GL3: Remove GL_MAX_LIGHTS

--HG--
branch : opengl3
hg/feature/opengl3
kaetemi 11 years ago
parent 8a60e5d4fa
commit 9c1165dcf9

@ -396,20 +396,12 @@ bool CDriverGL3::setupDisplay()
nlwarning("Missing Important GL extension: GL_EXT_texture_env_combine => All envcombine are setup to GL_MODULATE!!!"); nlwarning("Missing Important GL extension: GL_EXT_texture_env_combine => All envcombine are setup to GL_MODULATE!!!");
}*/ }*/
// Get num of light for this driver
int numLight;
glGetIntegerv (GL_MAX_LIGHTS, &numLight);
_MaxDriverLight=(uint)numLight;
if (_MaxDriverLight>MaxLight)
_MaxDriverLight=MaxLight;
// All User Light are disabled by Default // All User Light are disabled by Default
uint i; for (uint i = 0; i < MaxLight; ++i)
for (i=0;i<MaxLight;i++) _UserLightEnable[i] = false;
_UserLightEnable[i]= false;
// init _DriverGLStates // init _DriverGLStates
_DriverGLStates.init(_MaxDriverLight); _DriverGLStates.init();
// Init OpenGL/Driver defaults. // Init OpenGL/Driver defaults.
//============================= //=============================
@ -426,24 +418,24 @@ bool CDriverGL3::setupDisplay()
_CurrViewport.init(0.f, 0.f, 1.f, 1.f); _CurrViewport.init(0.f, 0.f, 1.f, 1.f);
_CurrScissor.initFullScreen(); _CurrScissor.initFullScreen();
_CurrentGlNormalize= false; _CurrentGlNormalize = false;
_ForceNormalize= false; _ForceNormalize = false;
// Setup defaults for blend, lighting ... // Setup defaults for blend, lighting ...
_DriverGLStates.forceDefaults(inlGetNumTextStages()); _DriverGLStates.forceDefaults(inlGetNumTextStages());
// Default delta camera pos. // Default delta camera pos.
_PZBCameraPos= CVector::Null; _PZBCameraPos = CVector::Null;
// Init VertexArrayRange according to supported extenstion. // Init VertexArrayRange according to supported extenstion.
_SlowUnlockVBHard= false; _SlowUnlockVBHard = false;
_AGPVertexArrayRange= new CVertexArrayRange(this); _AGPVertexArrayRange = new CVertexArrayRange(this);
_VRAMVertexArrayRange= new CVertexArrayRange(this); _VRAMVertexArrayRange = new CVertexArrayRange(this);
// Reset VertexArrayRange. // Reset VertexArrayRange.
_CurrentVertexArrayRange= NULL; _CurrentVertexArrayRange = NULL;
_CurrentVertexBufferHard= NULL; _CurrentVertexBufferHard = NULL;
_NVCurrentVARPtr= NULL; _NVCurrentVARPtr = NULL;
_NVCurrentVARSize= 0; _NVCurrentVARSize = 0;
initVertexBufferHard(NL3D_DRV_VERTEXARRAY_AGP_INIT_SIZE, 0); initVertexBufferHard(NL3D_DRV_VERTEXARRAY_AGP_INIT_SIZE, 0);
@ -456,22 +448,24 @@ bool CDriverGL3::setupDisplay()
for (uint stage=0;stage<inlGetNumTextStages(); stage++) for (uint stage=0;stage<inlGetNumTextStages(); stage++)
{ {
// init no texture. // init no texture.
_CurrentTexture[stage]= NULL; _CurrentTexture[stage] = NULL;
_CurrentTextureInfoGL[stage]= NULL; _CurrentTextureInfoGL[stage] = NULL;
// texture are disabled in DriverGLStates.forceDefaults(). // texture are disabled in DriverGLStates.forceDefaults().
// init default env. // init default env.
CMaterial::CTexEnv env; // envmode init to default. CMaterial::CTexEnv env; // envmode init to default.
env.ConstantColor.set(255,255,255,255); env.ConstantColor.set(255,255,255,255);
// Not special TexEnv. // Not special TexEnv.
_CurrentTexEnvSpecial[stage]= TexEnvSpecialDisabled; _CurrentTexEnvSpecial[stage] = TexEnvSpecialDisabled;
// set All TexGen by default to identity matrix (prefer use the textureMatrix scheme) // set All TexGen by default to identity matrix (prefer use the textureMatrix scheme)
_DriverGLStates.activeTextureARB(stage); _DriverGLStates.activeTextureARB(stage);
} }
if (!initProgramPipeline())
nlerror("Failed to create Pipeline Object");
_PPLExponent = 1.f; _PPLExponent = 1.f;
_PPLightDiffuseColor = NLMISC::CRGBA::White; _PPLightDiffuseColor = NLMISC::CRGBA::White;
_PPLightSpecularColor = NLMISC::CRGBA::White; _PPLightSpecularColor = NLMISC::CRGBA::White;
@ -499,12 +493,6 @@ bool CDriverGL3::setupDisplay()
// Reset the vbl interval // Reset the vbl interval
setSwapVBLInterval(_Interval); setSwapVBLInterval(_Interval);
if (!initPipeline())
{
nlinfo("Failed to create Pipeline Object");
nlassert(false);
}
return true; return true;
} }

@ -305,7 +305,7 @@ class CDriverGL3 : public IDriver
public: public:
// Some constants // Some constants
enum { MaxLight=8 }; enum { MaxLight = NL_OPENGL3_MAX_LIGHT };
CDriverGL3(); CDriverGL3();
virtual ~CDriverGL3(); virtual ~CDriverGL3();
@ -900,8 +900,6 @@ private:
bool _RenderTargetFBO; bool _RenderTargetFBO;
// Num lights return by GL_MAX_LIGHTS
uint _MaxDriverLight;
// real mirror of GL state // real mirror of GL state
uint _LightMode[MaxLight]; // Light mode. uint _LightMode[MaxLight]; // Light mode.
CVector _WorldLightPos[MaxLight]; // World position of the lights. CVector _WorldLightPos[MaxLight]; // World position of the lights.
@ -1352,7 +1350,7 @@ private:
CGLSLShaderGenerator *shaderGenerator; CGLSLShaderGenerator *shaderGenerator;
CUsrShaderManager *usrShaderManager; CUsrShaderManager *usrShaderManager;
bool initPipeline(); bool initProgramPipeline();
uint32 ppoId; uint32 ppoId;
SProgram currentProgram; SProgram currentProgram;

@ -29,8 +29,8 @@ namespace NLDRIVERGL3 {
uint CDriverGL3::getMaxLight () const uint CDriverGL3::getMaxLight () const
{ {
H_AUTO_OGL(CDriverGL3_getMaxLight) H_AUTO_OGL(CDriverGL3_getMaxLight)
// return min(maxLight supported by openGL, MaxLight=8). // return MaxLight=8.
return _MaxDriverLight; return MaxLight;
} }
@ -61,42 +61,42 @@ void CDriverGL3::setLightInternal(uint8 num, const CLight& light)
{ {
H_AUTO_OGL(CDriverGL3_setLightInternal) H_AUTO_OGL(CDriverGL3_setLightInternal)
// Check light count is good // Check light count is good
// nlassert (num<_MaxDriverLight); // nlassert(num < MaxLight);
// Set the light // Set the light
if (num<_MaxDriverLight) if (num < MaxLight)
{ {
// GL light number // GL light number
GLenum lightNum=(GLenum)(GL_LIGHT0+num); GLenum lightNum = (GLenum)(GL_LIGHT0+num);
// Get light mode // Get light mode
CLight::TLightMode mode=light.getMode (); CLight::TLightMode mode = light.getMode ();
// Copy the mode // Copy the mode
_LightMode[num]=mode; _LightMode[num] = mode;
_UserLight[num] = light; _UserLight[num] = light;
// Set the position // Set the position
if ((mode==CLight::DirectionalLight)||(mode==CLight::SpotLight)) if ((mode == CLight::DirectionalLight) || (mode == CLight::SpotLight))
{ {
// Get the direction of the light // Get the direction of the light
_WorldLightDirection[num]=light.getDirection (); _WorldLightDirection[num] = light.getDirection();
} }
if (mode!=CLight::DirectionalLight) if (mode != CLight::DirectionalLight)
{ {
// Get the position of the light // Get the position of the light
_WorldLightPos[num]=light.getPosition (); _WorldLightPos[num] = light.getPosition();
} }
if (mode==CLight::SpotLight) if (mode == CLight::SpotLight)
{ {
// Get the exponent of the spot // Get the exponent of the spot
float exponent=light.getExponent (); float exponent = light.getExponent();
// Get the cutoff of the spot // Get the cutoff of the spot
float cutoff=180.f*(light.getCutoff ()/(float)NLMISC::Pi); float cutoff = 180.f * (light.getCutoff() / (float)NLMISC::Pi);
} }
@ -104,7 +104,7 @@ void CDriverGL3::setLightInternal(uint8 num, const CLight& light)
} }
// *************************************************************************** // ***************************************************************************
void CDriverGL3::enableLight (uint8 num, bool enable) void CDriverGL3::enableLight(uint8 num, bool enable)
{ {
H_AUTO_OGL(CDriverGL3_enableLight) H_AUTO_OGL(CDriverGL3_enableLight)
@ -112,12 +112,12 @@ void CDriverGL3::enableLight (uint8 num, bool enable)
enableLightInternal(num, enable); enableLightInternal(num, enable);
// because the GL setup has changed, must dirt lightmap rendering // because the GL setup has changed, must dirt lightmap rendering
_LightMapDynamicLightDirty= true; _LightMapDynamicLightDirty = true;
} }
bool CDriverGL3::isLightEnabled (uint8 num) bool CDriverGL3::isLightEnabled (uint8 num)
{ {
if (num<_MaxDriverLight) if (num < MaxLight)
return _UserLightEnable[num]; return _UserLightEnable[num];
return false; return false;
@ -129,13 +129,13 @@ void CDriverGL3::enableLightInternal(uint8 num, bool enable)
{ {
H_AUTO_OGL(CDriverGL3_enableLightInternal) H_AUTO_OGL(CDriverGL3_enableLightInternal)
// Check light count is good // Check light count is good
// nlassert (num<_MaxDriverLight); // nlassert(num < MaxLight);
// Enable glLight // Enable glLight
if (num<_MaxDriverLight) if (num < MaxLight)
{ {
_DriverGLStates.enableLight(num, enable); _DriverGLStates.enableLight(num, enable); // FIXME GL3 FIXED
_UserLightEnable[ num ] = enable; _UserLightEnable[num] = enable;
} }
} }
@ -168,7 +168,7 @@ void CDriverGL3::setupLightMapDynamicLighting(bool enable)
if (enable) if (enable)
{ {
// disable all lights but the 0th. // disable all lights but the 0th.
for (uint i=1;i<_MaxDriverLight;i++) for (uint i = 1; i < MaxLight; ++i)
enableLightInternal(i, false); enableLightInternal(i, false);
// if the dynamic light is really enabled // if the dynamic light is really enabled
@ -185,7 +185,7 @@ void CDriverGL3::setupLightMapDynamicLighting(bool enable)
} }
// ok it has been setup // ok it has been setup
_LightMapDynamicLightDirty= false; _LightMapDynamicLightDirty = false;
} }
// restore old lighting // restore old lighting
else else
@ -194,7 +194,7 @@ void CDriverGL3::setupLightMapDynamicLighting(bool enable)
setLightInternal(0, _UserLight0); setLightInternal(0, _UserLight0);
// restore all standard light enable states // restore all standard light enable states
for (uint i=0;i<_MaxDriverLight;i++) for (uint i = 0; i < MaxLight; ++i)
enableLightInternal(i, _UserLightEnable[i]); enableLightInternal(i, _UserLightEnable[i]);
} }
} }

@ -1018,7 +1018,7 @@ namespace NL3D
} }
} }
bool CDriverGL3::initPipeline() bool CDriverGL3::initProgramPipeline()
{ {
ppoId = 0; ppoId = 0;

@ -36,17 +36,14 @@ CDriverGLStates3::CDriverGLStates3()
_DepthRangeNear = 0.f; _DepthRangeNear = 0.f;
_DepthRangeFar = 1.f; _DepthRangeFar = 1.f;
_ZBias = 0.f; _ZBias = 0.f;
_MaxDriverLight= 0;
_CullMode = CCW; _CullMode = CCW;
} }
// *************************************************************************** // ***************************************************************************
void CDriverGLStates3::init(uint maxLight) void CDriverGLStates3::init()
{ {
H_AUTO_OGL(CDriverGLStates3_init) H_AUTO_OGL(CDriverGLStates3_init)
_MaxDriverLight= maxLight;
_MaxDriverLight= std::min(_MaxDriverLight, uint(MaxLight));
// By default all arrays are disabled. // By default all arrays are disabled.
_VertexArrayEnabled= false; _VertexArrayEnabled= false;
@ -263,7 +260,7 @@ void CDriverGLStates3::enableLighting(uint enable)
void CDriverGLStates3::enableLight(uint num, uint enable) void CDriverGLStates3::enableLight(uint num, uint enable)
{ {
H_AUTO_OGL(CDriverGLStates3_enableLight) H_AUTO_OGL(CDriverGLStates3_enableLight)
if (num>=_MaxDriverLight) if (num >= MaxLight)
return; return;
// If different from current setup, update. // If different from current setup, update.
@ -281,7 +278,7 @@ void CDriverGLStates3::enableLight(uint num, uint enable)
bool CDriverGLStates3::isLightEnabled(uint num) const bool CDriverGLStates3::isLightEnabled(uint num) const
{ {
H_AUTO_OGL(CDriverGLStates3_isLightEnabled) H_AUTO_OGL(CDriverGLStates3_isLightEnabled)
if (num>=_MaxDriverLight) if (num >= MaxLight)
return false; return false;
else else
return _CurLight[num]; return _CurLight[num];

@ -26,6 +26,8 @@ namespace NL3D {
namespace NLDRIVERGL3 { namespace NLDRIVERGL3 {
#endif #endif
#define NL_OPENGL3_MAX_LIGHT 8
// *************************************************************************** // ***************************************************************************
/** /**
* Class for optimizing calls to openGL states, by caching old ones. * Class for optimizing calls to openGL states, by caching old ones.
@ -74,7 +76,7 @@ public:
/// Constructor. no-op. /// Constructor. no-op.
CDriverGLStates3(); CDriverGLStates3();
// init. Do it just after setDisplay() // init. Do it just after setDisplay()
void init(uint maxLight); void init();
/// Reset all OpenGL states of interest to default, and update caching. This don't apply to light. /// Reset all OpenGL states of interest to default, and update caching. This don't apply to light.
void forceDefaults(uint nbTextureStages); void forceDefaults(uint nbTextureStages);
@ -218,11 +220,10 @@ private:
TCullMode _CullMode; TCullMode _CullMode;
private: private:
void updateDepthRange(); void updateDepthRange();
// Mirror of glEnable() and GL_LIGHT0+i // Mirror of glEnable() and GL_LIGHT0+i
enum {MaxLight=8}; enum { MaxLight = NL_OPENGL3_MAX_LIGHT };
uint _MaxDriverLight;
bool _CurLight[MaxLight]; bool _CurLight[MaxLight];
}; };

Loading…
Cancel
Save