#pragma once using namespace System; #pragma unmanaged #include "..\\..\\include\\irrlicht.h" #pragma managed #include "Material.h" #include "IShaderConstantSetCallBack.h" namespace Irrlicht { namespace Video { /// /// Compile target enumeration for the addHighLevelShaderMaterial() method. /// public __value enum VertexShaderType { VST_VS_1_1 = 0, VST_VS_2_0, VST_VS_2_a, VST_VS_3_0, VST_COUNT }; /// /// Compile target enumeration for the addHighLevelShaderMaterial() method. /// public __value enum PixelShaderType { PST_PS_1_1 = 0, PST_PS_1_2, PST_PS_1_3, PST_PS_1_4, PST_PS_2_0, PST_PS_2_a, PST_PS_2_b, PST_PS_3_0, PST_COUNT }; /// /// Interface making it possible to create and use programs running on the GPU. /// public __gc class IGPUProgrammingServices { public: IGPUProgrammingServices( irr::video::IGPUProgrammingServices* realGPU, Irrlicht::Video::IVideoDriver* videoDriver ); /// /// Adds a new material renderer to the VideoDriver, based on a high level shading /// language. Currently only HLSL/D3D9 and GLSL/OpenGL is supported. /// /// name of the function of the vertexShaderProgram /// Vertex shader version where the high level shader should be compiled to. /// String containing the source of the pixel shader program. /// This can be 0 if no pixel shader should be used. /// Entry name of the function of the pixelShaderEntryPointName /// Pixel shader version where the high level shader should be compiled to. /// Pointer to an implementation of IShaderConstantSetCallBack in which you /// can set the needed vertex and pixel shader program constants. Set this to 0 if you don't need this. /// Base material which renderstates will be used to shade the /// material. /// Returns the number of the /// material type which can be set in SMaterial::MaterialType to use the renderer. /// -1 is returned if an error occured. -1 is returned for example if a vertex or pixel shader /// program could not be compiled or a compile target is not reachable. /// The error strings are then printed out into the error log, and /// can be catched with a custom event receiver. int AddHighLevelShaderMaterial( String* vertexShaderProgram, String* vertexShaderEntryPointName, VertexShaderType vsCompileTarget, String* pixelShaderProgram, String* pixelShaderEntryPointName, PixelShaderType psCompileTarget, IShaderConstantSetCallBack* callback, MaterialType baseMaterial ); /// /// Like IGPUProgrammingServices::addShaderMaterial() (look there for a detailed description), /// but tries to load the programs from files. /// Text file containing the source of the vertex shader program. /// Set to null if no shader should be created. /// Text file containing the source of the pixel shader program. Set to /// 0 if no shader should be created. int AddHighLevelShaderMaterialFromFiles( String* vertexShaderProgram, String* vertexShaderEntryPointName, VertexShaderType vsCompileTarget, String* pixelShaderProgram, String* pixelShaderEntryPointName, PixelShaderType psCompileTarget, IShaderConstantSetCallBack* callback, MaterialType baseMaterial) ; /// /// Adds a new material renderer to the VideoDriver, using pixel and/or /// vertex shaders to render geometry. /// Note that it is a good idea to call IVideoDriver::queryFeature() before to check /// if the IVideoDriver supports the vertex and/or pixel shader version your are using. /// The material is added to the VideoDriver like with IVideoDriver::addMaterialRenderer() /// and can be used like it had been added with that method. /// /// String containing the source of the vertex shader program. This can be /// 0 if no vertex program should be used. /// For DX8 programs, the will always input registers look like this: /// v0: position, v1: normal, /// v2: color, v3: texture cooridnates, v4: texture coordinates 2 if available. /// For DX9 programs, you can manually set the registers using the dcl_ statements. /// String containing the source of the pixel shader program. /// This can be 0 if you don't want to use a pixel shader. /// Pointer to an implementation of IShaderConstantSetCallBack in which you /// can set the needed vertex and pixel shader program constants. Set this to 0 if you don't need this. /// Base material which renderstates will be used to shade the /// material. /// Returns the number of the /// material type which can be set in SMaterial::MaterialType to use the renderer. /// -1 is returned if an error occured. -1 is returned for example if a vertex or pixel shader /// program could not be compiled, the error strings are then printed out into the error log, and /// can be catched with a custom event receiver. int AddShaderMaterial( String* vertexShaderProgram, String* pixelShaderProgram, IShaderConstantSetCallBack* callback, MaterialType baseMaterial ); /// /// Like IGPUProgrammingServices::addShaderMaterial(), but tries to load the /// programs from files. /// /// Text file containing the source of the vertex shader program. /// Set to null if no shader should be created. /// Text file containing the source of the pixel shader program. Set to /// null if no shader should be created. int AddShaderMaterialFromFiles( String* vertexShaderProgram, String* pixelShaderProgram, IShaderConstantSetCallBack* callback, MaterialType baseMaterial ); /// /// Internal list for mapping C++ callbacks to .NET callbacks. This was made public because /// of an obvious bug in managed C++. Simply don't use this. /// __property static System::Collections::ArrayList* get_CallbackMap() { return CallBackList; } __gc class SServiceCallbackMapping { public: Irrlicht::Video::IGPUProgrammingServices* ManagedServices; Irrlicht::Video::IShaderConstantSetCallBack* ManagedCallback; Irrlicht::Video::IMaterialRendererServices* ManagedMaterialServices; }; /// /// Returns the video driver. /// __property Irrlicht::Video::IVideoDriver* get_VideoDriver(); protected: irr::video::IGPUProgrammingServices* gpuProgrammingServices; inline irr::video::IGPUProgrammingServices* getGPUProgrammingServices() { return (irr::video::IGPUProgrammingServices*)gpuProgrammingServices; } /// /// Private method for receiving shader callbacks from the native C++ Irrlicht engine and /// to map them to the .NET callback method /// __nogc class NativeCallbackReceiver : public irr::video::IShaderConstantSetCallBack { public: void OnSetConstants(irr::video::IMaterialRendererServices* services, irr::s32 userData); }; int registerCallback(Irrlicht::Video::IShaderConstantSetCallBack* callback); NativeCallbackReceiver* Receiver; static System::Collections::ArrayList* CallBackList; Irrlicht::Video::IVideoDriver* TheVideoDriver; }; } }