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:
if (UseHighLevelShaders)
{
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;
if (UseHighLevelShaders && driver->getDriverType() == video::EDT_OPENGL)
if (UseHighLevelShaders)
services->setPixelShaderConstant("myTexture", &TextureLayerID, 1);
}
else
......
......@@ -286,11 +286,18 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
return false;
}
HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count);
if (FAILED(hr))
D3DXCONSTANT_DESC Description;
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);
return false;
HRESULT hr = tbl->SetFloatArray(pID3DDevice, hndl, floats, count);
if (FAILED(hr))
{
os::Printer::log("Error setting float array for HLSL variable", ELL_WARNING);
return false;
}
}
return true;
......@@ -318,11 +325,18 @@ bool CD3D9HLSLMaterialRenderer::setVariable(bool vertexShader, const c8* name,
return false;
}
HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count);
if (FAILED(hr))
D3DXCONSTANT_DESC Description;
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);
return false;
HRESULT hr = tbl->SetIntArray(pID3DDevice, hndl, ints, count);
if (FAILED(hr))
{
os::Printer::log("Error setting int array for HLSL variable", ELL_WARNING);
return false;
}
}
return true;
......
......@@ -550,10 +550,18 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const f32
case GL_FLOAT_MAT4_ARB:
Driver->extGlUniformMatrix4fv(Location, count/16, false, floats);
break;
default: // deprecated.
os::Printer::log("Deprecation! Please use int interface instead of float to set variable", name, ELL_WARNING);
const GLint id = static_cast<GLint>(*floats);
Driver->extGlUniform1iv(Location, 1, &id);
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:
{
const GLint id = static_cast<GLint>(*floats);
Driver->extGlUniform1iv(Location, 1, &id);
}
break;
default:
break;
}
return true;
......@@ -594,9 +602,16 @@ bool COpenGLSLMaterialRenderer::setPixelShaderConstant(const c8* name, const s32
case GL_INT_VEC4_ARB:
Driver->extGlUniform4iv(Location, count/4, ints);
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:
Driver->extGlUniform1iv(Location, count, ints);
break;
}
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