GL3: Cleanup user program state

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 3885389b3b
commit 7a960ed768

@ -308,11 +308,12 @@ CDriverGL3::CDriverGL3()
_TextureTargetCubeFace = 0; _TextureTargetCubeFace = 0;
_TextureTargetUpload = false; _TextureTargetUpload = false;
currentProgram.vp = NULL; m_UserVertexProgram = NULL;
currentProgram.pp = NULL; m_UserGeometryProgram = NULL;
currentProgram.gp = NULL; m_UserPixelProgram = NULL;
currentProgram.dynmatVP = NULL; m_DriverVertexProgram = NULL;
currentProgram.dynmatPP = NULL; m_DriverGeometryProgram = NULL;
m_DriverPixelProgram = NULL;
shaderGenerator = new CGLSLShaderGenerator(); shaderGenerator = new CGLSLShaderGenerator();
usrShaderManager = new CUsrShaderManager(); usrShaderManager = new CUsrShaderManager();
@ -329,18 +330,6 @@ CDriverGL3::~CDriverGL3()
release(); release();
currentProgram.vp = NULL;
currentProgram.pp = NULL;
currentProgram.gp = NULL;
if (currentProgram.dynmatVP != NULL)
delete currentProgram.dynmatVP;
currentProgram.dynmatVP = NULL;
if (currentProgram.dynmatPP != NULL)
delete currentProgram.dynmatPP;
currentProgram.dynmatPP = NULL;
delete shaderGenerator; delete shaderGenerator;
shaderGenerator = NULL; shaderGenerator = NULL;
delete usrShaderManager; delete usrShaderManager;
@ -702,6 +691,14 @@ bool CDriverGL3::release()
// hide window // hide window
showWindow(false); showWindow(false);
m_DriverVertexProgram = NULL;
m_DriverGeometryProgram = NULL;
m_DriverPixelProgram = NULL;
m_UserVertexProgram = NULL;
m_UserGeometryProgram = NULL;
m_UserPixelProgram = NULL;
// Call IDriver::release() before, to destroy textures, shaders and VBs... // Call IDriver::release() before, to destroy textures, shaders and VBs...
IDriver::release(); IDriver::release();

@ -279,26 +279,6 @@ public:
class CGLSLShaderGenerator; class CGLSLShaderGenerator;
class CUsrShaderManager; class CUsrShaderManager;
struct SProgram
{
CVertexProgram *vp;
CPixelProgram *pp;
CGeometryProgram *gp;
CVertexProgram *dynmatVP;
CPixelProgram *dynmatPP;
SProgram()
{
vp = NULL;
pp = NULL;
gp = NULL;
dynmatVP = NULL;
dynmatPP = NULL;
}
};
// *************************************************************************** // ***************************************************************************
class CDriverGL3 : public IDriver class CDriverGL3 : public IDriver
{ {
@ -712,13 +692,6 @@ private:
friend class CVertexProgamDrvInfosGL3; friend class CVertexProgamDrvInfosGL3;
private: private:
/// Simply sets the current programs to NULL
void nullPrograms()
{
currentProgram.vp = NULL;
currentProgram.pp = NULL;
currentProgram.gp = NULL;
}
// Version of the driver. Not the interface version!! Increment when implementation of the driver change. // Version of the driver. Not the interface version!! Increment when implementation of the driver change.
static const uint32 ReleaseVersion; static const uint32 ReleaseVersion;
@ -1251,14 +1224,16 @@ private:
bool compileVertexProgram(CVertexProgram *program); bool compileVertexProgram(CVertexProgram *program);
bool activeVertexProgram(CVertexProgram *program); bool activeVertexProgram(CVertexProgram *program);
bool activeVertexProgram(CVertexProgram *program, bool driver);
bool supportPixelProgram(CPixelProgram::TProfile profile) const; bool supportPixelProgram(CPixelProgram::TProfile profile) const;
bool compilePixelProgram(CPixelProgram *program); bool compilePixelProgram(CPixelProgram *program);
bool activePixelProgram(CPixelProgram *program); bool activePixelProgram(CPixelProgram *program);
bool activePixelProgram(CPixelProgram *program, bool driver);
bool supportGeometryProgram(CGeometryProgram::TProfile profile) const{ return false; } bool supportGeometryProgram(CGeometryProgram::TProfile profile) const { return false; }
bool compileGeometryProgram(CGeometryProgram *program) { return false; } bool compileGeometryProgram(CGeometryProgram *program) { return false; }
@ -1347,13 +1322,20 @@ private:
private: private:
CGLSLShaderGenerator *shaderGenerator; CGLSLShaderGenerator *shaderGenerator;
CUsrShaderManager *usrShaderManager; CUsrShaderManager *usrShaderManager;
bool initProgramPipeline(); bool initProgramPipeline();
uint32 ppoId;
CVertexProgram *m_UserVertexProgram;
CGeometryProgram *m_UserGeometryProgram;
CPixelProgram *m_UserPixelProgram;
uint32 ppoId; CVertexProgram *m_DriverVertexProgram;
SProgram currentProgram; CGeometryProgram *m_DriverGeometryProgram;
CPixelProgram *m_DriverPixelProgram;
// init EMBM settings (set each stage to modify the next) // init EMBM settings (set each stage to modify the next)
void initEMBM(); void initEMBM();

@ -602,7 +602,9 @@ void CDriverGL3::endMultiPass()
bool CDriverGL3::setupDynMatPass(uint pass) bool CDriverGL3::setupDynMatPass(uint pass)
{ {
return false;
/*
if (!setupDynMatProgram(*_CurrentMaterial, pass)) if (!setupDynMatProgram(*_CurrentMaterial, pass))
return false; return false;
@ -703,21 +705,27 @@ bool CDriverGL3::setupDynMatPass(uint pass)
} }
return true; return true;
*/
} }
void CDriverGL3::setupNormalPass() void CDriverGL3::setupNormalPass()
{ {
nlassert(m_DriverPixelProgram);
const CMaterial &mat = *_CurrentMaterial; const CMaterial &mat = *_CurrentMaterial;
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++) for (int i = 0; i < _Extensions.NbFragmentTextureUnits; i++)
{ {
// Set constant if (!m_UserPixelProgram)
int cl = currentProgram.pp->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + i));
if (cl != -1)
{ {
GLfloat glCol[ 4 ]; // Set constant
convColor(mat._TexEnvs[ i ].ConstantColor, glCol); int cl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + i));
setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]); if (cl != -1)
{
GLfloat glCol[ 4 ];
convColor(mat._TexEnvs[ i ].ConstantColor, glCol);
setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
}
} }
// Set texture // Set texture
@ -725,7 +733,7 @@ void CDriverGL3::setupNormalPass()
if (t == NULL) if (t == NULL)
continue; continue;
int index = currentProgram.pp->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + i)); int index = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + i));
if (index == -1) if (index == -1)
continue; continue;
@ -795,6 +803,9 @@ sint CDriverGL3::beginLightMapMultiPass ()
// *************************************************************************** // ***************************************************************************
void CDriverGL3::setupLightMapPass(uint pass) void CDriverGL3::setupLightMapPass(uint pass)
{ {
nlassert(m_DriverPixelProgram);
nlassert(!m_UserPixelProgram);
H_AUTO_OGL(CDriverGL3_setupLightMapPass) H_AUTO_OGL(CDriverGL3_setupLightMapPass)
const CMaterial &mat= *_CurrentMaterial; const CMaterial &mat= *_CurrentMaterial;
@ -906,7 +917,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
// setup constant color with Lightmap factor. // setup constant color with Lightmap factor.
stdEnv.ConstantColor=lmapFactor; stdEnv.ConstantColor=lmapFactor;
int cl = currentProgram.pp->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + stage)); int cl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + stage));
if (cl != -1) if (cl != -1)
{ {
GLfloat glCol[ 4 ]; GLfloat glCol[ 4 ];
@ -914,7 +925,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]); setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
} }
int tl = currentProgram.pp->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + stage)); int tl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + stage));
if (tl != -1) if (tl != -1)
{ {
setUniform1i(IDriver::PixelProgram, tl, stage); setUniform1i(IDriver::PixelProgram, tl, stage);
@ -955,7 +966,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
_DriverGLStates.activeTexture(stage); _DriverGLStates.activeTexture(stage);
_DriverGLStates.setTexGenMode(stage, 0); _DriverGLStates.setTexGenMode(stage, 0);
int tl = currentProgram.pp->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + stage)); int tl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Sampler0 + stage));
if (tl != -1) if (tl != -1)
{ {
setUniform1i(IDriver::PixelProgram, tl, stage); setUniform1i(IDriver::PixelProgram, tl, stage);
@ -966,7 +977,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
else else
{ {
// else all other stages are disabled. // else all other stages are disabled.
activateTexture(stage,NULL); activateTexture(stage, NULL);
} }
} }
@ -1137,6 +1148,10 @@ sint CDriverGL3::beginSpecularMultiPass()
// *************************************************************************** // ***************************************************************************
void CDriverGL3::setupSpecularPass(uint pass) void CDriverGL3::setupSpecularPass(uint pass)
{ {
nlassert(m_DriverPixelProgram);
nlassert(!m_UserPixelProgram);
nlassert(m_DriverVertexProgram);
H_AUTO_OGL(CDriverGL3_setupSpecularPass) H_AUTO_OGL(CDriverGL3_setupSpecularPass)
const CMaterial &mat= *_CurrentMaterial; const CMaterial &mat= *_CurrentMaterial;
@ -1148,19 +1163,19 @@ void CDriverGL3::setupSpecularPass(uint pass)
return; return;
} }
int sl0 = currentProgram.pp->getUniformIndex(CProgramIndex::Sampler0); int sl0 = m_DriverPixelProgram->getUniformIndex(CProgramIndex::Sampler0);
if (sl0 != -1) if (sl0 != -1)
{ {
setUniform1i(IDriver::PixelProgram, sl0, 0); setUniform1i(IDriver::PixelProgram, sl0, 0);
} }
int sl1 = currentProgram.pp->getUniformIndex(CProgramIndex::Sampler1); int sl1 = m_DriverPixelProgram->getUniformIndex(CProgramIndex::Sampler1);
if (sl1 != -1) if (sl1 != -1)
{ {
setUniform1i(IDriver::PixelProgram, sl1, 1); setUniform1i(IDriver::PixelProgram, sl1, 1);
} }
int tml = currentProgram.vp->getUniformIndex(CProgramIndex::TexMatrix0); int tml = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix0); // FIXME GL3 VERTEX PROGRAM
if (tml != -1) if (tml != -1)
{ {
setUniform4x4f(IDriver::VertexProgram, tml, _UserTexMat[ 1 ]); setUniform4x4f(IDriver::VertexProgram, tml, _UserTexMat[ 1 ]);

@ -144,26 +144,34 @@ namespace NL3D
bool CDriverGL3::activeVertexProgram(CVertexProgram *program) bool CDriverGL3::activeVertexProgram(CVertexProgram *program)
{ {
return activeVertexProgram(program, false);
}
bool CDriverGL3::activeVertexProgram(CVertexProgram *program, bool driver)
{
if (driver) nlassert(m_UserVertexProgram == NULL);
if (program == NULL) if (program == NULL)
{
nglUseProgramStages(ppoId, GL_VERTEX_SHADER_BIT, 0);
m_UserVertexProgram = NULL;
m_DriverVertexProgram = NULL;
return true; return true;
}
IProgramDrvInfos *di = program->m_DrvInfo; IProgramDrvInfos *di = program->m_DrvInfo;
CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di); CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di);
if (drvInfo == NULL) if (drvInfo == NULL)
return false; return false;
glGetError(); glGetError();
nglUseProgramStages(ppoId, GL_VERTEX_SHADER_BIT, drvInfo->getProgramId()); nglUseProgramStages(ppoId, GL_VERTEX_SHADER_BIT, drvInfo->getProgramId());
GLenum error = glGetError(); GLenum error = glGetError();
if (error != GL_NO_ERROR) if (error != GL_NO_ERROR)
{
return false; return false;
}
currentProgram.vp = program; if (!driver) m_UserVertexProgram = program;
m_DriverVertexProgram = program;
return true; return true;
} }
@ -234,8 +242,20 @@ namespace NL3D
bool CDriverGL3::activePixelProgram(CPixelProgram *program) bool CDriverGL3::activePixelProgram(CPixelProgram *program)
{ {
return activePixelProgram(program, false);
}
bool CDriverGL3::activePixelProgram(CPixelProgram *program, bool driver)
{
if (driver) nlassert(m_UserPixelProgram == NULL);
if (program == NULL) if (program == NULL)
{
nglUseProgramStages(ppoId, GL_FRAGMENT_SHADER_BIT, 0);
m_UserPixelProgram = NULL;
m_DriverPixelProgram = NULL;
return true; return true;
}
if (program->m_DrvInfo == NULL) if (program->m_DrvInfo == NULL)
return false; return false;
@ -244,18 +264,15 @@ namespace NL3D
CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di); CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di);
if (drvInfo == NULL) if (drvInfo == NULL)
return false; return false;
glGetError(); glGetError();
nglUseProgramStages(ppoId, GL_FRAGMENT_SHADER_BIT, drvInfo->getProgramId()); nglUseProgramStages(ppoId, GL_FRAGMENT_SHADER_BIT, drvInfo->getProgramId());
GLenum error = glGetError(); GLenum error = glGetError();
if (error != GL_NO_ERROR) if (error != GL_NO_ERROR)
{
return false; return false;
}
currentProgram.pp = program; if (!driver) m_UserPixelProgram = program;
m_DriverPixelProgram = program;
return true; return true;
} }
@ -268,21 +285,19 @@ namespace NL3D
switch(program) switch(program)
{ {
case IDriver::VertexProgram: case IDriver::VertexProgram:
if (m_DriverVertexProgram)
{ {
if (currentProgram.vp != NULL) IProgramDrvInfos *di = m_DriverVertexProgram->m_DrvInfo;
{ CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di);
IProgramDrvInfos *di = currentProgram.vp->m_DrvInfo; if (drvInfo != NULL)
CVertexProgramDrvInfosGL3 *drvInfo = dynamic_cast< CVertexProgramDrvInfosGL3* >(di); id = drvInfo->getProgramId();
if (drvInfo != NULL)
id = drvInfo->getProgramId();
}
} }
break; break;
case IDriver::PixelProgram: case IDriver::PixelProgram:
if (currentProgram.pp != NULL) if (m_DriverPixelProgram)
{ {
IProgramDrvInfos *di = currentProgram.pp->m_DrvInfo; IProgramDrvInfos *di = m_DriverPixelProgram->m_DrvInfo;
CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di); CPixelProgramDrvInfosGL3 *drvInfo = dynamic_cast< CPixelProgramDrvInfosGL3* >(di);
if (drvInfo != NULL) if (drvInfo != NULL)
id = drvInfo->getProgramId(); id = drvInfo->getProgramId();
@ -298,24 +313,17 @@ namespace NL3D
IProgram* CDriverGL3::getProgram(TProgram program) const IProgram* CDriverGL3::getProgram(TProgram program) const
{ {
IProgram *p = NULL;
switch(program) switch(program)
{ {
case IDriver::VertexProgram: case IDriver::VertexProgram:
p = currentProgram.vp; return m_DriverVertexProgram;
break;
case IDriver::PixelProgram: case IDriver::PixelProgram:
p = currentProgram.pp; return m_DriverPixelProgram;
break;
case IDriver::GeometryProgram: case IDriver::GeometryProgram:
p = currentProgram.gp; return m_DriverGeometryProgram;
break;
} }
return p; return NULL;
} }
int CDriverGL3::getUniformLocation(TProgram program, const char *name) int CDriverGL3::getUniformLocation(TProgram program, const char *name)
@ -585,6 +593,9 @@ namespace NL3D
bool CDriverGL3::setupProgram(CMaterial &mat) bool CDriverGL3::setupProgram(CMaterial &mat)
{ {
// nlassert(!m_UserVertexProgram); // TEMP
// nlassert(!m_UserPixelProgram); // TEMP
if (mat.getDynMat() != NULL) if (mat.getDynMat() != NULL)
return true; return true;
@ -602,15 +613,15 @@ namespace NL3D
// Yes we have! // Yes we have!
if (!sp.empty()) if (!sp.empty())
{ {
if (currentProgram.vp == NULL) if (m_UserVertexProgram == NULL)
{ {
if (!activeVertexProgram(sp.vp)) if (!activeVertexProgram(sp.vp, true))
return false; return false;
} }
if (currentProgram.pp == NULL) if (m_UserPixelProgram == NULL)
{ {
if (!activePixelProgram(sp.pp)) if (!activePixelProgram(sp.pp, true))
return false; return false;
} }
} }
@ -627,7 +638,7 @@ namespace NL3D
shaderGenerator->setShaderDesc(&desc); shaderGenerator->setShaderDesc(&desc);
// If we don't already have a vertex program attached, we'll generate it now // If we don't already have a vertex program attached, we'll generate it now
if (currentProgram.vp == NULL) if (m_UserVertexProgram == NULL)
{ {
shaderGenerator->generateVS(vs); shaderGenerator->generateVS(vs);
vp = new CVertexProgram(); vp = new CVertexProgram();
@ -646,7 +657,7 @@ namespace NL3D
return false; return false;
} }
if (!activeVertexProgram(vp)) if (!activeVertexProgram(vp, true))
{ {
delete vp; delete vp;
vp = NULL; vp = NULL;
@ -657,7 +668,7 @@ namespace NL3D
cacheShaders = false; cacheShaders = false;
// If we don't already have a pixel program attached, we'll generate it now // If we don't already have a pixel program attached, we'll generate it now
if (currentProgram.pp == NULL) if (m_UserPixelProgram == NULL)
{ {
shaderGenerator->generatePS(ps); shaderGenerator->generatePS(ps);
pp = new CPixelProgram(); pp = new CPixelProgram();
@ -678,7 +689,7 @@ namespace NL3D
return false; return false;
} }
if (!activePixelProgram(pp)) if (!activePixelProgram(pp, true))
{ {
delete vp; delete vp;
vp = NULL; vp = NULL;
@ -708,6 +719,7 @@ namespace NL3D
bool CDriverGL3::setupDynMatProgram(CMaterial& mat, uint pass) bool CDriverGL3::setupDynMatProgram(CMaterial& mat, uint pass)
{ {
/*
if ((currentProgram.vp != NULL) && (currentProgram.pp != NULL)) if ((currentProgram.vp != NULL) && (currentProgram.pp != NULL))
return true; return true;
@ -790,6 +802,8 @@ namespace NL3D
} }
return true; return true;
*/
return false;
} }

@ -70,8 +70,6 @@ bool CDriverGL3::renderLines(CMaterial& mat, uint32 firstIndex, uint32 nlines)
_PrimitiveProfileIn.NLines+= nlines; _PrimitiveProfileIn.NLines+= nlines;
_PrimitiveProfileOut.NLines+= nlines; _PrimitiveProfileOut.NLines+= nlines;
nullPrograms();
return true; return true;
} }
@ -123,8 +121,6 @@ bool CDriverGL3::renderTriangles(CMaterial& mat, uint32 firstIndex, uint32 ntris
_PrimitiveProfileIn.NTriangles+= ntris; _PrimitiveProfileIn.NTriangles+= ntris;
_PrimitiveProfileOut.NTriangles+= ntris * nPass; _PrimitiveProfileOut.NTriangles+= ntris * nPass;
nullPrograms();
return true; return true;
} }
@ -158,8 +154,6 @@ bool CDriverGL3::renderSimpleTriangles(uint32 firstTri, uint32 ntris)
_PrimitiveProfileIn.NTriangles+= ntris; _PrimitiveProfileIn.NTriangles+= ntris;
_PrimitiveProfileOut.NTriangles+= ntris; _PrimitiveProfileOut.NTriangles+= ntris;
nullPrograms();
return true; return true;
} }
@ -198,8 +192,6 @@ bool CDriverGL3::renderRawPoints(CMaterial& mat, uint32 startIndex, uint32 numPo
_PrimitiveProfileIn.NPoints+= numPoints; _PrimitiveProfileIn.NPoints+= numPoints;
_PrimitiveProfileOut.NPoints+= numPoints * nPass; _PrimitiveProfileOut.NPoints+= numPoints * nPass;
nullPrograms();
return true; return true;
} }
@ -238,8 +230,6 @@ bool CDriverGL3::renderRawLines(CMaterial& mat, uint32 startIndex, uint32 numLin
_PrimitiveProfileIn.NLines += numLines ; _PrimitiveProfileIn.NLines += numLines ;
_PrimitiveProfileOut.NLines += numLines * nPass; _PrimitiveProfileOut.NLines += numLines * nPass;
nullPrograms();
return true; return true;
} }
@ -280,8 +270,6 @@ bool CDriverGL3::renderRawTriangles(CMaterial& mat, uint32 startIndex, uint32 nu
_PrimitiveProfileIn.NTriangles += numTris ; _PrimitiveProfileIn.NTriangles += numTris ;
_PrimitiveProfileOut.NTriangles += numTris * nPass; _PrimitiveProfileOut.NTriangles += numTris * nPass;
nullPrograms();
return true; return true;
} }
@ -402,8 +390,6 @@ bool CDriverGL3::renderRawQuads(CMaterial& mat, uint32 startIndex, uint32 numQua
_PrimitiveProfileIn.NQuads += numQuads ; _PrimitiveProfileIn.NQuads += numQuads ;
_PrimitiveProfileOut.NQuads += numQuads * nPass; _PrimitiveProfileOut.NQuads += numQuads * nPass;
nullPrograms();
return true; return true;
} }

Loading…
Cancel
Save