Commit 263be759 authored by nadro's avatar nadro

- Improved a shader interface handling.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4399 dfc29bdd-3216-0410-991c-e03cc46cb475
parent fbedea08
......@@ -38,6 +38,9 @@ public:
const SMaterial& lastMaterial,
bool resetAllRenderstates) = 0;
//! Return an index constant for the vertex shader based on a name.
virtual s32 getVertexShaderConstantID(const c8* name) = 0;
//! Sets a constant for the vertex shader based on a name.
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. Example: If you created a shader which has
......@@ -58,15 +61,15 @@ public:
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
\endcode
\param name Name of the variable
\param index Index of the variable
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful.
*/
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count) = 0;
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count) = 0;
//! Int interface for the above.
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count) = 0;
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count) = 0;
//! Sets a vertex shader constant.
/** Can be used if you created a shader using pixel/vertex shader
......@@ -76,18 +79,21 @@ public:
\param constantAmount: Amount of registers to be set. One register consists of 4 floats. */
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! Return an index constant for the pixel shader based on a name.
virtual s32 getPixelShaderConstantID(const c8* name) = 0;
//! Sets a constant for the pixel shader based on a name.
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. See setVertexShaderConstant() for an
example on how to use this.
\param name Name of the variable
\param index Index of the variable
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful. */
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count) = 0;
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count) = 0;
//! Int interface for the above.
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count) = 0;
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count) = 0;
//! Sets a pixel shader constant.
/** Can be used if you created a shader using pixel/vertex shader
......
......@@ -185,19 +185,25 @@ bool CCgMaterialRenderer::isTransparent() const
return BaseMaterial ? BaseMaterial->isTransparent() : false;
}
void CCgMaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
s32 CCgMaterialRenderer::getVertexShaderConstantID(const c8* name)
{
os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
return getPixelShaderConstantID(name);
}
bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const f32* floats, int count)
s32 CCgMaterialRenderer::getPixelShaderConstantID(const c8* name)
{
return setPixelShaderConstant(name, floats, count);
for(u32 i = 0; i < UniformInfo.size(); ++i)
{
if(UniformInfo[i]->getName() == name)
return i;
}
return -1;
}
bool CCgMaterialRenderer::setVertexShaderConstant(const c8* name, const s32* ints, int count)
void CCgMaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
return setPixelShaderConstant(name, ints, count);
os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
}
void CCgMaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
......@@ -205,38 +211,34 @@ void CCgMaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegis
os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
}
bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const f32* floats, int count)
bool CCgMaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
bool Status = false;
return setPixelShaderConstant(index, floats, count);
}
for(unsigned int i = 0; i < UniformInfo.size(); ++i)
{
if(UniformInfo[i]->getName() == name)
{
UniformInfo[i]->update(floats, Material);
bool CCgMaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
return setPixelShaderConstant(index, ints, count);
}
Status = true;
}
}
bool CCgMaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
if(index < 0)
return false;
UniformInfo[index]->update(floats, Material);
return Status;
return true;
}
bool CCgMaterialRenderer::setPixelShaderConstant(const c8* name, const s32* ints, int count)
bool CCgMaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
bool Status = false;
if(index < 0)
return false;
for(unsigned int i = 0; i < UniformInfo.size(); ++i)
{
if(UniformInfo[i]->getName() == name)
{
UniformInfo[i]->update(ints, Material);
Status = true;
}
}
UniformInfo[index]->update(ints, Material);
return Status;
return true;
}
void CCgMaterialRenderer::getUniformList()
......
......@@ -139,12 +139,14 @@ public:
virtual bool isTransparent() const;
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) = 0;
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
virtual s32 getVertexShaderConstantID(const c8* name);
virtual s32 getPixelShaderConstantID(const c8* name);
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
virtual IVideoDriver* getVideoDriver() = 0;
protected:
......
......@@ -2161,6 +2161,20 @@ const core::matrix4& CD3D8Driver::getTransform(E_TRANSFORMATION_STATE state) con
return Matrices[state];
}
//! Get a vertex shader constant index.
s32 CD3D8Driver::getVertexShaderConstantID(const c8* name)
{
os::Printer::log("Cannot get constant index, no HLSL supported in D3D8");
return -1;
}
//! Get a pixel shader constant index.
s32 CD3D8Driver::getPixelShaderConstantID(const c8* name)
{
os::Printer::log("Cannot get constant index, no HLSL supported in D3D8");
return -1;
}
//! Sets a vertex shader constant.
void CD3D8Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
......@@ -2178,8 +2192,8 @@ void CD3D8Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32
}
//! Sets a constant for the vertex shader based on a name.
bool CD3D8Driver::setVertexShaderConstant(const c8* name, const f32* floats, int count)
//! Sets a constant for the vertex shader based on an index.
bool CD3D8Driver::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
os::Printer::log("Cannot set constant, no HLSL supported in D3D8");
return false;
......@@ -2187,15 +2201,15 @@ bool CD3D8Driver::setVertexShaderConstant(const c8* name, const f32* floats, int
//! Int interface for the above.
bool CD3D8Driver::setVertexShaderConstant(const c8* name, const s32* ints, int count)
bool CD3D8Driver::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
os::Printer::log("Cannot set constant, no HLSL supported in D3D8");
return false;
}
//! Sets a constant for the pixel shader based on a name.
bool CD3D8Driver::setPixelShaderConstant(const c8* name, const f32* floats, int count)
//! Sets a constant for the pixel shader based on an index.
bool CD3D8Driver::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
os::Printer::log("Cannot set constant, no HLSL supported in D3D8");
return false;
......@@ -2203,7 +2217,7 @@ bool CD3D8Driver::setPixelShaderConstant(const c8* name, const f32* floats, int
//! Int interface for the above.
bool CD3D8Driver::setPixelShaderConstant(const c8* name, const s32* ints, int count)
bool CD3D8Driver::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
os::Printer::log("Cannot set constant, no HLSL supported in D3D8");
return false;
......
......@@ -173,23 +173,29 @@ namespace video
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial,
bool resetAllRenderstates);
//! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name);
//! Get a pixel shader constant index.
virtual s32 getPixelShaderConstantID(const c8* name);
//! Sets a vertex shader constant.
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a pixel shader constant.
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a constant for the vertex shader based on a name.
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
//! Sets a constant for the vertex shader based on an index.
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
//! Sets a constant for the pixel shader based on a name.
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
//! Sets a constant for the pixel shader based on an index.
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
//! Returns a pointer to the IVideoDriver interface. (Implementation for
//! IMaterialRendererServices)
......
......@@ -3071,6 +3071,31 @@ const core::matrix4& CD3D9Driver::getTransform(E_TRANSFORMATION_STATE state) con
}
//! Get a vertex shader constant index.
s32 CD3D9Driver::getVertexShaderConstantID(const c8* name)
{
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer;
return r->getVariableID(true, name);
}
return -1;
}
//! Get a pixel shader constant index.
s32 CD3D9Driver::getPixelShaderConstantID(const c8* name)
{
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer;
return r->getVariableID(false, name);
}
return -1;
}
//! Sets a vertex shader constant.
void CD3D9Driver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
......@@ -3087,13 +3112,13 @@ void CD3D9Driver::setPixelShaderConstant(const f32* data, s32 startRegister, s32
}
//! Sets a constant for the vertex shader based on a name.
bool CD3D9Driver::setVertexShaderConstant(const c8* name, const f32* floats, int count)
//! Sets a constant for the vertex shader based on an index.
bool CD3D9Driver::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer;
return r->setVariable(true, name, floats, count);
return r->setVariable(true, index, floats, count);
}
return false;
......@@ -3101,25 +3126,25 @@ bool CD3D9Driver::setVertexShaderConstant(const c8* name, const f32* floats, int
//! Int interface for the above.
bool CD3D9Driver::setVertexShaderConstant(const c8* name, const s32* ints, int count)
bool CD3D9Driver::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer;
return r->setVariable(true, name, ints, count);
return r->setVariable(true, index, ints, count);
}
return false;
}
//! Sets a constant for the pixel shader based on a name.
bool CD3D9Driver::setPixelShaderConstant(const c8* name, const f32* floats, int count)
//! Sets a constant for the pixel shader based on an index.
bool CD3D9Driver::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer;
return r->setVariable(false, name, floats, count);
return r->setVariable(false, index, floats, count);
}
return false;
......@@ -3127,12 +3152,12 @@ bool CD3D9Driver::setPixelShaderConstant(const c8* name, const f32* floats, int
//! Int interface for the above.
bool CD3D9Driver::setPixelShaderConstant(const c8* name, const s32* ints, int count)
bool CD3D9Driver::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
if (Material.MaterialType >= 0 && Material.MaterialType < (s32)MaterialRenderers.size())
{
CD3D9MaterialRenderer* r = (CD3D9MaterialRenderer*)MaterialRenderers[Material.MaterialType].Renderer;
return r->setVariable(false, name, ints, count);
return r->setVariable(false, index, ints, count);
}
return false;
......
......@@ -259,23 +259,29 @@ namespace video
//! Returns the transformation set by setTransform
virtual const core::matrix4& getTransform(E_TRANSFORMATION_STATE state) const;
//! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name);
//! Get a pixel shader constant index.
virtual s32 getPixelShaderConstantID(const c8* name);
//! Sets a vertex shader constant.
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a pixel shader constant.
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a constant for the vertex shader based on a name.
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
//! Sets a constant for the vertex shader based on an index.
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
//! Sets a constant for the pixel shader based on a name.
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
//! Sets a constant for the pixel shader based on an index.
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
//! Returns a pointer to the IVideoDriver interface. (Implementation for
//! IMaterialRendererServices)
......
......@@ -265,29 +265,49 @@ bool CD3D9HLSLMaterialRenderer::createHLSLPixelShader(const char* pixelShaderPro
}
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
const f32* floats, int count)
s32 CD3D9HLSLMaterialRenderer::getVariableID(bool vertexShader, const c8* name)
{
LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable;
if (!tbl)
return false;
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
return -1;
D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name);
if (!hndl)
{
core::stringc s = "HLSL Variable to set not found: '";
core::stringc s = "HLSL Variable to get ID not found: '";
s += name;
s += "'. Available variables are:";
os::Printer::log(s.c_str(), ELL_WARNING);
printHLSLVariables(tbl);
return false;
return -1;
}
D3DXCONSTANT_DESC Description;
UINT ucount = 1;
if (!FAILED(tbl->GetConstantDesc(hndl, &Description, &ucount)))
return Description.RegisterIndex;
return -1;
}
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index,
const f32* floats, int count)
{
LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable;
if (index < 0 || !tbl)
return false;
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
D3DXHANDLE hndl = tbl->GetConstant(NULL, index);
if (!hndl)
return false;
D3DXCONSTANT_DESC Description;
UINT ucount = 1;
tbl->GetConstantDesc(hndl, &Description, &ucount);
if(Description.RegisterSet != D3DXRS_SAMPLER)
......@@ -304,26 +324,19 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
}
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, s32 index,
const s32* ints, int count)
{
LPD3DXCONSTANTTABLE tbl = vertexShader ? VSConstantsTable : PSConstantsTable;
if (!tbl)
if (index < 0 || !tbl)
return false;
// currently we only support top level parameters.
// Should be enough for the beginning. (TODO)
D3DXHANDLE hndl = tbl->GetConstantByName(NULL, name);
D3DXHANDLE hndl = tbl->GetConstant(NULL, index);
if (!hndl)
{
core::stringc s = "HLSL Variable to set not found: '";
s += name;
s += "'. Available variables are:";
os::Printer::log(s.c_str(), ELL_WARNING);
printHLSLVariables(tbl);
return false;
}
D3DXCONSTANT_DESC Description;
UINT ucount = 1;
......
......@@ -43,16 +43,18 @@ public:
//! Destructor
~CD3D9HLSLMaterialRenderer();
virtual s32 getVariableID(bool vertexShader, const c8* name);
//! sets a variable in the shader.
//! \param vertexShader: True if this should be set in the vertex shader, false if
//! in the pixel shader.
//! \param name: Name of the variable
//! \param index: Index of the variable
//! \param floats: Pointer to array of floats
//! \param count: Amount of floats in array.
virtual bool setVariable(bool vertexShader, const c8* name, const f32* floats, int count);
virtual bool setVariable(bool vertexShader, s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVariable(bool vertexShader, const c8* name, const s32* ints, int count);
virtual bool setVariable(bool vertexShader, s32 index, const s32* ints, int count);
bool OnRender(IMaterialRendererServices* service, E_VERTEX_TYPE vtxtype);
......
......@@ -63,20 +63,26 @@ public:
{
}
virtual s32 getVariableID(bool vertexShader, const c8* name)
{
os::Printer::log("Invalid material to set variable in.");
return -1;
}
//! sets a variable in the shader.
//! \param vertexShader: True if this should be set in the vertex shader, false if
//! in the pixel shader.
//! \param name: Name of the variable
//! \param index: Index of the variable
//! \param floats: Pointer to array of floats
//! \param count: Amount of floats in array.
virtual bool setVariable(bool vertexShader, const c8* name, const f32* floats, int count)
virtual bool setVariable(bool vertexShader, s32 index, const f32* floats, int count)
{
os::Printer::log("Invalid material to set variable in.");
return false;
}
//! Int interface for the above.
virtual bool setVariable(bool vertexShader, const c8* name, const s32* ints, int count)
virtual bool setVariable(bool vertexShader, s32 index, const s32* ints, int count)
{
os::Printer::log("Invalid material to set variable in.");
return false;
......
......@@ -3868,6 +3868,19 @@ ECOLOR_FORMAT COpenGLDriver::getColorFormat() const
}
//! Get a vertex shader constant index.
s32 COpenGLDriver::getVertexShaderConstantID(const c8* name)
{
return getPixelShaderConstantID(name);
}
//! Get a pixel shader constant index.
s32 COpenGLDriver::getPixelShaderConstantID(const c8* name)
{
os::Printer::log("Error: Please call services->getPixelShaderConstantID(), not VideoDriver->getPixelShaderConstantID().");
return -1;
}
//! Sets a vertex shader constant.
void COpenGLDriver::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
......@@ -3886,28 +3899,28 @@ void COpenGLDriver::setPixelShaderConstant(const f32* data, s32 startRegister, s
#endif
}
//! Sets a constant for the vertex shader based on a name.
bool COpenGLDriver::setVertexShaderConstant(const c8* name, const f32* floats, int count)
//! Sets a constant for the vertex shader based on an index.
bool COpenGLDriver::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
//pass this along, as in GLSL the same routine is used for both vertex and fragment shaders
return setPixelShaderConstant(name, floats, count);
return setPixelShaderConstant(index, floats, count);
}
//! Int interface for the above.
bool COpenGLDriver::setVertexShaderConstant(const c8* name, const s32* ints, int count)
bool COpenGLDriver::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
return setPixelShaderConstant(name, ints, count);
return setPixelShaderConstant(index, ints, count);
}
//! Sets a constant for the pixel shader based on a name.
bool COpenGLDriver::setPixelShaderConstant(const c8* name, const f32* floats, int count)
//! Sets a constant for the pixel shader based on an index.
bool COpenGLDriver::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
return false;
}
//! Int interface for the above.
bool COpenGLDriver::setPixelShaderConstant(const c8* name, const s32* ints, int count)
bool COpenGLDriver::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
os::Printer::log("Error: Please call services->setPixelShaderConstant(), not VideoDriver->setPixelShaderConstant().");
return false;
......
......@@ -277,23 +277,29 @@ namespace video
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastmaterial,
bool resetAllRenderstates);
//! Get a vertex shader constant index.
virtual s32 getVertexShaderConstantID(const c8* name);
//! Get a pixel shader constant index.
virtual s32 getPixelShaderConstantID(const c8* name);
//! Sets a vertex shader constant.
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a pixel shader constant.
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
//! Sets a constant for the vertex shader based on a name.
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
//! Sets a constant for the vertex shader based on an index.
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
//! Sets a constant for the pixel shader based on a name.
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
//! Sets a constant for the pixel shader based on an index.
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
//! Int interface for the above.
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
//! sets the current Texture
//! Returns whether setting was a success or not.
......
......@@ -399,6 +399,7 @@ bool COpenGLSLMaterialRenderer::linkProgram()
GLint size;
Driver->extGlGetActiveUniform(Program2, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLchar*>(buf));
ui.name = buf;
ui.location = Driver->extGlGetUniformLocation(Program2, buf);
UniformInfo.push_back(ui);
}
......@@ -475,6 +476,7 @@ bool COpenGLSLMaterialRenderer::linkProgram()
GLint size;
Driver->extGlGetActiveUniformARB(Program, i, maxlen, 0, &size, &ui.type, reinterpret_cast<GLcharARB*>(buf));
ui.name = buf;
ui.location = Driver->extGlGetUniformLocationARB(Program, buf);
UniformInfo.push_back(ui);
}
......@@ -494,15 +496,20 @@ void COpenGLSLMaterialRenderer::setBasicRenderStates(const SMaterial& material,
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
bool COpenGLSLMaterialRenderer::setVertexShaderConstant(const c8* name, const f32* floats, int count)
s32 COpenGLSLMaterialRenderer::getVertexShaderConstantID(const c8* name)
{
return setPixelShaderConstant(name, floats, count);
return getPixelShaderConstantID(name);
}
bool COpenGLSLMaterialRenderer::setVertexShaderConstant(const c8* name, const s32* ints, int count)
s32 COpenGLSLMaterialRenderer::getPixelShaderConstantID(const c8* name)
{
return setPixelShaderConstant(name, ints, count);
for (u32 i = 0; i < UniformInfo.size(); ++i)
{
if (UniformInfo[i].name == name)
return i;
}
return -1;
}
void COpenGLSLMaterialRenderer::setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
......@@ -510,51 +517,51 @@ void COpenGLSLMaterialRenderer::setVertexShaderConstant(const f32* data, s32 sta
os::Printer::log("Cannot set constant, please use high level shader call instead.", ELL_WARNING);
}
bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32* floats, int count)
void COpenGLSLMaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
u32 i;
const u32 num = UniformInfo.size();
os::Printer::log("Cannot set constant, use high level shader call.", ELL_WARNING);
}
for (i=0; i < num; ++i)
{
if (UniformInfo[i].name == name)
break;
}
bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const f32* floats, int count)
{
return setPixelShaderConstant(index, floats, count);
}
if (i == num)
return false;
bool COpenGLSLMaterialRenderer::setVertexShaderConstant(s32 index, const s32* ints, int count)
{
return setPixelShaderConstant(index, ints, count);
}
#if defined(GL_VERSION_2_0)||defined(GL_ARB_shader_objects)
GLint Location=0;
if (Program2)
Location=Driver->extGlGetUniformLocation(Program2,name);
else
Location=Driver->extGlGetUniformLocationARB(Program,name);
bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const f32* floats, int count)
{
#ifdef GL_ARB_shader_objects
if(index < 0 || UniformInfo[index].location < 0)
return false;
bool status = true;
switch (UniformInfo[i].type)
switch (UniformInfo[index].type)
{
case GL_FLOAT:
Driver->extGlUniform1fv(Location, count, floats);
Driver->extGlUniform1fv(UniformInfo[index].location, count, floats);
break;
case GL_FLOAT_VEC2:
Driver->extGlUniform2fv(Location, count/2, floats);
Driver->extGlUniform2fv(UniformInfo[index].location, count/2, floats);
break;
case GL_FLOAT_VEC3:
Driver->extGlUniform3fv(Location, count/3, floats);
Driver->extGlUniform3fv(UniformInfo[index].location, count/3, floats);
break;
case GL_FLOAT_VEC4:
Driver->extGlUniform4fv(Location, count/4, floats);
Driver->extGlUniform4fv(UniformInfo[index].location, count/4, floats);
break;
case GL_FLOAT_MAT2:
Driver->extGlUniformMatrix2fv(Location, count/4, false, floats);
Driver->extGlUniformMatrix2fv(UniformInfo[index].location, count/4, false, floats);
break;
case GL_FLOAT_MAT3:
Driver->extGlUniformMatrix3fv(Location, count/9, false, floats);
Driver->extGlUniformMatrix3fv(UniformInfo[index].location, count/9, false, floats);
break;
case GL_FLOAT_MAT4:
Driver->extGlUniformMatrix4fv(Location, count/16, false, floats);
Driver->extGlUniformMatrix4fv(UniformInfo[index].location, count/16, false, floats);
break;
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
......@@ -563,8 +570,13 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
{
const GLint id = static_cast<GLint>(*floats);
Driver->extGlUniform1iv(Location, 1, &id);
if(floats)
{
const GLint id = *floats;
Driver->extGlUniform1iv(UniformInfo[index].location, 1, &id);
}
else
status = false;
}
break;
default:
......@@ -577,42 +589,31 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32
#endif
}
bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32* ints, int count)
bool COpenGLSLMaterialRenderer::setPixelShaderConstant(s32 index, const s32* ints, int count)
{
u32 i;
const u32 num = UniformInfo.size();
for (i=0; i < num; ++i)
{
if (UniformInfo[i].name == name)
break;
}
if (i == num)
#ifdef GL_ARB_shader_objects
if(index < 0 || UniformInfo[index].location < 0)
return false;
#if defined(GL_VERSION_2_0)||defined(GL_ARB_shader_objects)
GLint Location=0;
if (Program2)
Location=Driver->extGlGetUniformLocation(Program2,name);
else
Location=Driver->extGlGetUniformLocationARB(Program,name);
bool status = true;
switch (UniformInfo[i].type)
switch (UniformInfo[index].type)
{
case GL_INT:
Driver->extGlUniform1iv(Location, count, ints);
case GL_BOOL:
Driver->extGlUniform1iv(UniformInfo[index].location, count, ints);
break;
case GL_INT_VEC2:
Driver->extGlUniform2iv(Location, count/2, ints);
case GL_BOOL_VEC2:
Driver->extGlUniform2iv(UniformInfo[index].location, count/2, ints);
break;
case GL_INT_VEC3:
Driver->extGlUniform3iv(Location, count/3, ints);
case GL_BOOL_VEC3:
Driver->extGlUniform3iv(UniformInfo[index].location, count/3, ints);
break;
case GL_INT_VEC4:
Driver->extGlUniform4iv(Location, count/4, ints);
case GL_BOOL_VEC4:
Driver->extGlUniform4iv(UniformInfo[index].location, count/4, ints);
break;
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
......@@ -620,7 +621,7 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32
case GL_SAMPLER_CUBE:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
Driver->extGlUniform1iv(Location, 1, ints);
Driver->extGlUniform1iv(UniformInfo[index].location, 1, ints);
break;
default:
status = false;
......@@ -632,11 +633,6 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32
#endif
}
void COpenGLSLMaterialRenderer::setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount)
{
os::Printer::log("Cannot set constant, use high level shader call.", ELL_WARNING);
}
IVideoDriver* COpenGLSLMaterialRenderer::getVideoDriver()
{
return Driver;
......
......@@ -85,12 +85,14 @@ public:
// implementations for the render services
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates);
virtual bool setVertexShaderConstant(const c8* name, const f32* floats, int count);
virtual bool setVertexShaderConstant(const c8* name, const s32* ints, int count);
virtual s32 getVertexShaderConstantID(const c8* name);
virtual s32 getPixelShaderConstantID(const c8* name);
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual bool setPixelShaderConstant(const c8* name, const f32* floats, int count);
virtual bool setPixelShaderConstant(const c8* name, const s32* ints, int count);
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
virtual bool setVertexShaderConstant(s32 index, const f32* floats, int count);
virtual bool setVertexShaderConstant(s32 index, const s32* ints, int count);
virtual bool setPixelShaderConstant(s32 index, const f32* floats, int count);
virtual bool setPixelShaderConstant(s32 index, const s32* ints, int count);
virtual IVideoDriver* getVideoDriver();
protected:
......@@ -122,6 +124,7 @@ protected:
{
core::stringc name;
GLenum type;
GLint location;
};
GLhandleARB Program;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment