Add bool return values on shader creation in order to signal problems and avoid illegal mem access on broken shaders.
git-svn-id: http://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@3834 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
0f933c27a9
commit
0795f00099
@ -71,12 +71,14 @@ namespace video
|
||||
else
|
||||
{
|
||||
// compile shaders on our own
|
||||
initFromFiles( outMaterialTypeNr, VertexShaderFile, FragmentShaderFile );
|
||||
useProgram();
|
||||
int dummy = 0;
|
||||
setUniform( TEXTURE_UNIT0, &dummy );
|
||||
dummy = 1;
|
||||
setUniform( TEXTURE_UNIT1, &dummy );
|
||||
if (initFromFiles(outMaterialTypeNr, VertexShaderFile, FragmentShaderFile))
|
||||
{
|
||||
useProgram();
|
||||
int dummy = 0;
|
||||
setUniform( TEXTURE_UNIT0, &dummy );
|
||||
dummy = 1;
|
||||
setUniform( TEXTURE_UNIT1, &dummy );
|
||||
}
|
||||
}
|
||||
|
||||
// fallback if compilation has failed
|
||||
|
@ -76,12 +76,14 @@ namespace video
|
||||
else
|
||||
{
|
||||
// compile shaders on our own
|
||||
initFromFiles( outMaterialTypeNr, VertexShaderFile, FragmentShaderFile );
|
||||
useProgram();
|
||||
int dummy = 0;
|
||||
setUniform( TEXTURE_UNIT0, &dummy );
|
||||
dummy = 1;
|
||||
setUniform( TEXTURE_UNIT1, &dummy );
|
||||
if (initFromFiles( outMaterialTypeNr, VertexShaderFile, FragmentShaderFile))
|
||||
{
|
||||
useProgram();
|
||||
int dummy = 0;
|
||||
setUniform( TEXTURE_UNIT0, &dummy );
|
||||
dummy = 1;
|
||||
setUniform( TEXTURE_UNIT1, &dummy );
|
||||
}
|
||||
}
|
||||
|
||||
// fallback if compilation has failed
|
||||
|
@ -33,7 +33,8 @@ namespace video
|
||||
setDebugName( "COGLES2Renderer2d" );
|
||||
#endif
|
||||
s32 dummy = -1;
|
||||
initFromFiles( dummy, vertexShaderFile, fragmentShaderFile, false );
|
||||
if (!initFromFiles( dummy, vertexShaderFile, fragmentShaderFile, false))
|
||||
return;
|
||||
useProgram();
|
||||
int texUnit = 0;
|
||||
setUniform( TEXTURE_UNIT, &texUnit );
|
||||
|
@ -89,7 +89,7 @@ namespace video
|
||||
BaseMaterial->drop();
|
||||
}
|
||||
|
||||
void COGLES2SLMaterialRenderer::init(s32& outMaterialTypeNr,
|
||||
bool COGLES2SLMaterialRenderer::init(s32& outMaterialTypeNr,
|
||||
const c8* vertexShaderProgram,
|
||||
const c8* pixelShaderProgram,
|
||||
bool registerMaterial )
|
||||
@ -97,32 +97,35 @@ namespace video
|
||||
outMaterialTypeNr = -1;
|
||||
|
||||
if ( Program == 0 && !createProgram() )
|
||||
return;
|
||||
return false;
|
||||
|
||||
if ( vertexShaderProgram )
|
||||
if ( !createShader( GL_VERTEX_SHADER, vertexShaderProgram, "" ) )
|
||||
return;
|
||||
return false;
|
||||
|
||||
if ( pixelShaderProgram )
|
||||
if ( !createShader( GL_FRAGMENT_SHADER, pixelShaderProgram, "" ) )
|
||||
return;
|
||||
return false;
|
||||
|
||||
if ( !linkProgram() )
|
||||
return;
|
||||
return false;
|
||||
|
||||
// register myself as new material
|
||||
if ( registerMaterial )
|
||||
outMaterialTypeNr = Driver->addMaterialRenderer( this );
|
||||
return true;
|
||||
}
|
||||
|
||||
void COGLES2SLMaterialRenderer::initFromFiles( s32 &outMaterialTypeNr,
|
||||
bool COGLES2SLMaterialRenderer::initFromFiles( s32 &outMaterialTypeNr,
|
||||
const c8 *vertexShaderFile,
|
||||
const c8 *pixelShaderFile,
|
||||
bool registerMaterial )
|
||||
{
|
||||
outMaterialTypeNr = -1;
|
||||
if ( !createProgram() )
|
||||
{
|
||||
os::Printer::log( "Could not create shader program.", ELL_ERROR );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !readVertexShader( vertexShaderFile ) )
|
||||
@ -141,13 +144,15 @@ namespace video
|
||||
if ( !linkProgram() )
|
||||
{
|
||||
os::Printer::log( "Error linking fixed pipeline shader program.", ELL_ERROR );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( registerMaterial )
|
||||
outMaterialTypeNr = Driver->addMaterialRenderer( this );
|
||||
return true;
|
||||
}
|
||||
|
||||
void COGLES2SLMaterialRenderer::reloadFromFiles( const c8 *vertexShaderFile,
|
||||
bool COGLES2SLMaterialRenderer::reloadFromFiles( const c8 *vertexShaderFile,
|
||||
const c8 *pixelShaderFile )
|
||||
{
|
||||
GLsizei shaderCount;
|
||||
@ -170,7 +175,10 @@ namespace video
|
||||
if ( !linkProgram() )
|
||||
{
|
||||
os::Printer::log( "Error linking fixed pipeline shader program.", ELL_ERROR );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -446,6 +454,8 @@ namespace video
|
||||
|
||||
bool COGLES2SLMaterialRenderer::setUniform( int index, const void* data, int count )
|
||||
{
|
||||
if ((u32)index>=UniformInfo.size())
|
||||
return false;
|
||||
SUniformInfo& ui = UniformInfo[index];
|
||||
if ( ui.location == -1 )
|
||||
return false;
|
||||
|
@ -97,17 +97,17 @@ namespace video
|
||||
const u32& uniformCount,
|
||||
s32 userData = 0);
|
||||
|
||||
void init(s32& outMaterialTypeNr,
|
||||
bool init(s32& outMaterialTypeNr,
|
||||
const c8* vertexShaderProgram,
|
||||
const c8* pixelShaderProgram,
|
||||
bool registerMaterial = true);
|
||||
|
||||
void initFromFiles(s32& outMaterialTypeNr,
|
||||
bool initFromFiles(s32& outMaterialTypeNr,
|
||||
const c8* vertexShaderFile,
|
||||
const c8* pixelShaderFile,
|
||||
bool registerMaterial = true);
|
||||
|
||||
void reloadFromFiles(const c8* vertexShaderFile,
|
||||
bool reloadFromFiles(const c8* vertexShaderFile,
|
||||
const c8* pixelShaderFile);
|
||||
|
||||
bool readVertexShader(const c8* vertexShaderFile);
|
||||
|
Loading…
x
Reference in New Issue
Block a user