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;
_TextureTargetUpload = false;
currentProgram.vp = NULL;
currentProgram.pp = NULL;
currentProgram.gp = NULL;
currentProgram.dynmatVP = NULL;
currentProgram.dynmatPP = NULL;
m_UserVertexProgram = NULL;
m_UserGeometryProgram = NULL;
m_UserPixelProgram = NULL;
m_DriverVertexProgram = NULL;
m_DriverGeometryProgram = NULL;
m_DriverPixelProgram = NULL;
shaderGenerator = new CGLSLShaderGenerator();
usrShaderManager = new CUsrShaderManager();
@ -329,18 +330,6 @@ CDriverGL3::~CDriverGL3()
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;
shaderGenerator = NULL;
delete usrShaderManager;
@ -702,6 +691,14 @@ bool CDriverGL3::release()
// hide window
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...
IDriver::release();

@ -279,26 +279,6 @@ public:
class CGLSLShaderGenerator;
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
{
@ -712,13 +692,6 @@ private:
friend class CVertexProgamDrvInfosGL3;
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.
static const uint32 ReleaseVersion;
@ -1251,14 +1224,16 @@ private:
bool compileVertexProgram(CVertexProgram *program);
bool activeVertexProgram(CVertexProgram *program);
bool activeVertexProgram(CVertexProgram *program, bool driver);
bool supportPixelProgram(CPixelProgram::TProfile profile) const;
bool compilePixelProgram(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; }
@ -1347,13 +1322,20 @@ private:
private:
CGLSLShaderGenerator *shaderGenerator;
CUsrShaderManager *usrShaderManager;
bool initProgramPipeline();
CGLSLShaderGenerator *shaderGenerator;
CUsrShaderManager *usrShaderManager;
bool initProgramPipeline();
uint32 ppoId;
CVertexProgram *m_UserVertexProgram;
CGeometryProgram *m_UserGeometryProgram;
CPixelProgram *m_UserPixelProgram;
uint32 ppoId;
SProgram currentProgram;
CVertexProgram *m_DriverVertexProgram;
CGeometryProgram *m_DriverGeometryProgram;
CPixelProgram *m_DriverPixelProgram;
// init EMBM settings (set each stage to modify the next)
void initEMBM();

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

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

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

Loading…
Cancel
Save