GL3: Cleanup

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 9dbdcd1d4e
commit a37d7a3127

@ -20,6 +20,7 @@
#include "nel/3d/texture_mem.h" #include "nel/3d/texture_mem.h"
#include "nel/3d/texture_bump.h" #include "nel/3d/texture_bump.h"
#include "nel/3d/material.h" #include "nel/3d/material.h"
#include "driver_opengl_vertex_buffer_hard.h"
namespace NL3D { namespace NL3D {
@ -351,6 +352,10 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
if (mat.getTexture(stage)) if (mat.getTexture(stage))
}*/ }*/
// NOTE: A vertex buffer MUST be enabled before calling setupMaterial!
nlassert(_CurrentVertexBufferHard);
uint16 vertexFormat = _CurrentVertexBufferHard->VB->getVertexFormat();
// Activate the textures. // Activate the textures.
// Do not do it for Lightmap and per pixel lighting , because done in multipass in a very special fashion. // 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. // This avoid the useless multiple change of texture states per lightmapped object.
@ -359,7 +364,6 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
/* && matShader != CMaterial::Caustics */ /* && matShader != CMaterial::Caustics */
&& matShader != CMaterial::Cloud && matShader != CMaterial::Cloud
&& matShader != CMaterial::Water && matShader != CMaterial::Water
&& matShader != CMaterial::Program
) )
{ {
uint maxTex = matShader == CMaterial::Specular ? 2 : inlGetNumTextStages(); uint maxTex = matShader == CMaterial::Specular ? 2 : inlGetNumTextStages();
@ -370,8 +374,12 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// activate the texture, or disable texturing if NULL. // activate the texture, or disable texturing if NULL.
activateTexture(stage, text); activateTexture(stage, text);
// Specular has it's own env function setup by startSpecularBatch if (vertexFormat & g_VertexFlags[TexCoord0 + stage])
if (matShader != CMaterial::Specular) {
// Do not allow TexGen when vertex flags set
setTexGenModeVP(stage, TexGenDisabled);
}
else if (matShader != CMaterial::Specular) // Specular has it's own env function setup by startSpecularBatch
{ {
setTexGenFunction(stage, mat); setTexGenFunction(stage, mat);
} }
@ -384,7 +392,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
activateTexture(1, mat.getTexture(0)); activateTexture(1, mat.getTexture(0));
setTexGenModeVP(1, TexGenDisabled); setTexGenModeVP(1, TexGenDisabled);
} }
else //if (matShader != CMaterial::Specular) // TEMP BUGFIX else if (matShader != CMaterial::Specular) // TEMP BUGFIX
{// TEMP BUGFIX {// TEMP BUGFIX
for (uint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage) for (uint stage = 0; stage < IDRV_MAT_MAXTEXTURES; ++stage)
{ {
@ -395,6 +403,13 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
if (matShader == CMaterial::Specular) if (matShader == CMaterial::Specular)
{ {
setTexGenModeVP(0, TexGenDisabled); setTexGenModeVP(0, TexGenDisabled);
if (vertexFormat & g_VertexFlags[TexCoord1])
{
// nlwarning("GL3: Specular material with TexCoord1 provided in vertex buffer");
setTexGenModeVP(1, TexGenDisabled);
}
else
{
ITexture *text = mat.getTexture(1); ITexture *text = mat.getTexture(1);
if (text) if (text)
{ {
@ -404,6 +419,7 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
setTexGenModeVP(1, TexGenSphereMap); setTexGenModeVP(1, TexGenSphereMap);
} }
} }
}
// 3. Bind OpenGL States. // 3. Bind OpenGL States.
//======================= //=======================
@ -443,24 +459,17 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// Fog Part. // Fog Part.
//================= //=================
// Disable fog if dest blend is ONE // Disable fog if dest blend is ONE or restore fog state to its current value
if (blend && (pShader->DstBlend == GL_ONE)) enableFogVP((blend && (pShader->DstBlend == GL_ONE)) ? false : _FogEnabled);
{
enableFogVP(false);
}
else
{
// Restaure fog state to its current value
enableFogVP(_FogEnabled);
}
// Done.
_CurrentMaterial = &mat; _CurrentMaterial = &mat;
} }
// 4. Misc // 4. Misc
//===================================== //=====================================
// Textures user matrix // Textures user matrix
if (matShader == CMaterial::Normal || matShader == CMaterial::Program) if (matShader == CMaterial::Normal)
{ {
setupUserTextureMatrix(inlGetNumTextStages(), mat); setupUserTextureMatrix(inlGetNumTextStages(), mat);
} }
@ -471,7 +480,11 @@ bool CDriverGL3::setupMaterial(CMaterial& mat)
// 5. Set up the program // 5. Set up the program
// ===================== // =====================
switch (matShader)
{
default:
return setupBuiltinPrograms(); return setupBuiltinPrograms();
}
} }
// *************************************************************************** // ***************************************************************************
@ -913,6 +926,7 @@ void CDriverGL3::setupSpecularBegin()
H_AUTO_OGL(CDriverGL3_setupSpecularBegin) H_AUTO_OGL(CDriverGL3_setupSpecularBegin)
// setup the good matrix for stage 1. // setup the good matrix for stage 1.
// NB: Cannot set uniforms here directly, because the program does not exist yet
_UserTexMat[1] = _SpecularTexMtx; _UserTexMat[1] = _SpecularTexMtx;
} }
@ -920,7 +934,8 @@ void CDriverGL3::setupSpecularBegin()
void CDriverGL3::setupSpecularEnd() void CDriverGL3::setupSpecularEnd()
{ {
H_AUTO_OGL(CDriverGL3_setupSpecularEnd) H_AUTO_OGL(CDriverGL3_setupSpecularEnd)
// Disable Texture coord generation.
// Disable Texture coord generation // FIXME GL3: This should not be necessary...
setTexGenModeVP(1, TexGenDisabled); setTexGenModeVP(1, TexGenDisabled);
// Happiness !!! we have already enabled the stage 1 - lolwhat // Happiness !!! we have already enabled the stage 1 - lolwhat

Loading…
Cancel
Save