GL3: Cleanup

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 07f663a68e
commit cb3f3b72c5

@ -411,7 +411,7 @@ bool CDriverGL3::setupDisplay()
// Activate the default texture environnments for all stages.
//===========================================================
for (uint stage=0;stage<inlGetNumTextStages(); stage++)
for (uint stage = 0; stage < inlGetNumTextStages(); ++stage)
{
// init no texture.
_CurrentTexture[stage] = NULL;
@ -422,11 +422,8 @@ bool CDriverGL3::setupDisplay()
CMaterial::CTexEnv env; // envmode init to default.
env.ConstantColor.set(255,255,255,255);
// Not special TexEnv.
_CurrentTexEnvSpecial[stage] = TexEnvSpecialDisabled;
// set All TexGen by default to identity matrix (prefer use the textureMatrix scheme)
setTexGenModeVP(stage, TexGenDisabled); // FIXME GL3 TEXGEN
setTexGenModeVP(stage, TexGenDisabled);
}
if (!initProgramPipeline())
@ -616,18 +613,13 @@ bool CDriverGL3::swapBuffers()
//===========================================================
// This is not a requirement, but it ensure a more stable state each frame.
// (well, maybe the good reason is "it hides much more the bugs" :o)).
for (uint stage=0;stage<inlGetNumTextStages(); stage++)
for (uint stage = 0; stage < inlGetNumTextStages(); ++stage)
{
// init no texture.
_CurrentTexture[stage]= NULL;
_CurrentTextureInfoGL[stage]= NULL;
// texture are disabled in DriverGLStates.forceDefaults().
// init default env.
CMaterial::CTexEnv env; // envmode init to default.
env.ConstantColor.set(255,255,255,255);
forceActivateTexEnvMode(stage, env);
forceActivateTexEnvColor(stage, env);
setTexGenModeVP(stage, TexGenDisabled);
}
// Activate the default material.

@ -352,7 +352,7 @@ public:
virtual void forceNativeFragmentPrograms(bool nativeOnly);
/// Setup texture env functions. Used by setupMaterial
void setTextureEnvFunction(uint stage, CMaterial& mat);
void setTexGenFunction(uint stage, CMaterial& mat);
/// setup the texture matrix for a given number of stages (starting from 0)
void setupUserTextureMatrix(uint numStages, CMaterial& mat);
@ -368,10 +368,9 @@ public:
virtual bool setupMaterial(CMaterial& mat);
void generateShaderDesc(CShaderDesc &desc, CMaterial &mat);
bool setupBuiltinPrograms(CMaterial& mat);
bool setupBuiltinPrograms();
bool setupBuiltinVertexProgram();
bool setupBuiltinPixelProgram(CMaterial& mat);
bool setupDynMatProgram(CMaterial& mat, uint pass);
bool setupBuiltinPixelProgram();
bool setupUniforms();
void setupUniforms(TProgram program);
void setupInitialUniforms(IProgram *program);
@ -904,7 +903,7 @@ private:
// @{
// Special Texture environnements.
enum CTexEnvSpecial {
/*enum CTexEnvSpecial {
TexEnvSpecialDisabled= 0,
TexEnvSpecialLightMap,
TexEnvSpecialSpecularStage1,
@ -913,7 +912,7 @@ private:
TexEnvSpecialPPLStage2,
TexEnvSpecialCloudStage0,
TexEnvSpecialCloudStage1
};
};*/
// NB: CRefPtr are not used for mem/spped optimisation. setupMaterial() and setupTexture() reset those states.
CMaterial* _CurrentMaterial;
@ -924,9 +923,9 @@ private:
ITexture* _CurrentTexture[IDRV_MAT_MAXTEXTURES];
CTextureDrvInfosGL3* _CurrentTextureInfoGL[IDRV_MAT_MAXTEXTURES];
CMaterial::CTexEnv _CurrentTexEnv[IDRV_MAT_MAXTEXTURES];
//CMaterial::CTexEnv _CurrentTexEnv[IDRV_MAT_MAXTEXTURES];
// Special Texture Environnement.
CTexEnvSpecial _CurrentTexEnvSpecial[IDRV_MAT_MAXTEXTURES];
//CTexEnvSpecial _CurrentTexEnvSpecial[IDRV_MAT_MAXTEXTURES];
// Texture addressing mode
GLenum _CurrentTexAddrMode[IDRV_MAT_MAXTEXTURES];
// Anisotropic filtering value
@ -992,23 +991,23 @@ private:
// Activate Texture Environnement. Do it with caching.
bool activateTexture(uint stage, ITexture *tex);
// NB: this test _CurrentTexEnv[] and _CurrentTexEnvSpecial[].
void activateTexEnvMode(uint stage, const CMaterial::CTexEnv &env);
void activateTexEnvColor(uint stage, const CMaterial::CTexEnv &env);
//void activateTexEnvMode(uint stage, const CMaterial::CTexEnv &env);
//void activateTexEnvColor(uint stage, const CMaterial::CTexEnv &env);
// Force Activate Texture Environnement. no caching here. TexEnvSpecial is disabled.
void forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv &env);
void activateTexEnvColor(uint stage, NLMISC::CRGBA col);
//void forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv &env);
//void activateTexEnvColor(uint stage, NLMISC::CRGBA col);
void forceActivateTexEnvColor(uint stage, NLMISC::CRGBA col)
/*void forceActivateTexEnvColor(uint stage, NLMISC::CRGBA col)
{
static const float OO255= 1.0f/255;
_CurrentTexEnv[stage].ConstantColor= col;
}
}*/
/*
void forceActivateTexEnvColor(uint stage, const CMaterial::CTexEnv &env)
{
H_AUTO_OGL(CDriverGL3_forceActivateTexEnvColor)
forceActivateTexEnvColor(stage, env.ConstantColor);
}
}*/
// According to extensions, retrieve GL tex format of the texture.
GLint getGlTextureFormat(ITexture& tex, bool &compressed);

@ -113,21 +113,12 @@ static inline void convTexAddr(ITexture *tex, CMaterial::TTexAddressingMode mode
}
// --------------------------------------------------
void CDriverGL3::setTextureEnvFunction(uint stage, CMaterial& mat)
void CDriverGL3::setTexGenFunction(uint stage, CMaterial& mat)
{
H_AUTO_OGL(CDriverGL3_setTextureEnvFunction)
H_AUTO_OGL(CDriverGL3_setTexGenFunction)
ITexture *text = mat.getTexture(uint8(stage));
if (text)
{
CMaterial::CTexEnv &env= mat._TexEnvs[stage];
// Activate the env for this stage.
// NB: Thoses calls use caching.
activateTexEnvMode(stage, env);
activateTexEnvColor(stage, env);
// Activate texture generation mapping
//_DriverGLStates.activeTexture(stage);
if (mat.getTexCoordGen(stage))
{
// set mode and enable.
@ -240,7 +231,6 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
CMaterial::TShader matShader;
GLenum glenum = GL_ZERO;
uint32 touched = mat.getTouched();
uint stage;
// profile.
_NbSetupMaterialCall++;
@ -315,15 +305,8 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// 2b. User supplied pixel shader overrides material
//==================================
if (m_UserPixelProgram)
{
matShader = CMaterial::Program;
}
else
{
// Now we can get the supported shader from the cache.
matShader = pShader->SupportedShader;
}
// 2b. Update more shader state
//==================================
@ -349,7 +332,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// because setupTexture() may disable all stage.
if (matShader != CMaterial::Water && matShader != CMaterial::Program)
{
for (stage=0 ; stage<inlGetNumTextStages() ; stage++)
for (uint stage = 0; stage < inlGetNumTextStages(); ++stage)
{
ITexture *text = mat.getTexture(uint8(stage));
if (text != NULL && !setupTexture(*text))
@ -359,11 +342,11 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// Here, for Lightmap materials, setup the lightmaps.
if (matShader == CMaterial::LightMap)
{
for (stage = 0; stage < mat._LightMaps.size(); stage++)
for (uint stage = 0; stage < mat._LightMaps.size(); stage++)
{
ITexture *text = mat._LightMaps[stage].Texture;
if (text != NULL && !setupTexture(*text))
return(false);
return false;
}
}
@ -376,23 +359,27 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// Activate the textures.
// Do not do it for Lightmap and per pixel lighting , because done in multipass in a very special fashion.
// This avoid the useless multiple change of texture states per lightmapped object.
// Don't do it also for Specular because the EnvFunction and the TexGen may be special.
if (matShader != CMaterial::LightMap
&& matShader != CMaterial::PerPixelLighting
/* && matShader != CMaterial::Caustics */
&& matShader != CMaterial::Cloud
&& matShader != CMaterial::Water
&& matShader != CMaterial::Specular
&& matShader != CMaterial::Program
)
{
for (stage=0 ; stage<inlGetNumTextStages() ; stage++)
uint maxTex = matShader == CMaterial::Specular ? 2 : inlGetNumTextStages();
for (uint stage = 0; stage < maxTex; ++stage)
{
ITexture *text = mat.getTexture(uint8(stage));
// activate the texture, or disable texturing if NULL.
activateTexture(stage, text);
// Specular has it's own env function setup by startSpecularBatch
if (matShader != CMaterial::Specular)
{
setTexGenFunction(stage, mat);
}
}
}
@ -497,7 +484,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// 5. Set up the program
// =====================
return setupBuiltinPrograms(mat);
return setupBuiltinPrograms();
}
// ***************************************************************************
@ -524,7 +511,8 @@ sint CDriverGL3::beginMultiPass()
return beginCloudMultiPass();
// All others materials require just 1 pass.
default: return 1;
default:
return 1;
}
}
@ -597,127 +585,17 @@ void CDriverGL3::endMultiPass()
}
}
bool CDriverGL3::setupDynMatPass(uint pass)
{
return false;
/*
if (!setupDynMatProgram(*_CurrentMaterial, pass))
return false;
if ((_CurrentMaterial->getFlags() & IDRV_MAT_DOUBLE_SIDED) != 0)
_DriverGLStates.enableCullFace(false);
else
_DriverGLStates.enableCullFace(true);
CDynMaterial *m = _CurrentMaterial->getDynMat();
SRenderPass *currentPass = m->getPass(pass);
IProgram *p;
IProgram* programs[ 2 ];
programs[ 0 ] = currentProgram.vp;
programs[ 1 ] = currentProgram.pp;
IDriver::TProgram type[ 2 ];
type[ 0 ] = IDriver::VertexProgram;
type[ 1 ] = IDriver::PixelProgram;
for (uint32 j = 0; j < 2; j++)
{
p = programs[ j ];
for (uint32 i = 0; i < currentPass->count(); i++)
{
const SDynMaterialProp *prop = currentPass->getProperty(i);
int loc = getUniformLocation(type[ j ], prop->prop.c_str());
if (loc == -1)
continue;
switch(prop->type)
{
case SDynMaterialProp::Float:
setUniform1f(type[ j ], loc, prop->value.toFloat());
break;
case SDynMaterialProp::Int:
setUniform1i(type[ j ], loc, prop->value.toInt());
break;
case SDynMaterialProp::Uint:
setUniform1ui(type[ j ], loc, prop->value.toUInt());
break;
case SDynMaterialProp::Color:
{
float v[ 4 ];
prop->value.getVector4(v);
for (int k = 0; k < 4; k++)
v[ k ] = v[ k ] / 255.0f;
setUniform4f(type[ j ], loc, v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ]);
}
break;
case SDynMaterialProp::Vector4:
{
float v[ 4 ];
prop->value.getVector4(v);
setUniform4f(type[ j ], loc, v[ 0 ], v[ 1 ], v[ 2 ], v[ 3 ]);
}
break;
case SDynMaterialProp::Matrix4:
{
float m[ 16 ];
prop->value.getMatrix4(m);
setUniform4x4f(type[ j ], loc, m);
break;
}
case SDynMaterialProp::Texture:
break;
}
}
////////////////////////////////// Set up some standard uniforms //////////////////////////////////
int loc = -1;
loc = getUniformLocation(type[ j ], "mvpMatrix");
if (loc != -1)
{
CMatrix mat = _GLProjMat * _ModelViewMatrix;
setUniform4x4f(type[ j ], loc, mat);
}
loc = getUniformLocation(type[ j ], "mvMatrix");
if (loc != -1)
{
setUniform4x4f(type[ j ], loc, _ModelViewMatrix);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
return true;
*/
}
void CDriverGL3::setupNormalPass()
{
nlassert(m_DriverPixelProgram);
const CMaterial &mat = *_CurrentMaterial;
for (int i = 0; i < _Extensions.NbFragmentTextureUnits; i++)
for (int i = 0; i < IDRV_MAT_MAXTEXTURES; i++)
{
if (!m_UserPixelProgram)
{
// Set constant
int cl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + i));
if (cl != -1)
// Set constants for TexEnv
uint cl = m_DriverPixelProgram->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + i));
if (cl != ~0)
{
GLfloat glCol[4];
convColor(mat._TexEnvs[i].ConstantColor, glCol);
@ -725,7 +603,6 @@ void CDriverGL3::setupNormalPass()
}
}
}
}
// ***************************************************************************
void CDriverGL3::computeLightMapInfos (const CMaterial &mat)
@ -762,6 +639,9 @@ void CDriverGL3::computeLightMapInfos (const CMaterial &mat)
sint CDriverGL3::beginLightMapMultiPass ()
{
H_AUTO_OGL(CDriverGL3_beginLightMapMultiPass)
//setupBuiltinPrograms(); // FIXME GL3
const CMaterial &mat= *_CurrentMaterial;
// compute how many lightmap and pass we must process.
@ -811,8 +691,8 @@ void CDriverGL3::setupLightMapPass(uint pass)
activateTexture(0,text);
// setup std modulate env
CMaterial::CTexEnv env;
activateTexEnvMode(0, env);
//CMaterial::CTexEnv env;
//activateTexEnvMode(0, env); // FIXME GL3
// Since Lighting is disabled, as well as colorArray, must setup alpha.
// setup color to 0 => blackness. in emissive cause texture can still be lighted by dynamic light
@ -820,7 +700,7 @@ void CDriverGL3::setupLightMapPass(uint pass)
// FIXME GL3 LIGHTMAP
// Setup gen tex off
setTexGenModeVP(0, TexGenDisabled);
// setTexGenModeVP(0, TexGenDisabled); // FIXME GL3
// And disable other stages.
for (uint stage = 1; stage < inlGetNumTextStages(); stage++)
@ -913,17 +793,17 @@ void CDriverGL3::setupLightMapPass(uint pass)
setUniform4f(IDriver::PixelProgram, cl, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ]);
}
activateTexEnvColor(stage, stdEnv);
// activateTexEnvColor(stage, stdEnv); // FIXME GL3
// Setup env for texture stage.
setTexGenModeVP(stage, TexGenDisabled);
// setTexGenModeVP(stage, TexGenDisabled); // FIXME GL3
// setup TexEnvCombine4 (ignore alpha part).
if (_CurrentTexEnvSpecial[stage] != TexEnvSpecialLightMap)
/*if (_CurrentTexEnvSpecial[stage] != TexEnvSpecialLightMap)
{
// TexEnv is special.
_CurrentTexEnvSpecial[stage] = TexEnvSpecialLightMap;
}
}*/ // FIXME GL3
}
}
@ -941,10 +821,10 @@ void CDriverGL3::setupLightMapPass(uint pass)
activateTexture(stage,text);
// setup ModulateRGB/ReplaceAlpha env. (this may disable possible COMBINE4_NV setup).
activateTexEnvMode(stage, _LightMapLastStageEnv);
// activateTexEnvMode(stage, _LightMapLastStageEnv); // FIXME GL3
// Setup gen tex off
setTexGenModeVP(stage, TexGenDisabled);
// setTexGenModeVP(stage, TexGenDisabled); // FIXME GL3
}
}
else
@ -1053,31 +933,9 @@ void CDriverGL3::endSpecularBatch()
void CDriverGL3::setupSpecularBegin()
{
H_AUTO_OGL(CDriverGL3_setupSpecularBegin)
// ---- Reset any textures with id>=2
uint stage = 2;
for (; stage < inlGetNumTextStages(); stage++)
{
// disable texturing
activateTexture(stage, NULL);
}
// ---- Stage 0 Common Setup.
// Setup the env for stage 0 only.
// Result RGB : Texture*Diffuse, Alpha : Texture
CMaterial::CTexEnv env;
env.Env.OpAlpha= CMaterial::Replace;
activateTexEnvMode(0, env);
// Disable texGen for stage 0
setTexGenModeVP(0, TexGenDisabled);
// ---- Stage 1 Common Setup.
// NB don't setup the TexEnv here (stage1 setuped in setupSpecularPass() according to extensions)
// For all cases, setup the TexCoord gen for stage1
_DriverGLStates.activeTexture(1);
// todo hulud remove - lol
// _DriverGLStates.setTextureMode(CDriverGLStates::TextureCubeMap);
setTexGenModeVP(1, TexGenReflectionMap);
// setup the good matrix for stage 1.
@ -1101,25 +959,14 @@ sint CDriverGL3::beginSpecularMultiPass()
H_AUTO_OGL(CDriverGL3_beginSpecularMultiPass)
const CMaterial &mat= *_CurrentMaterial;
// activate the 2 textures here
uint stage;
uint numStages= std::min((uint)2, inlGetNumTextStages());
for (stage=0 ; stage<numStages; stage++)
{
ITexture *text= mat.getTexture(uint8(stage));
// activate the texture, or disable texturing if NULL.
activateTexture(stage,text);
}
// End specular , only if not Batching mode.
if (!_SpecularBatchOn)
setupSpecularBegin();
// Manage the rare case when the SpecularMap is not provided (fault of graphist).
if (mat.getTexture(1)==NULL)
return 1;
// Setup programs
//setupBuiltinPrograms();
// Only need one pass for specular
return 1;
}
@ -1127,57 +974,15 @@ 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;
// Manage the rare case when the SpecularMap is not provided (error of a graphist).
if (mat.getTexture(1)==NULL)
{
// Just display the texture
// NB: setupMaterial() code has correclty setuped textures.
return;
}
int tm0 = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix0); // FIXME GL3 VERTEX PROGRAM
if (tm0 != -1)
{
setUniform4x4f(IDriver::VertexProgram, tm0, _UserTexMat[ 0 ]); // OR is it just 1 (and not 0 2 3)?
}
int tm2 = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix2); // FIXME GL3 VERTEX PROGRAM
if (tm2 != -1)
{
setUniform4x4f(IDriver::VertexProgram, tm2, _UserTexMat[ 2 ]);
}
int tm3 = m_DriverVertexProgram->getUniformIndex(CProgramIndex::TexMatrix3); // FIXME GL3 VERTEX PROGRAM
if (tm3 != -1)
{
setUniform4x4f(IDriver::VertexProgram, tm3, _UserTexMat[ 3 ]);
}
{
// Ok we can do it in a single pass
// Set Stage 1
// Special: not the same special env if there is or not texture in stage 0.
CTexEnvSpecial newEnvStage1;
if (mat.getTexture(0) == NULL)
newEnvStage1= TexEnvSpecialSpecularStage1NoText;
else
newEnvStage1= TexEnvSpecialSpecularStage1;
// Test if same env as prec.
if (_CurrentTexEnvSpecial[1] != newEnvStage1)
for (uint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage) // Verify: Is it really only Specular that uses TexMatrix?
{
// TexEnv is special.
_CurrentTexEnvSpecial[1] = newEnvStage1;
_DriverGLStates.activeTexture(1);
}
uint idx = m_DriverVertexProgram->getUniformIndex((CProgramIndex::TName)(CProgramIndex::TexMatrix0 + stage));
if (idx != ~0)
setUniform4x4f(IDriver::VertexProgram, idx, _UserTexMat[stage]);
}
}
@ -1185,6 +990,7 @@ void CDriverGL3::setupSpecularPass(uint pass)
void CDriverGL3::endSpecularMultiPass()
{
H_AUTO_OGL(CDriverGL3_endSpecularMultiPass)
// End specular , only if not Batching mode.
if (!_SpecularBatchOn)
setupSpecularEnd();
@ -1313,6 +1119,9 @@ CTextureCube *CDriverGL3::getSpecularCubeMap(uint exp)
sint CDriverGL3::beginPPLMultiPass()
{
H_AUTO_OGL(CDriverGL3_beginPPLMultiPass)
//setupBuiltinPrograms(); // FIXME GL3
#ifdef NL_DEBUG
nlassert(supportPerPixelLighting(true)); // make sure the hardware can do that
#endif
@ -1350,7 +1159,7 @@ void CDriverGL3::setupPPLPass(uint pass)
// Stage 0 is rgb = DiffuseCubeMap * LightColor + DiffuseGouraud * 1
activateTexEnvColor(0, _PPLightDiffuseColor);
// activateTexEnvColor(0, _PPLightDiffuseColor); // FIXME GL3
// Stage 1
// alpha = diffuse alpha
@ -1358,7 +1167,7 @@ void CDriverGL3::setupPPLPass(uint pass)
// Stage 2 is rgb = SpecularCubeMap * SpecularLightColor + Prec * 1
// alpha = prec alpha
activateTexEnvColor(2, _PPLightSpecularColor);
// activateTexEnvColor(2, _PPLightSpecularColor); // FIXME GL3
}
@ -1373,6 +1182,9 @@ void CDriverGL3::endPPLMultiPass()
sint CDriverGL3::beginPPLNoSpecMultiPass()
{
H_AUTO_OGL(CDriverGL3_beginPPLNoSpecMultiPass)
//setupBuiltinPrograms(); // FIXME GL3
#ifdef NL_DEBUG
nlassert(supportPerPixelLighting(false)); // make sure the hardware can do that
#endif
@ -1407,12 +1219,12 @@ void CDriverGL3::setupPPLNoSpecPass(uint pass)
// Stage 0 is rgb = DiffuseCubeMap * LightColor + DiffuseGouraud * 1 (TODO : EnvCombine3)
activateTexEnvColor(0, _PPLightDiffuseColor);
// activateTexEnvColor(0, _PPLightDiffuseColor); // FIXME GL3
// Stage 1
static CMaterial::CTexEnv env;
/*static CMaterial::CTexEnv env;
env.Env.SrcArg1Alpha = CMaterial::Diffuse;
activateTexEnvMode(1, env);
activateTexEnvMode(1, env);*/ // FIXME GL3
}
@ -1444,7 +1256,7 @@ void CDriverGL3::endPPLNoSpecMultiPass()
activateTexture(0, mat.getTexture(0));
/// texture environment 0
setTextureEnvFunction(0, mat);
setTexGenFunction(0, mat);
/// texture matrix 0
setupUserTextureMatrix(0, mat);
@ -1501,6 +1313,9 @@ void CDriverGL3::endCausticsMultiPass(const CMaterial &mat)
sint CDriverGL3::beginCloudMultiPass ()
{
H_AUTO_OGL(CDriverGL3_beginCloudMultiPass)
//setupBuiltinPrograms(); // FIXME GL3
nlassert(_CurrentMaterial->getShader() == CMaterial::Cloud);
return 1;
}
@ -1528,6 +1343,9 @@ void CDriverGL3::endCloudMultiPass()
sint CDriverGL3::beginWaterMultiPass()
{
H_AUTO_OGL(CDriverGL3_beginWaterMultiPass)
//setupBuiltinPrograms(); // FIXME GL3
nlassert(_CurrentMaterial->getShader() == CMaterial::Water);
return 1;
}

@ -629,10 +629,10 @@ void CDriverGL3::generateShaderDesc(CShaderDesc &desc, CMaterial &mat)
desc.setLighting(/*enableLights && mat.isLighted() &&*/ m_VPBuiltinCurrent.Lighting);
}
bool CDriverGL3::setupBuiltinPrograms(CMaterial &mat)
bool CDriverGL3::setupBuiltinPrograms()
{
return setupBuiltinVertexProgram()
&& setupBuiltinPixelProgram(mat)
&& setupBuiltinPixelProgram()
&& setupUniforms();
}
@ -657,10 +657,12 @@ bool CDriverGL3::setupBuiltinVertexProgram()
return true;
}
bool CDriverGL3::setupBuiltinPixelProgram(CMaterial &mat)
bool CDriverGL3::setupBuiltinPixelProgram()
{
if (m_UserPixelProgram) return true;
nlassert(_CurrentMaterial);
CMaterial &mat = *_CurrentMaterial;
CMaterialDrvInfosGL3 *matDrv = static_cast<CMaterialDrvInfosGL3 *>((IMaterialDrvInfos *)(mat._MatDrvInfo));
nlassert(matDrv);
@ -680,219 +682,6 @@ bool CDriverGL3::setupBuiltinPixelProgram(CMaterial &mat)
// GL3 TODO: Here we set the uniforms of the vertex program!
return true;
#if 0
// nlassert(!m_UserVertexProgram); // TEMP
// nlassert(!m_UserPixelProgram); // TEMP
if (mat.getDynMat() != NULL)
return true;
// CVertexProgram *vp = NULL; // REMOVED
CPixelProgram *pp = NULL;
SShaderPair sp;
CShaderDesc desc;
generateShaderDesc(desc, mat);
// See if we've already generated and compiled this shader
sp = shaderCache.findShader(desc);
// Yes we have!
if (!sp.empty())
{
/*if (m_UserVertexProgram == NULL)
{
if (!activeVertexProgram(sp.vp, true))
return false;
}*/
if (m_UserPixelProgram == NULL)
{
if (!activePixelProgram(sp.pp, true))
return false;
}
}
// No we need to generate it now
else
{
// std::string vs;
std::string ps;
bool cacheShaders = true;
shaderGenerator->reset();
shaderGenerator->setMaterial(&mat);
shaderGenerator->setShaderDesc(&desc);
// If we don't already have a vertex program attached, we'll generate it now
/* if (m_UserVertexProgram == NULL)
{
shaderGenerator->generateVS(vs);
vp = new CVertexProgram();
{
IProgram::CSource *src = new IProgram::CSource();
src->Profile = IProgram::glsl330v;
src->DisplayName = "";
src->setSource(vs);
vp->addSource(src);
}
if (!compileVertexProgram(vp))
{
delete vp;
vp = NULL;
return false;
}
if (!activeVertexProgram(vp, true))
{
delete vp;
vp = NULL;
return false;
}
}
else
cacheShaders = false;
*/
// If we don't already have a pixel program attached, we'll generate it now
if (m_UserPixelProgram == NULL)
{
shaderGenerator->generatePS(ps);
pp = new CPixelProgram();
{
IProgram::CSource *src = new IProgram::CSource();
src->Profile = IProgram::glsl330f;
src->DisplayName = "";
src->setSource(ps);
pp->addSource(src);
}
if (!compilePixelProgram(pp))
{
// delete vp;
// vp = NULL;
delete pp;
pp = NULL;
return false;
}
if (!activePixelProgram(pp, true))
{
// delete vp;
// vp = NULL;
delete pp;
pp = NULL;
return false;
}
}
else
cacheShaders = false;
// If we already have a shader attached we won't cache this shaderpair, since we didn't generate it
if (cacheShaders)
{
sp.vp = NULL;
sp.pp = pp;
desc.setShaders(sp);
shaderCache.cacheShader(desc);
}
}
return true;
#endif
}
bool CDriverGL3::setupDynMatProgram(CMaterial& mat, uint pass)
{
/*
if ((currentProgram.vp != NULL) && (currentProgram.pp != NULL))
return true;
CDynMaterial *m = mat.getDynMat();
const SRenderPass *rp = m->getPass(pass);
std::string shaderRef;
rp->getShaderRef(shaderRef);
NL3D::CUsrShaderProgram prg;
if (!usrShaderManager->getShader(shaderRef, &prg))
return false;
std::string shaderSource;
std::string log;
std::string name;
if (currentProgram.vp == NULL)
{
prg.getVP(shaderSource);
prg.getName(name);
CVertexProgram *vp = new CVertexProgram();
{
IProgram::CSource *src = new IProgram::CSource();
src->Profile = IProgram::glsl330v;
src->DisplayName = name;
src->setSource(shaderSource.c_str());
vp->addSource(src);
}
if (!compileVertexProgram(vp))
{
delete vp;
return false;
}
if (!activeVertexProgram(vp))
{
delete vp;
return false;
}
if (currentProgram.dynmatVP != NULL)
delete currentProgram.dynmatVP;
currentProgram.dynmatVP = vp;
}
if (currentProgram.pp == NULL)
{
CPixelProgram *pp = new CPixelProgram();
prg.getFP(shaderSource);
{
IProgram::CSource *src = new IProgram::CSource();
src->Profile = IProgram::glsl330f;
src->DisplayName = name;
src->setSource(shaderSource.c_str());
pp->addSource(src);
}
if (!compilePixelProgram(pp))
{
delete pp;
return false;
}
if (!activePixelProgram(pp))
{
delete pp;
return false;
}
if (currentProgram.dynmatPP != NULL)
delete currentProgram.dynmatPP;
currentProgram.dynmatPP = pp;
}
return true;
*/
return false;
}
bool CDriverGL3::setupUniforms()
@ -1056,27 +845,6 @@ void CDriverGL3::setupUniforms(TProgram program)
{
nglProgramUniform4f(progId, selfIlluminationId, selfIllumination.R, selfIllumination.G, selfIllumination.B, 0.0f);
}
// Lightmaps have special constants
if (mat.getShader() == CMaterial::Normal
|| mat.getShader() == CMaterial::UserColor)
{
for (uint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage)
{
int cl = p->getUniformIndex(CProgramIndex::TName(CProgramIndex::Constant0 + stage));
if (cl != -1)
{
CRGBA col = mat._TexEnvs[stage].ConstantColor;
GLfloat glCol[4];
glCol[0] = col.R / 255.0f;
glCol[1] = col.G / 255.0f;
glCol[2] = col.B / 255.0f;
glCol[3] = col.A / 255.0f;
nglProgramUniform4f(progId, cl, glCol[0], glCol[1], glCol[2], glCol[3]);
}
}
}
}
void CDriverGL3::setupInitialUniforms(IProgram *program)

@ -103,6 +103,7 @@ void CDriverGLStates3::forceDefaults(uint nbStages)
// FIXME GL3 TEXTUREMODE glDisable(GL_TEXTURE_RECTANGLE);
// FIXME GL3 TEXTUREMODE _TextureMode[stage]= TextureDisabled;
// FIXME GL3 TEXTUREMODE }
// etc
// ActiveTexture current texture to 0.
nglActiveTexture(GL_TEXTURE0);

@ -1377,7 +1377,7 @@ static const GLenum OperandLUT[4]= { GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SR
// This maps the CMaterial::TTexOperator, used for openGL Arg2 setup.
static const GLenum InterpolateSrcLUT[8]= { GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_TEXTURE, GL_PREVIOUS_EXT, GL_PRIMARY_COLOR_EXT, GL_CONSTANT_EXT };
/*
// ***************************************************************************
void CDriverGL3::forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv &env)
{
@ -1385,9 +1385,9 @@ void CDriverGL3::forceActivateTexEnvMode(uint stage, const CMaterial::CTexEnv
// cache mgt.
_CurrentTexEnv[stage].EnvPacked= env.EnvPacked;
// Disable Special tex env f().
_CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled;
//_CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled;
}
*//*
// ***************************************************************************
void CDriverGL3::activateTexEnvColor(uint stage, NLMISC::CRGBA col)
{
@ -1396,8 +1396,8 @@ void CDriverGL3::activateTexEnvColor(uint stage, NLMISC::CRGBA col)
{
forceActivateTexEnvColor(stage, col);
}
}
}*/
/*
// ***************************************************************************
void CDriverGL3::activateTexEnvMode(uint stage, const CMaterial::CTexEnv &env)
{
@ -1408,9 +1408,9 @@ void CDriverGL3::activateTexEnvMode(uint stage, const CMaterial::CTexEnv &env)
{
forceActivateTexEnvMode(stage, env);
}
}
}*/
/*
// ***************************************************************************
void CDriverGL3::activateTexEnvColor(uint stage, const CMaterial::CTexEnv &env)
{
@ -1420,7 +1420,7 @@ void CDriverGL3::activateTexEnvColor(uint stage, const CMaterial::CTexEnv &env
forceActivateTexEnvColor(stage, env);
}
}
*/
// ***************************************************************************
void CDriverGL3::forceDXTCCompression(bool dxtcComp)

Loading…
Cancel
Save