Unity Dx9 Occlusion Query plugin
//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的更多相关文章
- Dx12 occlusion query
https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/Samples/Desktop/D3D12PredicationQu ...
- Unity GPU Query OpenGLES 3.0
https://github.com/google/render-timing-for-unity/blob/master/RenderTimingPlugin/RenderTimingPlugin. ...
- Unity Glossary
https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...
- Unity读Excel 输出PC端(Windows)后不能读取的问题
问题:在Unity中用ExcelDataReader读Excel时,在编辑器模式下可以正常读取,但是在导出PC端app后读Excel却会报空,Excel读取失败. 要点: 1.把库文件Excel.dl ...
- Unity 编辑器学习(二)之 全局光照(GI)
光影流年,花影阡陌.光与影交织的岁月教育我们,不会使用光照的程序员不是个好美术. 一.概述 点击 Window > Lighting > Settings 会弹出Lighting窗口,这个 ...
- [OSG]OSG的相关扩展
参考:osg官网 http://www.osgchina.org/index.php?view=article&id=176 http://trac.openscenegraph.org/pr ...
- CSharpGL(31)[译]OpenGL渲染管道那些事
CSharpGL(31)[译]OpenGL渲染管道那些事 +BIT祝威+悄悄在此留下版了个权的信息说: 开始 自认为对OpenGL的掌握到了一个小瓶颈,现在回头细细地捋一遍OpenGL渲染管道应当是一 ...
- CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率
CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率 当场景中有比较复杂的模型时,条件渲染能够加速对复杂模型的渲染. 条件渲染(Conditio ...
- 【IDEA】intellij idea 插件推荐
CSDN 2016博客之星评选结果公布 [系列直播]零基础学习微信小程序! "我的2016"主题征文活动 博客的神秘功能 [IDEA]intellij idea ...
随机推荐
- 基于JAVA网络编程的聊天小程序
package com.neusoft.edu.socket; import java.io.BufferedReader; import java.io.IOException; import ja ...
- 记一次网站服务器迁移(my)
遇到的难题: 基本没有遇到太大的问题,因为服务器环境是配好的阿里云环境,最后再nginx的rewrite配置遇到了一点问题,最后也算解决. 收获小点: 1) vim替换命令: 利用 :s 命令可以实现 ...
- tomcat的webapp下的root文件夹的作用是什么
1.基本一样..只是表示不同的tomcat的http路径而已. root目录默认放的是tomcat自己的一个项目,如:http://localhost:8080/默认访问root项目 对于webapp ...
- CI 笔记5 (CI3.0 默认控制器,多目录)
在ci3.x中,不支持多级子目录的默认控制器设置, 解决方法如下: 在index.php中,添加 $routing['directory'] = 'admin';然后在默认的router.php的默 ...
- 移动触摸事件(touchstart、touchmove和touchend)
touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发. touchmove事件:当手指在屏幕上滑动的时候连续地触发.在这个事件发生期间,调用preventDefaul ...
- phpcms v9后台美化需要修改的部分整理
PHPcms后台登陆后的页面修改 Phpcms->modules->admin->templates->main.tpl.php 1,安全提示部分 <h6>< ...
- ThinkPHP框架下,给jq动态添加的标签添加点击事件移除标签
jq移除标签主要就是$("#要移除的id").remove();不再赘述,这里要提醒的是jq中动态添加标签后怎样添加点击事件.一般的jq添加点击事件是用这种方法$("#i ...
- js 表达式与运算符 详解(下)
比较运算符: > .>= .<. <=. ==. !=. ===. !==. 比较运算符的结果都为布尔值 ==只比较值是否相等 而 ===比较的是值和数据类型都要 ...
- 使用Slip.js快速创建整屏滑动的手机网页
原文 http://segmentfault.com/blog/laopopo/1190000000708417 现在滑屏网页越来越多,比如我在搜狐视频就做了好几个,举个例子,可以用手机扫描以下的二 ...
- 高级停靠(Dock)技术的实现
高级停靠(Dock)技术的实现 介绍 所谓停靠就是可以用鼠标拖动窗体或者控件,并将其从一个父窗体移出或者移动到另一个父窗体上,可以按水平,垂直方向整齐排列, 并且可以停靠在分页控制组件上.下面的示意图 ...