Fixed static variable in Renderer

Could not be used because of GPU-switching technologies like NVidia
Optimus


Former-commit-id: 7602e81747a40b1aceacc6b7d728ba269a30e333
This commit is contained in:
Lynix 2012-12-24 19:06:55 +01:00
parent f2271a6f87
commit 1a5cf8cc0f
4 changed files with 26 additions and 34 deletions

View File

@ -117,24 +117,22 @@ bool NzGLSLShader::Create()
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Tangent], "Tangent"); glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_Tangent], "Tangent");
NzString uniform; NzString uniform;
static const unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits();
uniform.Reserve(10); // 8 + 2 uniform.Reserve(10); // 8 + 2
uniform = "TexCoord"; uniform = "TexCoord";
unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits();
for (unsigned int i = 0; i < maxTexCoords; ++i) for (unsigned int i = 0; i < maxTexCoords; ++i)
{ {
NzString uniformName = uniform + NzString::Number(i); NzString uniformName = uniform + NzString::Number(i);
glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer()); glBindAttribLocation(m_program, NzOpenGL::AttributeIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer());
} }
static const bool mrtSupported = NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets); if (NzRenderer::HasCapability(nzRendererCap_MultipleRenderTargets))
if (mrtSupported)
{ {
static const unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets();
uniform.Reserve(14); // 12 + 2 uniform.Reserve(14); // 12 + 2
uniform = "RenderTarget"; uniform = "RenderTarget";
unsigned int maxRenderTargets = NzRenderer::GetMaxRenderTargets();
for (unsigned int i = 0; i < maxRenderTargets; ++i) for (unsigned int i = 0; i < maxRenderTargets; ++i)
{ {
NzString uniformName = uniform + NzString::Number(i); NzString uniformName = uniform + NzString::Number(i);
@ -451,8 +449,7 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture, nzUInt8*
} }
else else
{ {
static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits(); unsigned int maxUnits = NzRenderer::GetMaxTextureUnits();
unsigned int unitUsed = m_textures.size(); unsigned int unitUsed = m_textures.size();
if (unitUsed >= maxUnits) if (unitUsed >= maxUnits)
{ {

View File

@ -58,6 +58,8 @@ namespace
} }
std::set<NzString> s_openGLextensionSet; std::set<NzString> s_openGLextensionSet;
const char* s_rendererName = nullptr;
const char* s_vendorName = nullptr;
bool s_initialized = false; bool s_initialized = false;
bool s_openGLextensions[nzOpenGLExtension_Max+1] = {false}; bool s_openGLextensions[nzOpenGLExtension_Max+1] = {false};
unsigned int s_openGLversion = 0; unsigned int s_openGLversion = 0;
@ -114,14 +116,12 @@ NzOpenGLFunc NzOpenGL::GetEntry(const NzString& entryPoint)
NzString NzOpenGL::GetRendererName() NzString NzOpenGL::GetRendererName()
{ {
static const char* rendererName(reinterpret_cast<const char*>(glGetString(GL_RENDERER))); return s_rendererName;
return rendererName;
} }
NzString NzOpenGL::GetVendorName() NzString NzOpenGL::GetVendorName()
{ {
static const char* vendorName(reinterpret_cast<const char*>(glGetString(GL_VENDOR))); return s_vendorName;
return vendorName;
} }
unsigned int NzOpenGL::GetVersion() unsigned int NzOpenGL::GetVersion()
@ -156,7 +156,7 @@ bool NzOpenGL::Initialize()
Non sérieusement si vous avez une meilleure idée contactez-moi Non sérieusement si vous avez une meilleure idée contactez-moi
*/ */
/****************************************Initialisation****************************************/ /****************************************Chargement OpenGL****************************************/
NzContext loadContext; NzContext loadContext;
if (!loadContext.Create(parameters)) if (!loadContext.Create(parameters))
@ -556,7 +556,7 @@ bool NzOpenGL::Initialize()
if (!glGenerateMipmap) if (!glGenerateMipmap)
glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPEXTPROC>(LoadEntry("glGenerateMipmapEXT", false)); glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPEXTPROC>(LoadEntry("glGenerateMipmapEXT", false));
/****************************************Contexte de référence****************************************/ /****************************************Initialisation****************************************/
///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug) ///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug)
if (!NzContext::Initialize()) if (!NzContext::Initialize())
@ -567,7 +567,8 @@ bool NzOpenGL::Initialize()
return false; return false;
} }
NzContextParameters::defaultShareContext = NzContext::GetReference(); s_rendererName = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
s_vendorName = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
return true; return true;
} }
@ -737,6 +738,8 @@ void NzOpenGL::Uninitialize()
s_initialized = false; s_initialized = false;
s_openGLextensionSet.clear(); s_openGLextensionSet.clear();
s_openGLversion = 0; s_openGLversion = 0;
s_rendererName = nullptr;
s_vendorName = nullptr;
UnloadLibrary(); UnloadLibrary();
} }

View File

@ -82,6 +82,8 @@ namespace
bool s_capabilities[nzRendererCap_Max+1]; bool s_capabilities[nzRendererCap_Max+1];
bool s_stencilFuncUpdated; bool s_stencilFuncUpdated;
bool s_stencilOpUpdated; bool s_stencilOpUpdated;
bool s_useSamplerObjects;
bool s_useVertexArrayObjects;
unsigned int s_maxRenderTarget; unsigned int s_maxRenderTarget;
unsigned int s_maxTextureUnit; unsigned int s_maxTextureUnit;
unsigned int s_stencilReference; unsigned int s_stencilReference;
@ -453,6 +455,8 @@ bool NzRenderer::Initialize(bool initializeDebugDrawer)
s_stencilZFail = nzStencilOperation_Keep; s_stencilZFail = nzStencilOperation_Keep;
s_target = nullptr; s_target = nullptr;
s_textureUnits.resize(s_maxTextureUnit); s_textureUnits.resize(s_maxTextureUnit);
s_useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects);
s_useVertexArrayObjects = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects);
s_vaoUpdated = false; s_vaoUpdated = false;
s_vertexBuffer = nullptr; s_vertexBuffer = nullptr;
s_vertexDeclaration = nullptr; s_vertexDeclaration = nullptr;
@ -1050,9 +1054,7 @@ bool NzRenderer::EnsureStateUpdate()
NzShaderImpl* shaderImpl = s_shader->m_impl; NzShaderImpl* shaderImpl = s_shader->m_impl;
shaderImpl->BindTextures(); shaderImpl->BindTextures();
static const bool useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects); if (s_useSamplerObjects)
if (useSamplerObjects)
{ {
for (unsigned int i = 0; i < s_textureUnits.size(); ++i) for (unsigned int i = 0; i < s_textureUnits.size(); ++i)
{ {
@ -1164,12 +1166,11 @@ bool NzRenderer::EnsureStateUpdate()
} }
#endif #endif
static const bool vaoSupported = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects);
bool update; bool update;
GLuint vao; GLuint vao;
// Si les VAOs sont supportés, on entoure nos appels par ceux-ci // Si les VAOs sont supportés, on entoure nos appels par ceux-ci
if (vaoSupported) if (s_useVertexArrayObjects)
{ {
// On recherche si un VAO existe déjà avec notre configuration // On recherche si un VAO existe déjà avec notre configuration
// Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration // Note: Les VAOs ne sont pas partagés entre les contextes, ces derniers font donc partie de notre configuration
@ -1232,7 +1233,7 @@ bool NzRenderer::EnsureStateUpdate()
} }
} }
if (vaoSupported) if (s_useVertexArrayObjects)
{ {
// Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction // Si nous venons de définir notre VAO, nous devons le débinder pour indiquer la fin de sa construction
if (update) if (update)

View File

@ -1254,10 +1254,7 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
case nzPixelFormat_Depth24: case nzPixelFormat_Depth24:
case nzPixelFormat_Depth32: case nzPixelFormat_Depth32:
case nzPixelFormat_Depth24Stencil8: case nzPixelFormat_Depth24Stencil8:
{ return NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_FrameBufferObject);
return supported;
}
// Formats de stencil (Non supportés pour les textures) // Formats de stencil (Non supportés pour les textures)
case nzPixelFormat_Stencil1: case nzPixelFormat_Stencil1:
@ -1275,10 +1272,7 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
case nzPixelFormat_DXT1: case nzPixelFormat_DXT1:
case nzPixelFormat_DXT3: case nzPixelFormat_DXT3:
case nzPixelFormat_DXT5: case nzPixelFormat_DXT5:
{ return NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc);
static const bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureCompression_s3tc);
return supported;
}
case nzPixelFormat_Undefined: case nzPixelFormat_Undefined:
break; break;
@ -1306,10 +1300,7 @@ bool NzTexture::IsTypeSupported(nzImageType type)
case nzImageType_1D_Array: case nzImageType_1D_Array:
case nzImageType_2D_Array: case nzImageType_2D_Array:
{ return NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray);
static bool supported = NzOpenGL::IsSupported(nzOpenGLExtension_TextureArray);
return supported;
}
} }
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')'); NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');