mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +00:00
Proper splitting of D3D and OpenGL sides of the CSF.
This commit is contained in:
parent
529558f671
commit
f9371bfc2e
3 changed files with 71 additions and 20 deletions
|
|
@ -21,8 +21,13 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen/CustomShaderFeature.h"
|
||||
|
||||
#ifdef TORQUE_D3D11
|
||||
#include "shaderGen/HLSL/customFeatureHLSL.h"
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
#include "shaderGen/GLSL/customFeatureGLSL.h"
|
||||
#endif
|
||||
|
||||
#include "math/mathIO.h"
|
||||
#include "scene/sceneRenderState.h"
|
||||
|
|
@ -36,16 +41,10 @@
|
|||
IMPLEMENT_CONOBJECT(CustomShaderFeatureData);
|
||||
|
||||
ConsoleDocClass(CustomShaderFeatureData,
|
||||
"@brief An example scene object which renders using a callback.\n\n"
|
||||
"This class implements a basic SceneObject that can exist in the world at a "
|
||||
"3D position and render itself. Note that CustomShaderFeatureData handles its own "
|
||||
"rendering by submitting itself as an ObjectRenderInst (see "
|
||||
"renderInstance\renderPassmanager.h) along with a delegate for its render() "
|
||||
"function. However, the preffered rendering method in the engine is to submit "
|
||||
"a MeshRenderInst along with a Material, vertex buffer, primitive buffer, and "
|
||||
"transform and allow the RenderMeshMgr handle the actual rendering. You can "
|
||||
"see this implemented in RenderMeshExample.\n\n"
|
||||
"See the C++ code for implementation details.\n\n"
|
||||
"@brief A Shader Feature with custom definitions.\n\n"
|
||||
"This class allows for the creation and implementation of a ShaderGen ShaderFeature "
|
||||
"Implemented either engine side or script, and facilitates passing along of per-instance "
|
||||
"ShaderData. "
|
||||
"@ingroup Examples\n");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -53,6 +52,12 @@ ConsoleDocClass(CustomShaderFeatureData,
|
|||
//-----------------------------------------------------------------------------
|
||||
CustomShaderFeatureData::CustomShaderFeatureData()
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
mFeatureHLSL = nullptr;
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
mFeatureGLSL = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
CustomShaderFeatureData::~CustomShaderFeatureData()
|
||||
|
|
@ -73,16 +78,21 @@ bool CustomShaderFeatureData::onAdd()
|
|||
if (!Parent::onAdd())
|
||||
return false;
|
||||
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
{
|
||||
mFeatureHLSL = new CustomFeatureHLSL();
|
||||
mFeatureHLSL->mOwner = this;
|
||||
}
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
{
|
||||
mFeatureGLSL = new CustomFeatureGLSL();
|
||||
mFeatureGLSL->mOwner = this;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -95,66 +105,98 @@ void CustomShaderFeatureData::onRemove()
|
|||
//Shadergen setup functions
|
||||
void CustomShaderFeatureData::addVariable(String name, String type, String defaultValue)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->addVariable(name, type, defaultValue);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->addVariable(name, type, defaultValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CustomShaderFeatureData::addUniform(String name, String type, String defaultValue, U32 arraySize)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->addUniform(name, type, defaultValue, arraySize);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->addUniform(name, type, defaultValue, arraySize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CustomShaderFeatureData::addSampler(String name, String type, U32 arraySize)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->addSampler(name, type, arraySize);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->addSampler(name, type, arraySize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CustomShaderFeatureData::addTexture(String name, String type, String samplerState, U32 arraySize)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->addTexture(name, type, samplerState, arraySize);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->addTexture(name, type, samplerState, arraySize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CustomShaderFeatureData::addConnector(String name, String type, String elementName)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->addConnector(name, type, elementName);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->addConnector(name, type, elementName);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CustomShaderFeatureData::addVertTexCoord(String name)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->addVertTexCoord(name);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->addVertTexCoord(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CustomShaderFeatureData::hasFeature(String name)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
return mFeatureHLSL->hasFeature(name);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
return mFeatureGLSL->hasFeature(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CustomShaderFeatureData::writeLine(String format, S32 argc, ConsoleValueRef* argv)
|
||||
{
|
||||
#ifdef TORQUE_D3D11
|
||||
if (GFX->getAdapterType() == GFXAdapterType::Direct3D11)
|
||||
mFeatureHLSL->writeLine(format, argc, argv);
|
||||
else if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
#endif
|
||||
#ifdef TORQUE_OPENGL
|
||||
if (GFX->getAdapterType() == GFXAdapterType::OpenGL)
|
||||
mFeatureGLSL->writeLine(format, argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
DefineEngineMethod(CustomShaderFeatureData, addVariable, void, (String name, String type, String defaultValue), ("", "", ""), "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue