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

View File

@ -58,6 +58,8 @@ namespace
}
std::set<NzString> s_openGLextensionSet;
const char* s_rendererName = nullptr;
const char* s_vendorName = nullptr;
bool s_initialized = false;
bool s_openGLextensions[nzOpenGLExtension_Max+1] = {false};
unsigned int s_openGLversion = 0;
@ -114,14 +116,12 @@ NzOpenGLFunc NzOpenGL::GetEntry(const NzString& entryPoint)
NzString NzOpenGL::GetRendererName()
{
static const char* rendererName(reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
return rendererName;
return s_rendererName;
}
NzString NzOpenGL::GetVendorName()
{
static const char* vendorName(reinterpret_cast<const char*>(glGetString(GL_VENDOR)));
return vendorName;
return s_vendorName;
}
unsigned int NzOpenGL::GetVersion()
@ -156,7 +156,7 @@ bool NzOpenGL::Initialize()
Non sérieusement si vous avez une meilleure idée contactez-moi
*/
/****************************************Initialisation****************************************/
/****************************************Chargement OpenGL****************************************/
NzContext loadContext;
if (!loadContext.Create(parameters))
@ -556,7 +556,7 @@ bool NzOpenGL::Initialize()
if (!glGenerateMipmap)
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)
if (!NzContext::Initialize())
@ -567,7 +567,8 @@ bool NzOpenGL::Initialize()
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;
}
@ -737,6 +738,8 @@ void NzOpenGL::Uninitialize()
s_initialized = false;
s_openGLextensionSet.clear();
s_openGLversion = 0;
s_rendererName = nullptr;
s_vendorName = nullptr;
UnloadLibrary();
}

View File

@ -82,6 +82,8 @@ namespace
bool s_capabilities[nzRendererCap_Max+1];
bool s_stencilFuncUpdated;
bool s_stencilOpUpdated;
bool s_useSamplerObjects;
bool s_useVertexArrayObjects;
unsigned int s_maxRenderTarget;
unsigned int s_maxTextureUnit;
unsigned int s_stencilReference;
@ -453,6 +455,8 @@ bool NzRenderer::Initialize(bool initializeDebugDrawer)
s_stencilZFail = nzStencilOperation_Keep;
s_target = nullptr;
s_textureUnits.resize(s_maxTextureUnit);
s_useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects);
s_useVertexArrayObjects = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects);
s_vaoUpdated = false;
s_vertexBuffer = nullptr;
s_vertexDeclaration = nullptr;
@ -1050,9 +1054,7 @@ bool NzRenderer::EnsureStateUpdate()
NzShaderImpl* shaderImpl = s_shader->m_impl;
shaderImpl->BindTextures();
static const bool useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects);
if (useSamplerObjects)
if (s_useSamplerObjects)
{
for (unsigned int i = 0; i < s_textureUnits.size(); ++i)
{
@ -1164,12 +1166,11 @@ bool NzRenderer::EnsureStateUpdate()
}
#endif
static const bool vaoSupported = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects);
bool update;
GLuint vao;
// 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
// 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
if (update)

View File

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