資源簡(jiǎn)介
Unity3D調(diào)用Native OpenGL,Unity3D支持調(diào)用C++工程的OpenGL渲染,使用RenderingPlugin DLL方式。
代碼片段和文件信息
//?Example?low?level?rendering?Unity?plugin
#include?“UnityPluginInterface.h“
#include?
#include?
//?--------------------------------------------------------------------------
//?Include?headers?for?the?graphics?APIs?we?support
#if?SUPPORT_D3D9
#include?
#endif
#if?SUPPORT_OPENGL
#if?UNITY_WIN
#include?
#else
#include?
#endif
#endif
//?--------------------------------------------------------------------------
//?Helper?function?to?print?a?string
static?void?DebugLog?(const?char*?str)
{
#if?UNITY_WIN
OutputDebugStringA?(str);
#else
printf?(“%s“?str);
#endif
}
//?--------------------------------------------------------------------------
//?SetTimeFromUnity?an?example?function?we?export?which?is?called?by?one?of?the?scripts.
static?float?g_Time;
extern?“C“?void?EXPORT_API?SetTimeFromUnity?(float?t)?
{
g_Time?=?t;?
}
//?--------------------------------------------------------------------------
//?UnitySetGraphicsDevice
static?int?g_DeviceType?=?-1;
#if?SUPPORT_D3D9
static?IDirect3DDevice9*?g_D3D9Device;
//?In?D3D9?case?we‘ll?also?create?a?dynamic?vertex?buffer?just?to?demonstrate
//?how?to?handle?D3D9?device?resets.
static?IDirect3DVertexBuffer9*?g_D3D9DynamicVB;
#endif
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
//?If?we‘ve?got?a?D3D9?device?remember?device?pointer?and?device?type.
//?The?pointer?we?get?is?IDirect3DDevice9.
if?(deviceType?==?kGfxRendererD3D9)
{
DebugLog?(“Set?D3D9?graphics?device\n“);
g_D3D9Device?=?(IDirect3DDevice9*)device;
g_DeviceType?=?deviceType;
//?Create?or?release?a?small?dynamic?vertex?buffer?depending?on?the?event?type.
switch?(eventType)?{
case?kGfxDeviceEventInitialize:
case?kGfxDeviceEventAfterReset:
//?After?device?is?initialized?or?was?just?reset?create?the?VB.
if?(!g_D3D9DynamicVB)
g_D3D9Device->CreateVertexBuffer?(1024?D3DUSAGE_WRITEONLY?|?D3DUSAGE_DYNAMIC?0?D3DPOOL_DEFAULT?&g_D3D9DynamicVB?NULL);
break;
case?kGfxDeviceEventBeforeReset:
case?kGfxDeviceEventShutdown:
//?Before?device?is?reset?or?being?shut?down?release?the?VB.
if?(g_D3D9DynamicVB)
{
g_D3D9DynamicVB->Release();
g_D3D9DynamicVB?=?NULL;
}
break;
}
}
#endif
#if?SUPPORT_OPENGL
//?If?we‘ve?got?an?OpenGL?device?remember?device?type.?There‘s?no?OpenGL
//?“device?pointer“?to?remember?since?OpenGL?always?operates?on?a?currently?set
//?global?context.
if?(deviceType?==?kGfxRendererOpenGL)
{
DebugLog?(“Set?OpenGL?graphics?device\n“);
g_DeviceType?=?deviceType;
}
#endif
}
//?--------------------------------------------------------------------------
//?SetDefaultGraphicsState
//
//?Helper?function?to?setup?some?“sane“?g
- 上一篇:squish 幫助手冊(cè)
- 下一篇:vc++6.0簡(jiǎn)體中文版
評(píng)論
共有 條評(píng)論