//Occlusion Unity plugin

#include "UnityPluginInterface.h"

#include <math.h>
#include <stdio.h>

// --------------------------------------------------------------------------
// Include headers for the graphics APIs we support
#if SUPPORT_D3D9
#include <d3d9.h>
#endif

// --------------------------------------------------------------------------
// Helper utilities

// COM-like Release macro
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(a) if (a) { a->Release(); a = NULL; }
#endif

// --------------------------------------------------------------------------
// SetTimeFromUnity, an example function we export which is called by one of the scripts.
static int g_pixelsVisible = 0;

extern "C" int EXPORT_API Result() { return g_pixelsVisible; }

// --------------------------------------------------------------------------
// UnitySetGraphicsDevice

static int g_DeviceType = -1;

// Actual setup/teardown functions defined below
#if SUPPORT_D3D9
static IDirect3DDevice9* g_D3D9Device = NULL;

// A D3dQuery Interface Pointer
static IDirect3DQuery9 * g_D3DQuery = NULL;

static void SetGraphicsDeviceD3D9 (IDirect3DDevice9* device, GfxDeviceEventType eventType)
{
g_D3D9Device = device;

// Create or Reset release g_D3DQuery
switch (eventType) {
case kGfxDeviceEventInitialize:
case kGfxDeviceEventAfterReset:
// After device is initialized or was just reset, create the g_D3DQuery.
if (!g_D3DQuery)
g_D3D9Device->CreateQuery( D3DQUERYTYPE_OCCLUSION, &g_D3DQuery );
break;
case kGfxDeviceEventBeforeReset:
case kGfxDeviceEventShutdown:
// Before device is reset or being shut down, release the g_D3DQuery.
SAFE_RELEASE(g_D3DQuery);
break;
}
}

#endif // #if SUPPORT_D3D9

extern "C" void EXPORT_API UnitySetGraphicsDevice (void* device, int deviceType, int eventType)
{
// Set device type to -1, i.e. "not recognized by our plugin"
g_DeviceType = -1;

#if SUPPORT_D3D9
// D3D9 device, remember device pointer and device type.
// The pointer we get is IDirect3DDevice9.
if (deviceType == kGfxRendererD3D9)
{
g_DeviceType = deviceType;
SetGraphicsDeviceD3D9 ((IDirect3DDevice9*)device, (GfxDeviceEventType)eventType);
}
#endif
}

// --------------------------------------------------------------------------
// OcclusionBegin

extern "C" void EXPORT_API OcclusionBegin ()
{
#if SUPPORT_D3D9
if(g_D3DQuery != NULL)
g_D3DQuery->Issue( D3DISSUE_BEGIN );
#endif
}

// --------------------------------------------------------------------------
// OcclusionEnd
extern "C" void EXPORT_API OcclusionEnd ()
{
#if SUPPORT_D3D9
// End the query, get the data
if(g_D3DQuery != NULL)
{
g_D3DQuery->Issue( D3DISSUE_END );

while (g_D3DQuery->GetData((void *) &g_pixelsVisible,
sizeof(int), D3DGETDATA_FLUSH) == S_FALSE);
}
#endif
}

Unity Dx9 Occlusion Query plugin的更多相关文章

  1. Dx12 occlusion query

    https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12PredicationQu ...

  2. Unity GPU Query OpenGLES 3.0

    https://github.com/google/render-timing-for-unity/blob/master/RenderTimingPlugin/RenderTimingPlugin. ...

  3. Unity Glossary

    https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...

  4. Unity读Excel 输出PC端(Windows)后不能读取的问题

    问题:在Unity中用ExcelDataReader读Excel时,在编辑器模式下可以正常读取,但是在导出PC端app后读Excel却会报空,Excel读取失败. 要点: 1.把库文件Excel.dl ...

  5. Unity 编辑器学习(二)之 全局光照(GI)

    光影流年,花影阡陌.光与影交织的岁月教育我们,不会使用光照的程序员不是个好美术. 一.概述 点击 Window > Lighting > Settings 会弹出Lighting窗口,这个 ...

  6. [OSG]OSG的相关扩展

    参考:osg官网 http://www.osgchina.org/index.php?view=article&id=176 http://trac.openscenegraph.org/pr ...

  7. CSharpGL(31)[译]OpenGL渲染管道那些事

    CSharpGL(31)[译]OpenGL渲染管道那些事 +BIT祝威+悄悄在此留下版了个权的信息说: 开始 自认为对OpenGL的掌握到了一个小瓶颈,现在回头细细地捋一遍OpenGL渲染管道应当是一 ...

  8. CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率

    CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率 当场景中有比较复杂的模型时,条件渲染能够加速对复杂模型的渲染. 条件渲染(Conditio ...

  9. 【IDEA】intellij idea 插件推荐

    CSDN 2016博客之星评选结果公布    [系列直播]零基础学习微信小程序!      "我的2016"主题征文活动   博客的神秘功能 [IDEA]intellij idea ...

随机推荐

  1. 屏蔽Codeforces做题时的Problem tags提示

    当在Codeforces上做题的时,有时会无意撇到右侧的Problem tags边栏,但是原本并不希望能够看到它. 能否把它屏蔽了呢?答案是显然的,我们只需要加一段很短的CSS即可. span.tag ...

  2. 用GitHub Pages免费空间搭建Blog

    前言   其实之前就知道可以用GitHub Pages搭建静态博客,不过之前一直忙着爬手册撸代码==,昨天终于把前端各种手册里的入门教程撸的差不多了(CSS布局撸的我要吐了好嘛),于是把代码什么的放一 ...

  3. HTML - 键盘事件

    Keyboard 事件 onkeydown: 在用户按下按键时触发. onkeypress: 在用户敲击按钮时触发. onkeyup: 当用户释放按键时触发. 示例 <!DOCTYPE html ...

  4. EntityFrameowk6.1 使用enum和低版本的不同

    原有项目中使用EF5.0 实体类 public partial class Log : BaseEntity { public Nullable<int> LogLevelId { get ...

  5. android SDK 代理配置(东北大学)

    启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Settings』窗口: 在『Andro ...

  6. JavaScript_变量的自动转换和语句

    JS自动类型转换 var a = 1; var b = true; "==" 表示 可以自动类型转换,比较的是数值 "===" 表示可以自动类型转换,先比较数值 ...

  7. STL库list::sort()实现深度解析

    原创,转载请注明出处:STL库list::sort()实现深度解析 list模板的定义以及一些基本成员函数的实现这里我就不赘述了,还不清楚的同学可以到网上查找相关资料或者直接查看侯捷翻译的<ST ...

  8. C++中extern关键字使用(转)

    参考文章:http://blog.csdn.net/sruru/article/details/7951019 chapter1.如何混合编译C语言和C++ 实际开发过程中,C++中会调用C与语言编写 ...

  9. js 的其它运算符和优先级

    三元运算符: 语法为 exp1? exp2:exp3 判断 exp1是true 和 false  如果true,则返回exp2  ,如果false ,则返回exp3 <script> if ...

  10. MySql数据库4【命令行赋权操作】

    MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant selec ...