deargui-vpl/ref/virtools/Samples/Behaviors/Shader/Shader.cpp

223 lines
7.6 KiB
C++

// Shader.cpp : Defines the initialization routines for the plugin DLL.
//
#include "stdafx.h"
//nicolasp
//NO_CG_SHADERS is only defined in a subproject under macintosh, not in another platform
#ifndef NO_CG_SHADERS
// Include the manager definition regarding to the D3D Version or the Cg Usage :
#if defined(MULTIPLESHADERMANAGER)
#include ".\Sources\ShaderManagerWrapper.h"
#elif defined(CGFX)
#include "./Sources/ShaderManagerCG.h"
#else // #ifdef CGFX
#include ".\Sources\ShaderManager.h"
#endif // #ifndef CGFX
#include "./Sources/GetShaderCapabilities.h"
#endif //#ifndef NO_CG_SHADERS
#include "./Sources/RTView.h"
#define ShaderBehaviorsGUID CKGUID(0x15525d9b,0x42b915d7)
#define PLUGIN_COUNT 2 // A Manager
CKGUID CKPGUID_CUBEFACE = CKGUID(0x29716003, 0x3c5d47cd);
CKGUID CKPGUID_VRREGISTERUNREGISTERENUM = CKGUID(0x7abf5d88, 0x1d315020);
#ifdef CK_LIB
#define RegisterBehaviorDeclarations Register_Shaders_BehaviorDeclarations
#define InitInstance _Shaders_InitInstance
#define ExitInstance _Shaders_ExitInstance
#define CKGetPluginInfoCount CKGet_Shaders_PluginInfoCount
#define CKGetPluginInfo CKGet_Shaders_PluginInfo
#define g_PluginInfo g_3Shaders_PluginInfo
#else
#define RegisterBehaviorDeclarations RegisterBehaviorDeclarations
#define InitInstance InitInstance
#define ExitInstance ExitInstance
#define CKGetPluginInfoCount CKGetPluginInfoCount
#define CKGetPluginInfo CKGetPluginInfo
#define g_PluginInfo g_PluginInfo
#endif
CKPluginInfo g_PluginInfo[PLUGIN_COUNT];
CKERROR InitInstance(CKContext* context);
int CKGetPluginInfoCount() {
return PLUGIN_COUNT;
}
// TMP TMP
#define CKPGUID_STENCILFUNC CKGUID(0x37293802,0x58c70dbc)
#define CKPGUID_STENCILOP CKGUID(0x4f65530c,0x56f335da)
CKPluginInfo* CKGetPluginInfo(int Index)
{
#if (defined(macintosh) && defined (VIRTOOLS_PLAYER))
if (!LoadCgFrameworkBundle())
return NULL;
#endif
int Plugin = 0;
g_PluginInfo[Plugin].m_Author = "Virtools";
#if defined(MULTIPLESHADERMANAGER)
g_PluginInfo[Plugin].m_Description = "Shader management for Direct X and OpenGL";
#elif defined(CGFX)
g_PluginInfo[Plugin].m_Description = "CgFX Shader management for OpenGL";
#else // #ifndef CGFX
g_PluginInfo[Plugin].m_Description = "Shader management for Direct X";
#endif // #ifdef CGFX
g_PluginInfo[Plugin].m_Extension = "";
g_PluginInfo[Plugin].m_Type = CKPLUGIN_MANAGER_DLL;
g_PluginInfo[Plugin].m_Version = 0x00000001;
g_PluginInfo[Plugin].m_InitInstanceFct = InitInstance;
g_PluginInfo[Plugin].m_GUID = ShaderManagerGUID;
g_PluginInfo[Plugin].m_Summary = "Shader Manager "; // Hack: use different string to impede user deactivation
Plugin++;
g_PluginInfo[Plugin].m_Author = "Virtools";
#if defined(MULTIPLESHADERMANAGER)
g_PluginInfo[Plugin].m_Description = "Shader management for Direct X and OpenGL";
#elif defined(CGFX)
g_PluginInfo[Plugin].m_Description = "CgFX Shader management for OpenGL";
#else // #ifndef CGFX
g_PluginInfo[Plugin].m_Description = "Shader management for Direct X";
#endif // #ifdef CGFX
g_PluginInfo[Plugin].m_Extension = "";
g_PluginInfo[Plugin].m_Type = CKPLUGIN_BEHAVIOR_DLL;
g_PluginInfo[Plugin].m_Version = 0x00000001;
g_PluginInfo[Plugin].m_InitInstanceFct = NULL;
g_PluginInfo[Plugin].m_GUID = ShaderBehaviorsGUID;
g_PluginInfo[Plugin].m_Summary = "Shader Behaviors";
return &g_PluginInfo[Index];
}
// If no manager is used in the plugin
// these functions are optional and can be exported.
// Virtools will call 'InitInstance' when loading the behavior library
// and 'ExitInstance' when unloading it.
// It is a good place to perform Attributes Types declaration,
// registering new enums or new parameter types.
CKERROR InitInstance(CKContext* context)
{
#ifndef NO_CG_SHADERS
#if defined(MULTIPLESHADERMANAGER)
new ShaderManagerWrapper(context);
#elif defined(CGFX)
// Compile with the NVIDIA CgFX Toolkit, then use the Cg Manager
new ShaderManagerCG(context);
#else // #ifdef CGFX
// Compile with DirectX SDK ...
new ShaderManager(context);
#endif // #ifdef CGFX
#endif
CKParameterManager* pman = context->GetParameterManager();
//-------------------------------------------------------------------------
// Register Rendertarget View
//-------------------------------------------------------------------------
XArray<CKGUID> structure;
structure.PushBack(CKPGUID_TEXTURE);
structure.PushBack(CKPGUID_RECT);
pman->RegisterNewStructure(CKPGUID_RTVIEW, "RenderTarget View",
"RenderTarget,RenderTarget Viewport", structure);
//-------------------------------------------------------------------------
// Register Paramops
//-------------------------------------------------------------------------
// Create Rendertarget View
pman->RegisterOperationType(CKOGUID_SETRTVIEW, "Set RTView");
pman->RegisterOperationFunction(CKOGUID_SETRTVIEW,
CKPGUID_RTVIEW, CKPGUID_TEXTURE, CKPGUID_RECT,
_PopCreateRenderTargetView);
//--- Get Texture
pman->RegisterOperationFunction(CKOGUID_GETTEXTURE,
CKPGUID_TEXTURE, CKPGUID_RTVIEW, CKPGUID_NONE,
_PopGetTexture);
//--- Get RTView Rect
pman->RegisterOperationType(CKOGUID_GETRECTANGLE, "Get Rect");
pman->RegisterOperationFunction(CKOGUID_GETRECTANGLE,
CKPGUID_RECT, CKPGUID_RTVIEW, CKPGUID_NONE,
_PopGetRectangle);
//--- Get RTView Texture Rect
pman->RegisterOperationType(CKOGUID_GETTEXCOORDS, "Get Texture Rect");
pman->RegisterOperationFunction(CKOGUID_GETTEXCOORDS,
CKPGUID_RECT, CKPGUID_RTVIEW, CKPGUID_NONE,
_PopGetRectangleTexcoords);
//--- Get RTView Texel Size
pman->RegisterOperationType(CKOGUID_GETTEXELSIZE, "Get Texel Size");
pman->RegisterOperationFunction(CKOGUID_GETTEXELSIZE,
CKPGUID_2DVECTOR, CKPGUID_RTVIEW, CKPGUID_NONE,
_PopGetTexelSize);
#ifndef NO_CG_SHADERS
//-------------------------------------------------------------------------
// Register Enums
//-------------------------------------------------------------------------
pman->RegisterNewEnum(CKENUMGUID_COMPILATIONPROFILE, "Shader Compilation Profile", SHADERCPLPROFILESTR);
pman->RegisterNewEnum(CKENUMGUID_RASTERIZERVERSION, "Rasterizer Version", RASTERIZERVERSIONSTR);
#endif
pman->RegisterNewEnum(CKPGUID_CUBEFACE,"Cube Face","XPos=0,XNeg=1,YPos=2,YNeg=3,ZPos=4,ZNeg=5");
pman->RegisterNewEnum( CKPGUID_VRREGISTERUNREGISTERENUM,
"VR Register/Unregister",
"Register=0,Unregister=1");
return CK_OK;
}
CKERROR ExitInstance(CKContext* context)
{
#ifndef NO_CG_SHADERS
// If the dll is unloaded explicitely by a user in Virtools Dev interface
// this function will be called
CKParameterManager* pman = context->GetParameterManager();
pman->UnRegisterParameterType(CKENUMGUID_COMPILATIONPROFILE);
delete context->GetManagerByGuid(ShaderManagerGUID);
#endif
return CK_OK;
}
void RegisterBehaviorDeclarations(XObjectDeclarationArray *reg)
{
#ifndef NO_CG_SHADERS
// Shader
RegisterBehavior(reg, FillBehaviorGetShaderCapabilities);
RegisterBehavior(reg, FillBehaviorGetShaderCapabilities_2);
RegisterBehavior(reg, FillBehaviorBuildTangentSpace);
RegisterBehavior(reg, FillBehaviorApplyShader);
// Material
RegisterBehavior(reg, FillBehaviorSetMaterialShaderParameters);
RegisterBehavior(reg, FillBehaviorGetMaterialShaderParameters);
RegisterBehavior(reg, FillBehaviorSetMaterialShaderTechnique);
// Rendering
RegisterBehavior(reg, FillBehaviorCombineRTViews);
#endif
RegisterBehavior(reg, FillBehaviorRenderScene);
RegisterBehavior(reg, FillBehaviorStretchRect); // Put on hold for now ...
RegisterBehavior(reg, FillBehaviorIsStretchRectSupported); // Put on hold for now ...
RegisterBehavior(reg, FillBehaviorResolveMultisampling);
RegisterBehavior(reg, FillBehaviorResumeMultisampling);
}