Commit 7f01500f authored by Nadro's avatar Nadro

- Improved texture handling in a shader callback (returned ability to bind a...

- Improved texture handling in a shader callback (returned ability to bind a texture by a float interface).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4228 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 614b6894
...@@ -105,9 +105,10 @@ public: ...@@ -105,9 +105,10 @@ public:
if (UseHighLevelShaders) if (UseHighLevelShaders)
{ {
services->setVertexShaderConstant("mTransWorld", world.pointer(), 16); services->setVertexShaderConstant("mTransWorld", world.pointer(), 16);
// set texture, for textures it's very important to pass an int instead of float for a setPixelShaderConstant method.
// set texture, for textures you can use both an int and a float setPixelShaderConstant interfaces (You need it only for an OpenGL driver).
s32 TextureLayerID = 0; s32 TextureLayerID = 0;
if (UseHighLevelShaders && driver->getDriverType() == video::EDT_OPENGL) if (UseHighLevelShaders)
services->setPixelShaderConstant("myTexture", &TextureLayerID, 1); services->setPixelShaderConstant("myTexture", &TextureLayerID, 1);
} }
else else
......
...@@ -286,11 +286,18 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, ...@@ -286,11 +286,18 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
return false; return false;
} }
HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count); D3DXCONSTANT_DESC Description;
if (FAILED(hr)) UINT ucount = 1;
tbl->GetConstantDesc(hndl, &Description, &ucount);
if(Description.RegisterSet != D3DXRS_SAMPLER)
{ {
os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING); HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count);
return false; if (FAILED(hr))
{
os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING);
return false;
}
} }
return true; return true;
...@@ -318,11 +325,18 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name, ...@@ -318,11 +325,18 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
return false; return false;
} }
HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count); D3DXCONSTANT_DESC Description;
if (FAILED(hr)) UINT ucount = 1;
tbl->GetConstantDesc(hndl, &Description, &ucount);
if(Description.RegisterSet != D3DXRS_SAMPLER)
{ {
os::Printer::log("Error setting int array for HLSL variable", ELL_WARNING); HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count);
return false; if (FAILED(hr))
{
os::Printer::log("Error setting int array for HLSL variable", ELL_WARNING);
return false;
}
} }
return true; return true;
......
...@@ -550,10 +550,18 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32 ...@@ -550,10 +550,18 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32
case GL_FLOAT_MAT4_ARB: case GL_FLOAT_MAT4_ARB:
Driver->extGlUniformMatrix4fv(Location, count/16, false, floats); Driver->extGlUniformMatrix4fv(Location, count/16, false, floats);
break; break;
default: // deprecated. case GL_SAMPLER_1D:
os::Printer::log("Deprecation! Please use int interface instead of float to set variable", name, ELL_WARNING); case GL_SAMPLER_2D:
const GLint id = static_cast<GLint>(*floats); case GL_SAMPLER_3D:
Driver->extGlUniform1iv(Location, 1, &id); case GL_SAMPLER_CUBE:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
{
const GLint id = static_cast<GLint>(*floats);
Driver->extGlUniform1iv(Location, 1, &id);
}
break;
default:
break; break;
} }
return true; return true;
...@@ -594,9 +602,16 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32 ...@@ -594,9 +602,16 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32
case GL_INT_VEC4_ARB: case GL_INT_VEC4_ARB:
Driver->extGlUniform4iv(Location, count/4, ints); Driver->extGlUniform4iv(Location, count/4, ints);
break; break;
// case GL_INT: case GL_INT:
case GL_SAMPLER_1D:
case GL_SAMPLER_2D:
case GL_SAMPLER_3D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_1D_SHADOW:
case GL_SAMPLER_2D_SHADOW:
Driver->extGlUniform1iv(Location, 1, ints);
break;
default: default:
Driver->extGlUniform1iv(Location, count, ints);
break; break;
} }
return true; return true;
......
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