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 ...
随机推荐
- PHP获取文件行数
原文出处 提供两种实现方法,但是第一种效率最好 第一种: <?php $file_path = 'test.txt'; //文件路径 此处找一个1094644行的TXT文件 test.txt $ ...
- ActionResult 常见问题
1:在Asp.net Mvc 2中由于对数据的保护,当返回类型为JsonResult时 ,默认情况下request需要为post.(可使用 return Json(person,JsonReque ...
- String 方法
import java.lang.*; /** * 1.查找"asdfjvjadsffvaadfkfasaffdsasdffadsafafsafdadsfaafd" * 该字符串中 ...
- idea配置tomcat.md
[toc] 1.打开Edit Configurations,可以通过万能搜索快速进入!!! 2.添加服务器,在左上角找到Tomcat并添加 3.配置发布路径,Server标签页中填写完名称和路径,在D ...
- 百度地图实现车辆轨迹移动播放(baidu map api)
开发技术:jquery,js baidu map api,json,ajax QQ1310651206
- 代码bug
1.webstorm ide未配置basePath本地会加入根路径 2.点击一次就销毁可以给标签设置一个值data-val="0" 某个函数只执行一次的方法,或者也可以考虑绑用on ...
- Magento 2.0 安装
环境: 直接升到最新版PHP5.6.x 刚才开MAC OS PHP 5.5 CENTOS PHP 5.5 composer install 依懒包错误.反复安装组件.还是不行.后来决定重新编释最 ...
- masonry结合json 制作无限滚动的瀑布流
做前端这行的 能直接贴代码就直接贴代码了,不用多说什么别的 效果需要引入jquery和jquery.masonry.min.js这两个JS JS代码如下: $(document).ready(func ...
- 用urlencode(String str)对URL传递参数进行编码,提高安全
在PHP 提交地址后面带有参数的时候,参数会在浏览器的地址栏暴露无疑,这样是不安全的,这个时候就必须用些方法对这些参数进行安全处理 这里可以用 urlencode(String URL);//对URL ...
- BAE 环境下 hibernate annotations 配置
annotations 配置 首先需要加入 hibernate-jpa-2.0-api-1.0.1.Final.jar 和 ejb3-persistence.jar 这两个包 ejb3-persis ...