Refactored mathematics module
Added AABBs Added code examples Added experimental support for texture arrays (1D/2D) Added initialisers (new way of initialising modules) Added global headers (Plus a global header generator script) Added pattern support for directory Added support for spinlocks critical section on Windows Added NzRenderWindow::SetFramerateLimit Core project now includes Mathematics files Fixed color implementation using double Fixed declaration needing renderer include Fixed MLT not clearing nextFree(File/Line) after Free Fixed move operators not being noexcept Fixed thread-safety (Now working correctly - If I'm lucky) Moved Resource to core New interface for modules New interface for the renderer Put some global functions to anonymous namespace Removed empty modules Renamed ThreadCondition to ConditionVariable Replaced redirect to cerr log option by duplicate to cout Setting mouse position relative to a window will make this window ignore the event Shaders sending methods no longer takes the uniform variable name (it's using ID instead) Using new OpenGL 4.3 header
This commit is contained in:
@@ -63,11 +63,22 @@ bool NzGLSLShader::Bind()
|
||||
|
||||
glUseProgram(m_program);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::BindTextures()
|
||||
{
|
||||
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + it->second.unit);
|
||||
if (!it->second.texture->Bind())
|
||||
NazaraWarning("Failed to bind texture");
|
||||
TextureSlot& slot = it->second;
|
||||
if (!slot.updated)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + slot.unit);
|
||||
if (!slot.texture->Bind())
|
||||
NazaraWarning("Failed to bind texture");
|
||||
|
||||
slot.updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -78,6 +89,7 @@ bool NzGLSLShader::Compile()
|
||||
NzContext::EnsureContext();
|
||||
|
||||
m_idCache.clear();
|
||||
m_textures.clear();
|
||||
|
||||
glLinkProgram(m_program);
|
||||
|
||||
@@ -86,8 +98,8 @@ bool NzGLSLShader::Compile()
|
||||
|
||||
if (success == GL_TRUE)
|
||||
{
|
||||
static NzString success("Linkage successful");
|
||||
m_log = success;
|
||||
static NzString successStr("Linkage successful");
|
||||
m_log = successStr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -131,7 +143,7 @@ bool NzGLSLShader::Create()
|
||||
glBindAttribLocation(m_program, attribIndex[nzElementUsage_Tangent], "Tangent");
|
||||
|
||||
NzString uniform = "TexCoord";
|
||||
unsigned int maxTexCoords = NazaraRenderer->GetMaxTextureUnits();
|
||||
unsigned int maxTexCoords = NzRenderer::GetMaxTextureUnits();
|
||||
for (unsigned int i = 0; i < maxTexCoords; ++i)
|
||||
{
|
||||
NzString uniformName = uniform + NzString::Number(i);
|
||||
@@ -148,6 +160,9 @@ void NzGLSLShader::Destroy()
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
|
||||
it->second.texture->RemoveResourceReference();
|
||||
|
||||
for (GLuint shader : m_shaders)
|
||||
if (shader)
|
||||
glDeleteShader(shader);
|
||||
@@ -183,7 +198,7 @@ NzString NzGLSLShader::GetSourceCode(nzShaderType type) const
|
||||
return source;
|
||||
}
|
||||
|
||||
GLint NzGLSLShader::GetUniformLocation(const NzString& name) const
|
||||
int NzGLSLShader::GetUniformLocation(const NzString& name) const
|
||||
{
|
||||
std::map<NzString, GLint>::const_iterator it = m_idCache.find(name);
|
||||
GLint id;
|
||||
@@ -232,8 +247,8 @@ bool NzGLSLShader::Load(nzShaderType type, const NzString& source)
|
||||
glAttachShader(m_program, shader);
|
||||
m_shaders[type] = shader;
|
||||
|
||||
static NzString success("Compilation successful");
|
||||
m_log = success;
|
||||
static NzString successStr("Compilation successful");
|
||||
m_log = successStr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -280,226 +295,247 @@ bool NzGLSLShader::Lock()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendBoolean(const NzString& name, bool value)
|
||||
bool NzGLSLShader::SendBoolean(int location, bool value)
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1i(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(GetUniformLocation(name), value);
|
||||
glUniform1i(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendDouble(const NzString& name, double value)
|
||||
bool NzGLSLShader::SendDouble(int location, double value)
|
||||
{
|
||||
if (glProgramUniform1d)
|
||||
glProgramUniform1d(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1d(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1d(GetUniformLocation(name), value);
|
||||
glUniform1d(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendFloat(const NzString& name, float value)
|
||||
bool NzGLSLShader::SendFloat(int location, float value)
|
||||
{
|
||||
if (glProgramUniform1f)
|
||||
glProgramUniform1f(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1f(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1f(GetUniformLocation(name), value);
|
||||
glUniform1f(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendInteger(const NzString& name, int value)
|
||||
bool NzGLSLShader::SendInteger(int location, int value)
|
||||
{
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, GetUniformLocation(name), value);
|
||||
glProgramUniform1i(m_program, location, value);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(GetUniformLocation(name), value);
|
||||
glUniform1i(location, value);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix)
|
||||
bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix)
|
||||
{
|
||||
if (glProgramUniformMatrix4dv)
|
||||
glProgramUniformMatrix4dv(m_program, GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniformMatrix4dv(GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glUniformMatrix4dv(location, 1, GL_FALSE, matrix);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendMatrix(const NzString& name, const NzMatrix4f& matrix)
|
||||
bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix)
|
||||
{
|
||||
if (glProgramUniformMatrix4fv)
|
||||
glProgramUniformMatrix4fv(m_program, GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, matrix);
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, matrix);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector2d& vector)
|
||||
bool NzGLSLShader::SendTexture(int location, const NzTexture* texture)
|
||||
{
|
||||
if (glProgramUniform2dv)
|
||||
glProgramUniform2dv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
auto it = m_textures.find(location);
|
||||
if (it != m_textures.end())
|
||||
{
|
||||
Lock();
|
||||
glUniform2dv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector2f& vector)
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2fv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform2fv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector3d& vector)
|
||||
{
|
||||
if (glProgramUniform3dv)
|
||||
glProgramUniform3dv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3dv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector3f& vector)
|
||||
{
|
||||
if (glProgramUniform3fv)
|
||||
glProgramUniform3fv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3fv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector4d& vector)
|
||||
{
|
||||
if (glProgramUniform4dv)
|
||||
glProgramUniform4dv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4dv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(const NzString& name, const NzVector4f& vector)
|
||||
{
|
||||
if (glProgramUniform4fv)
|
||||
glProgramUniform4fv(m_program, GetUniformLocation(name), 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4fv(GetUniformLocation(name), 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendTexture(const NzString& name, NzTexture* texture)
|
||||
{
|
||||
static const unsigned int maxUnits = NazaraRenderer->GetMaxTextureUnits();
|
||||
|
||||
unsigned int unitUsed = m_textures.size();
|
||||
if (unitUsed >= maxUnits)
|
||||
{
|
||||
NazaraError("Unable to use texture \"" + name + "\" for shader: all available texture units are used");
|
||||
return false;
|
||||
}
|
||||
|
||||
// À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre
|
||||
GLint location = GetUniformLocation(name);
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Parameter name \"" + name + "\" not found in shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
nzUInt8 unit;
|
||||
if (unitUsed == 0)
|
||||
// Pas d'unité utilisée, la tâche est simple
|
||||
unit = 0;
|
||||
else
|
||||
{
|
||||
auto it = m_textures.rbegin(); // Itérateur vers la fin de la map
|
||||
unit = it->second.unit;
|
||||
if (unit == maxUnits-1)
|
||||
// Slot déjà utilisé
|
||||
TextureSlot& slot = it->second;
|
||||
if (slot.texture != texture)
|
||||
{
|
||||
// Il y a une place libre, mais pas à la fin
|
||||
for (; it != m_textures.rend(); ++it)
|
||||
slot.texture->RemoveResourceReference();
|
||||
|
||||
if (texture)
|
||||
{
|
||||
if (unit - it->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre
|
||||
slot.texture = texture;
|
||||
slot.texture->AddResourceReference();
|
||||
|
||||
slot.updated = false;
|
||||
}
|
||||
else
|
||||
m_textures.erase(it); // On supprime le slot
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static const unsigned int maxUnits = NzRenderer::GetMaxTextureUnits();
|
||||
|
||||
unsigned int unitUsed = m_textures.size();
|
||||
if (unitUsed >= maxUnits)
|
||||
{
|
||||
NazaraError("Unable to use texture for shader: all available texture units are used");
|
||||
return false;
|
||||
}
|
||||
|
||||
// À partir d'ici nous savons qu'il y a au moins un identifiant de texture libre
|
||||
nzUInt8 unit;
|
||||
if (unitUsed == 0)
|
||||
// Pas d'unité utilisée, la tâche est simple
|
||||
unit = 0;
|
||||
else
|
||||
{
|
||||
auto it2 = m_textures.rbegin(); // Itérateur vers la fin de la map
|
||||
unit = it2->second.unit;
|
||||
if (unit == maxUnits-1)
|
||||
{
|
||||
// Il y a une place libre, mais pas à la fin
|
||||
for (; it2 != m_textures.rend(); ++it2)
|
||||
{
|
||||
unit--;
|
||||
break;
|
||||
if (unit - it2->second.unit > 1) // Si l'espace entre les indices est supérieur à 1, alors il y a une place libre
|
||||
{
|
||||
unit--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
// Il y a une place libre à la fin
|
||||
unit++;
|
||||
}
|
||||
|
||||
TextureSlot slot;
|
||||
slot.unit = unit;
|
||||
slot.texture = texture;
|
||||
texture->AddResourceReference();
|
||||
|
||||
m_textures[location] = slot;
|
||||
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, unit);
|
||||
else
|
||||
// Il y a une place libre à la fin
|
||||
unit++;
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(location, unit);
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
m_textures[location] = TextureSlot{unit, texture};
|
||||
return true;
|
||||
}
|
||||
|
||||
if (glProgramUniform1i)
|
||||
glProgramUniform1i(m_program, location, unit);
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector2d& vector)
|
||||
{
|
||||
if (glProgramUniform2dv)
|
||||
glProgramUniform2dv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform1i(location, unit);
|
||||
glUniform2dv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector2f& vector)
|
||||
{
|
||||
if (glProgramUniform2fv)
|
||||
glProgramUniform2fv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform2fv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector3d& vector)
|
||||
{
|
||||
if (glProgramUniform3dv)
|
||||
glProgramUniform3dv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3dv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector3f& vector)
|
||||
{
|
||||
if (glProgramUniform3fv)
|
||||
glProgramUniform3fv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform3fv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector4d& vector)
|
||||
{
|
||||
if (glProgramUniform4dv)
|
||||
glProgramUniform4dv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4dv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzGLSLShader::SendVector(int location, const NzVector4f& vector)
|
||||
{
|
||||
if (glProgramUniform4fv)
|
||||
glProgramUniform4fv(m_program, location, 1, vector);
|
||||
else
|
||||
{
|
||||
Lock();
|
||||
glUniform4fv(location, 1, vector);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,35 +20,36 @@ class NzGLSLShader : public NzShaderImpl
|
||||
~NzGLSLShader();
|
||||
|
||||
bool Bind();
|
||||
bool BindTextures();
|
||||
|
||||
bool Compile();
|
||||
bool Create();
|
||||
|
||||
bool Create();
|
||||
void Destroy();
|
||||
|
||||
NzString GetLog() const;
|
||||
nzShaderLanguage GetLanguage() const;
|
||||
NzString GetSourceCode(nzShaderType type) const;
|
||||
GLint GetUniformLocation(const NzString& name) const;
|
||||
int GetUniformLocation(const NzString& name) const;
|
||||
|
||||
bool IsLoaded(nzShaderType type) const;
|
||||
|
||||
bool Load(nzShaderType type, const NzString& source);
|
||||
bool Lock();
|
||||
|
||||
bool SendBoolean(const NzString& name, bool value);
|
||||
bool SendDouble(const NzString& name, double value);
|
||||
bool SendFloat(const NzString& name, float value);
|
||||
bool SendInteger(const NzString& name, int value);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
|
||||
bool SendVector(const NzString& name, const NzVector2d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector2f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4f& vector);
|
||||
bool SendTexture(const NzString& name, NzTexture* texture);
|
||||
bool SendBoolean(int location, bool value);
|
||||
bool SendDouble(int location, double value);
|
||||
bool SendFloat(int location, float value);
|
||||
bool SendInteger(int location, int value);
|
||||
bool SendMatrix(int location, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(int location, const NzMatrix4f& matrix);
|
||||
bool SendTexture(int location, const NzTexture* texture);
|
||||
bool SendVector(int location, const NzVector2d& vector);
|
||||
bool SendVector(int location, const NzVector2f& vector);
|
||||
bool SendVector(int location, const NzVector3d& vector);
|
||||
bool SendVector(int location, const NzVector3f& vector);
|
||||
bool SendVector(int location, const NzVector4d& vector);
|
||||
bool SendVector(int location, const NzVector4f& vector);
|
||||
|
||||
void Unbind();
|
||||
void Unlock();
|
||||
@@ -56,8 +57,9 @@ class NzGLSLShader : public NzShaderImpl
|
||||
private:
|
||||
struct TextureSlot
|
||||
{
|
||||
bool updated = false;
|
||||
nzUInt8 unit;
|
||||
NzTexture* texture;
|
||||
const NzTexture* texture;
|
||||
};
|
||||
|
||||
mutable std::map<NzString, GLint> m_idCache;
|
||||
|
||||
@@ -52,14 +52,14 @@ namespace
|
||||
|
||||
if (access == nzBufferAccess_DiscardAndWrite)
|
||||
{
|
||||
GLint bufferSize;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufferSize);
|
||||
GLint bufSize;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_SIZE, &bufSize);
|
||||
|
||||
GLint bufferUsage;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufferUsage);
|
||||
GLint bufUsage;
|
||||
glGetBufferParameteriv(bufferTargetBinding[type], GL_BUFFER_USAGE, &bufUsage);
|
||||
|
||||
// On discard le buffer
|
||||
glBufferData(bufferTargetBinding[type], bufferSize, nullptr, bufferUsage);
|
||||
glBufferData(bufferTargetBinding[type], bufSize, nullptr, bufUsage);
|
||||
}
|
||||
|
||||
void* ptr = glMapBuffer(bufferTarget[type], bufferLock[access]);
|
||||
|
||||
@@ -98,5 +98,5 @@ bool NzOcclusionQuery::IsResultAvailable() const
|
||||
|
||||
bool NzOcclusionQuery::IsSupported()
|
||||
{
|
||||
return NazaraRenderer->HasCapability(nzRendererCap_OcclusionQuery);
|
||||
return NzRenderer::HasCapability(nzRendererCap_OcclusionQuery);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
@@ -54,7 +58,7 @@ namespace
|
||||
}
|
||||
|
||||
std::set<NzString> openGLextensionSet;
|
||||
bool openGLextensions[NzOpenGL::Count] = {false};
|
||||
bool openGLextensions[NzOpenGL::Max+1] = {false};
|
||||
unsigned int openGLversion = 0;
|
||||
|
||||
bool LoadExtensionsString(const NzString& extensionString)
|
||||
@@ -129,7 +133,7 @@ bool NzOpenGL::Initialize()
|
||||
/*
|
||||
Note: Même le contexte de chargement nécessite quelques fonctions de base pour correctement s'initialiser
|
||||
Pour cette raison, deux contextes sont créés, le premier sert à récupérer les fonctions permetttant
|
||||
de créer le second avec les bons paramètres.s
|
||||
de créer le second avec les bons paramètres.
|
||||
|
||||
Non sérieusement si quelqu'un a une meilleure idée qu'il me le dise
|
||||
*/
|
||||
@@ -157,7 +161,7 @@ bool NzOpenGL::Initialize()
|
||||
// Récupération de la version d'OpenGL
|
||||
// Ce code se base sur le fait que la carte graphique renverra un contexte de compatibilité avec la plus haute version supportée
|
||||
// Ce qui semble vrai au moins chez ATI/AMD et NVidia, mais si quelqu'un à une meilleure idée ...
|
||||
glGetString = reinterpret_cast<PFNGLGETSTRINGPROC>(LoadEntry("glGetString"));
|
||||
glGetString = reinterpret_cast<PFNGLGETSTRINGPROC>(LoadEntry("glGetString", false));
|
||||
if (!glGetString)
|
||||
{
|
||||
NazaraError("Unable to load OpenGL: failed to load glGetString");
|
||||
@@ -191,10 +195,17 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
|
||||
openGLversion = major*100 + minor*10;
|
||||
if (openGLversion < 200)
|
||||
{
|
||||
NazaraError("OpenGL version is too low, please upgrade your drivers or your graphics card");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
parameters.debugMode = true; // Certaines extensions n'apparaissent qu'avec un contexte de debug (e.g. ARB_debug_output)
|
||||
parameters.majorVersion = NzContextParameters::defaultMajorVersion = openGLversion/100;
|
||||
parameters.minorVersion = NzContextParameters::defaultMinorVersion = (openGLversion%100)/10;
|
||||
parameters.majorVersion = NzContextParameters::defaultMajorVersion = major;
|
||||
parameters.minorVersion = NzContextParameters::defaultMinorVersion = minor;
|
||||
|
||||
// Destruction implicite du premier contexte
|
||||
if (!loadContext.Create(parameters))
|
||||
@@ -331,7 +342,7 @@ bool NzOpenGL::Initialize()
|
||||
loaded = false;
|
||||
|
||||
if (!loaded)
|
||||
NazaraWarning("Failed to load windows' extension string");
|
||||
NazaraWarning("Failed to load wgl extension string");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -403,7 +414,7 @@ bool NzOpenGL::Initialize()
|
||||
openGLextensions[NzOpenGL::PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object"));
|
||||
|
||||
// SeparateShaderObjects
|
||||
if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64"))
|
||||
if (openGLversion >= 400 || IsSupported("GL_ARB_separate_shader_objects"))
|
||||
{
|
||||
glProgramUniform1f = reinterpret_cast<PFNGLPROGRAMUNIFORM1FPROC>(LoadEntry("glProgramUniform1f"));
|
||||
glProgramUniform1i = reinterpret_cast<PFNGLPROGRAMUNIFORM1IPROC>(LoadEntry("glProgramUniform1i"));
|
||||
@@ -412,6 +423,7 @@ bool NzOpenGL::Initialize()
|
||||
glProgramUniform4fv = reinterpret_cast<PFNGLPROGRAMUNIFORM4FVPROC>(LoadEntry("glProgramUniform4fv"));
|
||||
glProgramUniformMatrix4fv = reinterpret_cast<PFNGLPROGRAMUNIFORMMATRIX4FVPROC>(LoadEntry("glProgramUniformMatrix4fv"));
|
||||
|
||||
// Si ARB_gpu_shader_fp64 est supporté, alors cette extension donne également accès aux fonctions utilisant des double
|
||||
if (openGLextensions[NzOpenGL::FP64])
|
||||
{
|
||||
glProgramUniform1d = reinterpret_cast<PFNGLPROGRAMUNIFORM1DPROC>(LoadEntry("glProgramUniform1d"));
|
||||
@@ -434,8 +446,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
if (openGLversion >= 120)
|
||||
NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")");
|
||||
NazaraWarning("Failed to load core texture 3D (" + NzString(e.what()) + ")");
|
||||
|
||||
if (IsSupported("GL_EXT_texture3D"))
|
||||
{
|
||||
@@ -449,13 +460,16 @@ bool NzOpenGL::Initialize()
|
||||
|
||||
openGLextensions[NzOpenGL::Texture3D] = true;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
catch (const std::exception& e2)
|
||||
{
|
||||
NazaraWarning("Failed to load EXT_texture3D: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load EXT_texture3D: " + NzString(e2.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TextureArray
|
||||
openGLextensions[NzOpenGL::TextureArray] = (openGLversion >= 300 || IsSupported("GL_EXT_texture_array"));
|
||||
|
||||
// TextureCompression_s3tc
|
||||
openGLextensions[NzOpenGL::TextureCompression_s3tc] = IsSupported("GL_EXT_texture_compression_s3tc");
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ NzRenderTarget::~NzRenderTarget() = default;
|
||||
|
||||
bool NzRenderTarget::IsActive() const
|
||||
{
|
||||
return NazaraRenderer->GetTarget() == this;
|
||||
return NzRenderer::GetTarget() == this;
|
||||
}
|
||||
|
||||
bool NzRenderTarget::SetActive(bool active)
|
||||
{
|
||||
if (active)
|
||||
return NazaraRenderer->SetTarget(this);
|
||||
else if (NazaraRenderer->GetTarget() == this)
|
||||
return NazaraRenderer->SetTarget(nullptr);
|
||||
return NzRenderer::SetTarget(this);
|
||||
else if (NzRenderer::GetTarget() == this)
|
||||
return NzRenderer::SetTarget(nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,18 +5,13 @@
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzRenderWindow::NzRenderWindow() :
|
||||
m_context(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters) :
|
||||
m_context(nullptr)
|
||||
NzRenderWindow::NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style, const NzContextParameters& parameters)
|
||||
{
|
||||
Create(mode, title, style, parameters);
|
||||
|
||||
@@ -29,8 +24,7 @@ m_context(nullptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters) :
|
||||
m_context(nullptr)
|
||||
NzRenderWindow::NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters)
|
||||
{
|
||||
Create(handle, parameters);
|
||||
|
||||
@@ -45,6 +39,8 @@ m_context(nullptr)
|
||||
|
||||
NzRenderWindow::~NzRenderWindow()
|
||||
{
|
||||
// Nécessaire si NzWindow::Destroy est appelé par son destructeur
|
||||
OnWindowDestroying();
|
||||
}
|
||||
|
||||
bool NzRenderWindow::CopyToImage(NzImage* image)
|
||||
@@ -136,6 +132,15 @@ bool NzRenderWindow::Create(NzWindowHandle handle, const NzContextParameters& pa
|
||||
|
||||
void NzRenderWindow::Display()
|
||||
{
|
||||
if (m_framerateLimit > 0)
|
||||
{
|
||||
int remainingTime = 1000/m_framerateLimit - m_clock.GetMilliseconds();
|
||||
if (remainingTime > 0)
|
||||
NzThread::Sleep(remainingTime);
|
||||
|
||||
m_clock.Restart();
|
||||
}
|
||||
|
||||
if (m_context && m_parameters.doubleBuffered)
|
||||
m_context->SwapBuffers();
|
||||
}
|
||||
@@ -218,6 +223,11 @@ bool NzRenderWindow::IsValid() const
|
||||
return m_impl != nullptr && m_context != nullptr;
|
||||
}
|
||||
|
||||
void NzRenderWindow::SetFramerateLimit(unsigned int limit)
|
||||
{
|
||||
m_framerateLimit = limit;
|
||||
}
|
||||
|
||||
bool NzRenderWindow::Activate()
|
||||
{
|
||||
if (m_context->SetActive(true))
|
||||
@@ -232,12 +242,16 @@ bool NzRenderWindow::Activate()
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderWindow::OnClose()
|
||||
void NzRenderWindow::OnWindowDestroying()
|
||||
{
|
||||
delete m_context;
|
||||
if (m_context)
|
||||
{
|
||||
delete m_context;
|
||||
m_context = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzRenderWindow::OnCreate()
|
||||
bool NzRenderWindow::OnWindowCreated()
|
||||
{
|
||||
m_parameters.doubleBuffered = true;
|
||||
m_parameters.window = GetHandle();
|
||||
@@ -258,5 +272,7 @@ bool NzRenderWindow::OnCreate()
|
||||
NazaraWarning("Failed to activate window");
|
||||
#endif
|
||||
|
||||
m_clock.Restart();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/HardwareBuffer.hpp>
|
||||
@@ -18,6 +19,7 @@
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
@@ -61,7 +63,6 @@ namespace
|
||||
GL_FILL // nzFaceFilling_Fill
|
||||
};
|
||||
|
||||
|
||||
const GLenum openglPrimitive[] =
|
||||
{
|
||||
GL_LINES, // nzPrimitiveType_LineList,
|
||||
@@ -131,28 +132,47 @@ namespace
|
||||
GL_ZERO // nzStencilOperation_Zero
|
||||
};
|
||||
|
||||
///FIXME: Solution temporaire pour plus de facilité
|
||||
enum nzMatrixCombination
|
||||
{
|
||||
nzMatrixCombination_ViewProj = nzMatrixType_Max+1,
|
||||
nzMatrixCombination_WorldView,
|
||||
nzMatrixCombination_WorldViewProj,
|
||||
|
||||
nzMatrixCombination_Max = nzMatrixCombination_WorldViewProj
|
||||
};
|
||||
|
||||
NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type)
|
||||
{
|
||||
return new NzHardwareBuffer(parent, type);
|
||||
}
|
||||
}
|
||||
|
||||
NzRenderer::NzRenderer()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (s_instance)
|
||||
throw std::runtime_error("Renderer already instanced");
|
||||
#endif
|
||||
typedef std::tuple<const NzContext*, const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*> VAO_Key;
|
||||
|
||||
s_instance = this;
|
||||
}
|
||||
constexpr unsigned int totalMatrixCount = nzMatrixCombination_Max+1;
|
||||
|
||||
NzRenderer::~NzRenderer()
|
||||
{
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
|
||||
s_instance = nullptr;
|
||||
std::map<VAO_Key, unsigned int> s_vaos;
|
||||
NzMatrix4f s_matrix[totalMatrixCount];
|
||||
int s_matrixLocation[totalMatrixCount];
|
||||
bool s_matrixUpdated[totalMatrixCount];
|
||||
nzRendererComparison s_stencilCompare;
|
||||
nzStencilOperation s_stencilFail;
|
||||
nzStencilOperation s_stencilPass;
|
||||
nzStencilOperation s_stencilZFail;
|
||||
nzUInt32 s_stencilMask;
|
||||
const NzIndexBuffer* s_indexBuffer;
|
||||
NzRenderTarget* s_target;
|
||||
NzShader* s_shader;
|
||||
const NzVertexBuffer* s_vertexBuffer;
|
||||
const NzVertexDeclaration* s_vertexDeclaration;
|
||||
bool s_vaoUpdated;
|
||||
bool s_capabilities[nzRendererCap_Max+1];
|
||||
bool s_stencilFuncUpdated;
|
||||
bool s_stencilOpUpdated;
|
||||
unsigned int s_maxAnisotropyLevel;
|
||||
unsigned int s_maxRenderTarget;
|
||||
unsigned int s_maxTextureUnit;
|
||||
unsigned int s_stencilReference;
|
||||
}
|
||||
|
||||
void NzRenderer::Clear(unsigned long flags)
|
||||
@@ -190,8 +210,10 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
||||
NazaraError("No active context");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_indexBuffer)
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_indexBuffer)
|
||||
{
|
||||
NazaraError("No index buffer");
|
||||
return;
|
||||
@@ -204,11 +226,11 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_indexBuffer->IsSequential())
|
||||
glDrawArrays(openglPrimitive[primitive], m_indexBuffer->GetStartIndex(), m_indexBuffer->GetIndexCount());
|
||||
if (s_indexBuffer->IsSequential())
|
||||
glDrawArrays(openglPrimitive[primitive], s_indexBuffer->GetStartIndex(), s_indexBuffer->GetIndexCount());
|
||||
else
|
||||
{
|
||||
nzUInt8 indexSize = m_indexBuffer->GetIndexSize();
|
||||
nzUInt8 indexSize = s_indexBuffer->GetIndexSize();
|
||||
|
||||
GLenum type;
|
||||
switch (indexSize)
|
||||
@@ -230,7 +252,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
||||
return;
|
||||
}
|
||||
|
||||
glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(m_indexBuffer->GetPointer()) + firstIndex*indexSize);
|
||||
glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(s_indexBuffer->GetPointer()) + firstIndex*indexSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,33 +304,70 @@ void NzRenderer::Enable(nzRendererParameter parameter, bool enable)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxAnisotropyLevel() const
|
||||
/*
|
||||
NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination)
|
||||
{
|
||||
return m_maxAnisotropyLevel;
|
||||
switch (combination)
|
||||
{
|
||||
case nzMatrixCombination_ViewProj:
|
||||
if (!s_matrixUpdated[nzMatrixCombination_ViewProj])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection];
|
||||
s_matrixUpdated[nzMatrixCombination_ViewProj] = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzMatrixCombination_WorldView:
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldView])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]);
|
||||
s_matrixUpdated[nzMatrixCombination_WorldView] = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzMatrixCombination_WorldViewProj:
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection];
|
||||
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return m_matrix[combination];
|
||||
}
|
||||
*/
|
||||
NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type)
|
||||
{
|
||||
return s_matrix[type];
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxRenderTargets() const
|
||||
unsigned int NzRenderer::GetMaxAnisotropyLevel()
|
||||
{
|
||||
return m_maxRenderTarget;
|
||||
return s_maxAnisotropyLevel;
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxTextureUnits() const
|
||||
unsigned int NzRenderer::GetMaxRenderTargets()
|
||||
{
|
||||
return m_maxTextureUnit;
|
||||
return s_maxRenderTarget;
|
||||
}
|
||||
|
||||
NzShader* NzRenderer::GetShader() const
|
||||
unsigned int NzRenderer::GetMaxTextureUnits()
|
||||
{
|
||||
return m_shader;
|
||||
return s_maxTextureUnit;
|
||||
}
|
||||
|
||||
NzRenderTarget* NzRenderer::GetTarget() const
|
||||
NzShader* NzRenderer::GetShader()
|
||||
{
|
||||
return m_target;
|
||||
return s_shader;
|
||||
}
|
||||
|
||||
NzRectui NzRenderer::GetViewport() const
|
||||
NzRenderTarget* NzRenderer::GetTarget()
|
||||
{
|
||||
return s_target;
|
||||
}
|
||||
|
||||
NzRectui NzRenderer::GetViewport()
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (NzContext::GetCurrent() == nullptr)
|
||||
@@ -324,103 +383,110 @@ NzRectui NzRenderer::GetViewport() const
|
||||
return NzRectui(params[0], params[1], params[2], params[3]);
|
||||
}
|
||||
|
||||
bool NzRenderer::HasCapability(nzRendererCap capability) const
|
||||
bool NzRenderer::HasCapability(nzRendererCap capability)
|
||||
{
|
||||
return m_capabilities[capability];
|
||||
return s_capabilities[capability];
|
||||
}
|
||||
|
||||
bool NzRenderer::Initialize()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (s_initialized)
|
||||
if (s_moduleReferenceCouter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzUtility::Initialize())
|
||||
{
|
||||
NazaraError("Renderer already initialized");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialisation du module Utility
|
||||
if (!NzUtility::IsInitialized())
|
||||
{
|
||||
m_utilityModule = new NzUtility;
|
||||
m_utilityModule->Initialize();
|
||||
}
|
||||
else
|
||||
m_utilityModule = nullptr;
|
||||
|
||||
if (NzOpenGL::Initialize())
|
||||
{
|
||||
NzContext::EnsureContext();
|
||||
|
||||
m_indexBuffer = nullptr;
|
||||
m_shader = nullptr;
|
||||
m_stencilCompare = nzRendererComparison_Always;
|
||||
m_stencilFail = nzStencilOperation_Keep;
|
||||
m_stencilFuncUpdated = true;
|
||||
m_stencilMask = 0xFFFFFFFF;
|
||||
m_stencilOpUpdated = true;
|
||||
m_stencilPass = nzStencilOperation_Keep;
|
||||
m_stencilReference = 0;
|
||||
m_stencilZFail = nzStencilOperation_Keep;
|
||||
m_target = nullptr;
|
||||
m_vaoUpdated = false;
|
||||
m_vertexBuffer = nullptr;
|
||||
m_vertexDeclaration = nullptr;
|
||||
|
||||
// Récupération des capacités
|
||||
m_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter);
|
||||
m_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64);
|
||||
m_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5
|
||||
m_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0
|
||||
m_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5
|
||||
m_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject);
|
||||
m_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D);
|
||||
m_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3
|
||||
m_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3
|
||||
m_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0
|
||||
|
||||
if (m_capabilities[nzRendererCap_AnisotropicFilter])
|
||||
{
|
||||
GLint maxAnisotropy;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
|
||||
|
||||
m_maxAnisotropyLevel = static_cast<unsigned int>(maxAnisotropy);
|
||||
}
|
||||
else
|
||||
m_maxAnisotropyLevel = 1;
|
||||
|
||||
if (m_capabilities[nzRendererCap_MultipleRenderTargets])
|
||||
{
|
||||
GLint maxDrawBuffers;
|
||||
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
|
||||
|
||||
m_maxRenderTarget = static_cast<unsigned int>(maxDrawBuffers);
|
||||
}
|
||||
else
|
||||
m_maxRenderTarget = 1;
|
||||
|
||||
if (m_capabilities[nzRendererCap_TextureMulti])
|
||||
{
|
||||
GLint maxTextureUnits;
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
|
||||
GLint maxVertexAttribs;
|
||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
|
||||
|
||||
// Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs)
|
||||
m_maxTextureUnit = static_cast<unsigned int>(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord]));
|
||||
}
|
||||
else
|
||||
m_maxTextureUnit = 1;
|
||||
|
||||
NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction);
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
NazaraError("Failed to initialize utility module");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialisation du module
|
||||
if (!NzOpenGL::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize OpenGL");
|
||||
return false;
|
||||
}
|
||||
|
||||
NzContext::EnsureContext();
|
||||
|
||||
for (unsigned int i = 0; i < totalMatrixCount; ++i)
|
||||
{
|
||||
s_matrix[i].MakeIdentity();
|
||||
s_matrixLocation[i] = -1;
|
||||
s_matrixUpdated[i] = false;
|
||||
}
|
||||
|
||||
s_indexBuffer = nullptr;
|
||||
s_shader = nullptr;
|
||||
s_stencilCompare = nzRendererComparison_Always;
|
||||
s_stencilFail = nzStencilOperation_Keep;
|
||||
s_stencilFuncUpdated = true;
|
||||
s_stencilMask = 0xFFFFFFFF;
|
||||
s_stencilOpUpdated = true;
|
||||
s_stencilPass = nzStencilOperation_Keep;
|
||||
s_stencilReference = 0;
|
||||
s_stencilZFail = nzStencilOperation_Keep;
|
||||
s_target = nullptr;
|
||||
s_vaoUpdated = false;
|
||||
s_vertexBuffer = nullptr;
|
||||
s_vertexDeclaration = nullptr;
|
||||
|
||||
// Récupération des capacités
|
||||
s_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter);
|
||||
s_capabilities[nzRendererCap_FP64] = NzOpenGL::IsSupported(NzOpenGL::FP64);
|
||||
s_capabilities[nzRendererCap_HardwareBuffer] = true; // Natif depuis OpenGL 1.5
|
||||
s_capabilities[nzRendererCap_MultipleRenderTargets] = true; // Natif depuis OpenGL 2.0
|
||||
s_capabilities[nzRendererCap_OcclusionQuery] = true; // Natif depuis OpenGL 1.5
|
||||
s_capabilities[nzRendererCap_PixelBufferObject] = NzOpenGL::IsSupported(NzOpenGL::PixelBufferObject);
|
||||
s_capabilities[nzRendererCap_Texture3D] = NzOpenGL::IsSupported(NzOpenGL::Texture3D);
|
||||
s_capabilities[nzRendererCap_TextureCubemap] = true; // Natif depuis OpenGL 1.3
|
||||
s_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3
|
||||
s_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0
|
||||
|
||||
if (s_capabilities[nzRendererCap_AnisotropicFilter])
|
||||
{
|
||||
GLint maxAnisotropy;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
|
||||
|
||||
s_maxAnisotropyLevel = static_cast<unsigned int>(maxAnisotropy);
|
||||
}
|
||||
else
|
||||
s_maxAnisotropyLevel = 1;
|
||||
|
||||
if (s_capabilities[nzRendererCap_MultipleRenderTargets])
|
||||
{
|
||||
GLint maxDrawBuffers;
|
||||
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
|
||||
|
||||
s_maxRenderTarget = static_cast<unsigned int>(maxDrawBuffers);
|
||||
}
|
||||
else
|
||||
s_maxRenderTarget = 1;
|
||||
|
||||
if (s_capabilities[nzRendererCap_TextureMulti])
|
||||
{
|
||||
GLint maxTextureUnits;
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
|
||||
GLint maxVertexAttribs;
|
||||
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
|
||||
|
||||
// Impossible de binder plus de texcoords que d'attributes (en sachant qu'un certain nombre est déjà pris par les autres attributs)
|
||||
s_maxTextureUnit = static_cast<unsigned int>(std::min(maxTextureUnits, maxVertexAttribs-attribIndex[nzElementUsage_TexCoord]));
|
||||
}
|
||||
else
|
||||
s_maxTextureUnit = 1;
|
||||
|
||||
NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction);
|
||||
|
||||
NazaraNotice("Initialized: Renderer module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzRenderer::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCouter != 0;
|
||||
}
|
||||
|
||||
void NzRenderer::SetBlendFunc(nzBlendFunc src, nzBlendFunc dest)
|
||||
@@ -524,22 +590,43 @@ bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (indexBuffer != m_indexBuffer)
|
||||
if (s_indexBuffer != indexBuffer)
|
||||
{
|
||||
m_indexBuffer = indexBuffer;
|
||||
m_vaoUpdated = false;
|
||||
s_indexBuffer = indexBuffer;
|
||||
s_vaoUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix)
|
||||
{
|
||||
s_matrix[type] = matrix;
|
||||
|
||||
// Cas particulier, la matrice projection doit être inversée sur l'axe Y à cause des conventions d'OpenGL
|
||||
if (type == nzMatrixType_Projection)
|
||||
s_matrix[type] *= NzMatrix4f::Scale(NzVector3f(1.f, -1.f, 1.f));
|
||||
|
||||
// Invalidation des combinaisons
|
||||
switch (type)
|
||||
{
|
||||
case nzMatrixType_View:
|
||||
case nzMatrixType_World:
|
||||
s_matrixUpdated[nzMatrixCombination_WorldView] = false;
|
||||
case nzMatrixType_Projection:
|
||||
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = false;
|
||||
s_matrixUpdated[nzMatrixCombination_ViewProj] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzRenderer::SetShader(NzShader* shader)
|
||||
{
|
||||
if (shader == m_shader)
|
||||
if (s_shader == shader)
|
||||
return true;
|
||||
|
||||
if (m_shader)
|
||||
m_shader->m_impl->Unbind();
|
||||
if (s_shader)
|
||||
s_shader->m_impl->Unbind();
|
||||
|
||||
if (shader)
|
||||
{
|
||||
@@ -547,7 +634,7 @@ bool NzRenderer::SetShader(NzShader* shader)
|
||||
if (!shader->IsCompiled())
|
||||
{
|
||||
NazaraError("Shader is not compiled");
|
||||
m_shader = nullptr;
|
||||
shader = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -556,78 +643,87 @@ bool NzRenderer::SetShader(NzShader* shader)
|
||||
if (!shader->m_impl->Bind())
|
||||
{
|
||||
NazaraError("Failed to bind shader");
|
||||
m_shader = nullptr;
|
||||
shader = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Récupération des indices des variables uniformes (-1 si la variable n'existe pas)
|
||||
s_matrixLocation[nzMatrixType_Projection] = shader->GetUniformLocation("ProjMatrix");
|
||||
s_matrixLocation[nzMatrixType_View] = shader->GetUniformLocation("ViewMatrix");
|
||||
s_matrixLocation[nzMatrixType_World] = shader->GetUniformLocation("WorldMatrix");
|
||||
|
||||
s_matrixLocation[nzMatrixCombination_ViewProj] = shader->GetUniformLocation("ViewProjMatrix");
|
||||
s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix");
|
||||
s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix");
|
||||
}
|
||||
|
||||
m_shader = shader;
|
||||
s_shader = shader;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc)
|
||||
{
|
||||
if (compareFunc != m_stencilCompare)
|
||||
if (compareFunc != s_stencilCompare)
|
||||
{
|
||||
m_stencilCompare = compareFunc;
|
||||
m_stencilFuncUpdated = false;
|
||||
s_stencilCompare = compareFunc;
|
||||
s_stencilFuncUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation)
|
||||
{
|
||||
if (failOperation != m_stencilFail)
|
||||
if (failOperation != s_stencilFail)
|
||||
{
|
||||
m_stencilFail = failOperation;
|
||||
m_stencilOpUpdated = false;
|
||||
s_stencilFail = failOperation;
|
||||
s_stencilOpUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilMask(nzUInt32 mask)
|
||||
{
|
||||
if (mask != m_stencilMask)
|
||||
if (mask != s_stencilMask)
|
||||
{
|
||||
m_stencilMask = mask;
|
||||
m_stencilFuncUpdated = false;
|
||||
s_stencilMask = mask;
|
||||
s_stencilFuncUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation)
|
||||
{
|
||||
if (passOperation != m_stencilPass)
|
||||
if (passOperation != s_stencilPass)
|
||||
{
|
||||
m_stencilPass = passOperation;
|
||||
m_stencilOpUpdated = false;
|
||||
s_stencilPass = passOperation;
|
||||
s_stencilOpUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilReferenceValue(unsigned int refValue)
|
||||
{
|
||||
if (refValue != m_stencilReference)
|
||||
if (refValue != s_stencilReference)
|
||||
{
|
||||
m_stencilReference = refValue;
|
||||
m_stencilFuncUpdated = false;
|
||||
s_stencilReference = refValue;
|
||||
s_stencilFuncUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation)
|
||||
{
|
||||
if (zfailOperation != m_stencilZFail)
|
||||
if (zfailOperation != s_stencilZFail)
|
||||
{
|
||||
m_stencilZFail = zfailOperation;
|
||||
m_stencilOpUpdated = false;
|
||||
s_stencilZFail = zfailOperation;
|
||||
s_stencilOpUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzRenderer::SetTarget(NzRenderTarget* target)
|
||||
{
|
||||
if (target == m_target)
|
||||
if (s_target == target)
|
||||
return true;
|
||||
|
||||
if (m_target && !m_target->HasContext())
|
||||
m_target->Desactivate();
|
||||
if (s_target && !target->HasContext())
|
||||
s_target->Desactivate();
|
||||
|
||||
if (target)
|
||||
{
|
||||
@@ -640,17 +736,17 @@ bool NzRenderer::SetTarget(NzRenderTarget* target)
|
||||
#endif
|
||||
|
||||
if (target->Activate())
|
||||
m_target = target;
|
||||
s_target = target;
|
||||
else
|
||||
{
|
||||
NazaraError("Failed to activate target");
|
||||
m_target = nullptr;
|
||||
s_target = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_target = nullptr;
|
||||
s_target = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -665,10 +761,10 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_vertexBuffer != vertexBuffer)
|
||||
if (s_vertexBuffer != vertexBuffer)
|
||||
{
|
||||
m_vertexBuffer = vertexBuffer;
|
||||
m_vaoUpdated = false;
|
||||
s_vertexBuffer = vertexBuffer;
|
||||
s_vaoUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -676,10 +772,10 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer)
|
||||
|
||||
bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration)
|
||||
{
|
||||
if (m_vertexDeclaration != vertexDeclaration)
|
||||
if (s_vertexDeclaration != vertexDeclaration)
|
||||
{
|
||||
m_vertexDeclaration = vertexDeclaration;
|
||||
m_vaoUpdated = false;
|
||||
s_vertexDeclaration = vertexDeclaration;
|
||||
s_vaoUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -695,16 +791,16 @@ void NzRenderer::SetViewport(const NzRectui& viewport)
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int height = m_target->GetHeight();
|
||||
unsigned int height = s_target->GetHeight();
|
||||
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_target)
|
||||
if (!s_target)
|
||||
{
|
||||
NazaraError("Renderer has no target");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int width = m_target->GetWidth();
|
||||
unsigned int width = s_target->GetWidth();
|
||||
if (viewport.x+viewport.width > width || viewport.y+viewport.height > height)
|
||||
{
|
||||
NazaraError("Rectangle dimensions are out of bounds");
|
||||
@@ -718,20 +814,14 @@ void NzRenderer::SetViewport(const NzRectui& viewport)
|
||||
|
||||
void NzRenderer::Uninitialize()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("Renderer not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (--s_moduleReferenceCouter != 0)
|
||||
return; // Encore utilisé
|
||||
|
||||
// Libération du module
|
||||
NzContext::EnsureContext();
|
||||
|
||||
s_initialized = false;
|
||||
|
||||
// Libération des VAOs
|
||||
for (auto it = m_vaos.begin(); it != m_vaos.end(); ++it)
|
||||
for (auto it = s_vaos.begin(); it != s_vaos.end(); ++it)
|
||||
{
|
||||
GLuint vao = static_cast<GLuint>(it->second);
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
@@ -739,26 +829,10 @@ void NzRenderer::Uninitialize()
|
||||
|
||||
NzOpenGL::Uninitialize();
|
||||
|
||||
if (m_utilityModule)
|
||||
{
|
||||
delete m_utilityModule;
|
||||
m_utilityModule = nullptr;
|
||||
}
|
||||
}
|
||||
NazaraNotice("Uninitialized: Renderer module");
|
||||
|
||||
NzRenderer* NzRenderer::Instance()
|
||||
{
|
||||
#if defined(NAZARA_DEBUG)
|
||||
if (!s_instance)
|
||||
NazaraError("Renderer not instanced");
|
||||
#endif
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
bool NzRenderer::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
// Libération des dépendances
|
||||
NzUtility::Uninitialize();
|
||||
}
|
||||
|
||||
bool NzRenderer::EnsureStateUpdate()
|
||||
@@ -771,28 +845,76 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_stencilFuncUpdated)
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_shader)
|
||||
{
|
||||
glStencilFunc(rendererComparison[m_stencilCompare], m_stencilReference, m_stencilMask);
|
||||
m_stencilFuncUpdated = true;
|
||||
NazaraError("No shader");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Il est plus rapide d'opérer sur l'implémentation du shader directement
|
||||
NzShaderImpl* shaderImpl = s_shader->m_impl;
|
||||
|
||||
if (!shaderImpl->BindTextures())
|
||||
NazaraWarning("Failed to bind textures");
|
||||
|
||||
for (unsigned int i = 0; i <= nzMatrixType_Max; ++i)
|
||||
{
|
||||
if (!s_matrixUpdated[i])
|
||||
{
|
||||
shaderImpl->SendMatrix(s_matrixLocation[i], s_matrix[i]);
|
||||
s_matrixUpdated[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_stencilOpUpdated)
|
||||
// Cas spéciaux car il faut recalculer la matrice
|
||||
if (!s_matrixUpdated[nzMatrixCombination_ViewProj])
|
||||
{
|
||||
glStencilOp(stencilOperation[m_stencilFail], stencilOperation[m_stencilZFail], stencilOperation[m_stencilPass]);
|
||||
m_stencilOpUpdated = true;
|
||||
s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection];
|
||||
|
||||
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]);
|
||||
s_matrixUpdated[nzMatrixCombination_ViewProj] = true;
|
||||
}
|
||||
|
||||
if (!m_vaoUpdated)
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldView])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]);
|
||||
|
||||
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]);
|
||||
s_matrixUpdated[nzMatrixCombination_WorldView] = true;
|
||||
}
|
||||
|
||||
if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj])
|
||||
{
|
||||
s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection];
|
||||
|
||||
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]);
|
||||
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true;
|
||||
}
|
||||
|
||||
if (!s_stencilFuncUpdated)
|
||||
{
|
||||
glStencilFunc(rendererComparison[s_stencilCompare], s_stencilReference, s_stencilMask);
|
||||
s_stencilFuncUpdated = true;
|
||||
}
|
||||
|
||||
if (!s_stencilOpUpdated)
|
||||
{
|
||||
glStencilOp(stencilOperation[s_stencilFail], stencilOperation[s_stencilZFail], stencilOperation[s_stencilPass]);
|
||||
s_stencilOpUpdated = true;
|
||||
}
|
||||
|
||||
if (!s_vaoUpdated)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_vertexBuffer)
|
||||
if (!s_vertexBuffer)
|
||||
{
|
||||
NazaraError("No vertex buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_vertexDeclaration)
|
||||
if (!s_vertexDeclaration)
|
||||
{
|
||||
NazaraError("No vertex declaration");
|
||||
return false;
|
||||
@@ -809,16 +931,16 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
// 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
|
||||
|
||||
auto key = std::make_tuple(NzContext::GetCurrent(), m_indexBuffer, m_vertexBuffer, m_vertexDeclaration);
|
||||
auto it = m_vaos.find(key);
|
||||
if (it == m_vaos.end())
|
||||
auto key = std::make_tuple(NzContext::GetCurrent(), s_indexBuffer, s_vertexBuffer, s_vertexDeclaration);
|
||||
auto it = s_vaos.find(key);
|
||||
if (it == s_vaos.end())
|
||||
{
|
||||
// On créé notre VAO
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
// On l'ajoute à notre liste
|
||||
m_vaos.insert(std::make_pair(key, static_cast<unsigned int>(vao)));
|
||||
s_vaos.insert(std::make_pair(key, static_cast<unsigned int>(vao)));
|
||||
|
||||
// Et on indique qu'on veut le programmer
|
||||
update = true;
|
||||
@@ -836,15 +958,15 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
|
||||
if (update)
|
||||
{
|
||||
NzHardwareBuffer* vertexBuffer = static_cast<NzHardwareBuffer*>(m_vertexBuffer->GetBuffer()->GetImpl());
|
||||
vertexBuffer->Bind();
|
||||
NzHardwareBuffer* vertexBufferImpl = static_cast<NzHardwareBuffer*>(s_vertexBuffer->GetBuffer()->GetImpl());
|
||||
vertexBufferImpl->Bind();
|
||||
|
||||
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(m_vertexBuffer->GetPointer());
|
||||
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(s_vertexBuffer->GetPointer());
|
||||
|
||||
unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
unsigned int stride = s_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
for (unsigned int i = 0; i <= nzElementUsage_Max; ++i)
|
||||
{
|
||||
const NzVertexElement* element = m_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast<nzElementUsage>(i));
|
||||
const NzVertexElement* element = s_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast<nzElementUsage>(i));
|
||||
|
||||
if (element)
|
||||
{
|
||||
@@ -860,10 +982,10 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
glDisableVertexAttribArray(attribIndex[i]);
|
||||
}
|
||||
|
||||
if (m_indexBuffer)
|
||||
if (s_indexBuffer)
|
||||
{
|
||||
NzHardwareBuffer* indexBuffer = static_cast<NzHardwareBuffer*>(m_indexBuffer->GetBuffer()->GetImpl());
|
||||
indexBuffer->Bind();
|
||||
NzHardwareBuffer* indexBufferImpl = static_cast<NzHardwareBuffer*>(s_indexBuffer->GetBuffer()->GetImpl());
|
||||
indexBufferImpl->Bind();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -877,11 +999,10 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
glBindVertexArray(vao);
|
||||
}
|
||||
|
||||
m_vaoUpdated = true;
|
||||
s_vaoUpdated = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NzRenderer* NzRenderer::s_instance = nullptr;
|
||||
bool NzRenderer::s_initialized = false;
|
||||
unsigned int NzRenderer::s_moduleReferenceCouter = 0;
|
||||
|
||||
@@ -161,6 +161,32 @@ NzString NzShader::GetSourceCode(nzShaderType type) const
|
||||
return m_impl->GetSourceCode(type);
|
||||
}
|
||||
|
||||
int NzShader::GetUniformLocation(const NzString& name) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetUniformLocation(name);
|
||||
}
|
||||
|
||||
bool NzShader::HasUniform(const NzString& name) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetUniformLocation(name) != -1;
|
||||
}
|
||||
|
||||
bool NzShader::IsCompiled() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
@@ -282,7 +308,7 @@ bool NzShader::Lock()
|
||||
return m_impl->Lock();
|
||||
}
|
||||
|
||||
bool NzShader::SendBoolean(const NzString& name, bool value)
|
||||
bool NzShader::SendBoolean(int location, bool value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -290,57 +316,43 @@ bool NzShader::SendBoolean(const NzString& name, bool value)
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendBoolean(name, value);
|
||||
return m_impl->SendBoolean(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendDouble(const NzString& name, double value)
|
||||
bool NzShader::SendDouble(int location, double value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendDouble(name, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendFloat(const NzString& name, float value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendFloat(name, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendInteger(const NzString& name, int value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendInteger(name, value);
|
||||
return m_impl->SendDouble(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix)
|
||||
bool NzShader::SendFloat(int location, float value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -349,30 +361,61 @@ bool NzShader::SendMatrix(const NzString& name, const NzMatrix4d& matrix)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendFloat(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendInteger(int location, int value)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendInteger(location, value);
|
||||
}
|
||||
|
||||
bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendMatrix(name, matrix);
|
||||
}
|
||||
|
||||
bool NzShader::SendMatrix(const NzString& name, const NzMatrix4f& matrix)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendMatrix(name, matrix);
|
||||
return m_impl->SendMatrix(location, matrix);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector2d& vector)
|
||||
bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -381,30 +424,61 @@ bool NzShader::SendVector(const NzString& name, const NzVector2d& vector)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendMatrix(location, matrix);
|
||||
}
|
||||
|
||||
bool NzShader::SendTexture(int location, const NzTexture* texture)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendTexture(location, texture);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(int location, const NzVector2d& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector2f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector3d& vector)
|
||||
bool NzShader::SendVector(int location, const NzVector2f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -413,30 +487,42 @@ bool NzShader::SendVector(const NzString& name, const NzVector3d& vector)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(int location, const NzVector3d& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector3f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector4d& vector)
|
||||
bool NzShader::SendVector(int location, const NzVector3f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -445,17 +531,42 @@ bool NzShader::SendVector(const NzString& name, const NzVector4d& vector)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_FP64))
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(int location, const NzVector4d& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!NzRenderer::HasCapability(nzRendererCap_FP64))
|
||||
{
|
||||
NazaraError("FP64 is not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendVector(const NzString& name, const NzVector4f& vector)
|
||||
bool NzShader::SendVector(int location, const NzVector4f& vector)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
@@ -463,22 +574,15 @@ bool NzShader::SendVector(const NzString& name, const NzVector4f& vector)
|
||||
NazaraError("Shader not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendVector(name, vector);
|
||||
}
|
||||
|
||||
bool NzShader::SendTexture(const NzString& name, NzTexture* texture)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
if (location == -1)
|
||||
{
|
||||
NazaraError("Shader not created");
|
||||
NazaraError("Invalid location");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->SendTexture(name, texture);
|
||||
return m_impl->SendVector(location, vector);
|
||||
}
|
||||
|
||||
void NzShader::Unlock()
|
||||
|
||||
@@ -23,6 +23,7 @@ class NzShaderImpl
|
||||
virtual ~NzShaderImpl();
|
||||
|
||||
virtual bool Bind() = 0;
|
||||
virtual bool BindTextures() = 0;
|
||||
|
||||
virtual bool Compile() = 0;
|
||||
virtual bool Create() = 0;
|
||||
@@ -32,6 +33,7 @@ class NzShaderImpl
|
||||
virtual NzString GetLog() const = 0;
|
||||
virtual nzShaderLanguage GetLanguage() const = 0;
|
||||
virtual NzString GetSourceCode(nzShaderType type) const = 0;
|
||||
virtual int GetUniformLocation(const NzString& name) const = 0;
|
||||
|
||||
virtual bool IsLoaded(nzShaderType type) const = 0;
|
||||
|
||||
@@ -39,19 +41,19 @@ class NzShaderImpl
|
||||
|
||||
virtual bool Lock() = 0;
|
||||
|
||||
virtual bool SendBoolean(const NzString& name, bool value) = 0;
|
||||
virtual bool SendDouble(const NzString& name, double value) = 0;
|
||||
virtual bool SendFloat(const NzString& name, float value) = 0;
|
||||
virtual bool SendInteger(const NzString& name, int value) = 0;
|
||||
virtual bool SendMatrix(const NzString& name, const NzMatrix4d& matrix) = 0;
|
||||
virtual bool SendMatrix(const NzString& name, const NzMatrix4f& matrix) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector2d& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector2f& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector3d& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector3f& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector4d& vector) = 0;
|
||||
virtual bool SendVector(const NzString& name, const NzVector4f& vector) = 0;
|
||||
virtual bool SendTexture(const NzString& name, NzTexture* texture) = 0;
|
||||
virtual bool SendBoolean(int location, bool value) = 0;
|
||||
virtual bool SendDouble(int location, double value) = 0;
|
||||
virtual bool SendFloat(int location, float value) = 0;
|
||||
virtual bool SendInteger(int location, int value) = 0;
|
||||
virtual bool SendMatrix(int location, const NzMatrix4d& matrix) = 0;
|
||||
virtual bool SendMatrix(int location, const NzMatrix4f& matrix) = 0;
|
||||
virtual bool SendTexture(int location, const NzTexture* texture) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector2f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector3f& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4d& vector) = 0;
|
||||
virtual bool SendVector(int location, const NzVector4f& vector) = 0;
|
||||
|
||||
virtual void Unbind() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
@@ -39,18 +39,31 @@ namespace
|
||||
|
||||
GLenum openglTarget[] =
|
||||
{
|
||||
GL_TEXTURE_1D, // nzImageType_1D
|
||||
GL_TEXTURE_2D, // nzImageType_2D
|
||||
GL_TEXTURE_3D, // nzImageType_3D
|
||||
GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap
|
||||
GL_TEXTURE_1D, // nzImageType_1D
|
||||
GL_TEXTURE_1D_ARRAY, // nzImageType_1D_Array
|
||||
GL_TEXTURE_2D, // nzImageType_2D
|
||||
GL_TEXTURE_2D_ARRAY, // nzImageType_2D_Array
|
||||
GL_TEXTURE_3D, // nzImageType_3D
|
||||
GL_TEXTURE_CUBE_MAP // nzImageType_Cubemap
|
||||
};
|
||||
|
||||
GLenum openglTargetBinding[] =
|
||||
{
|
||||
GL_TEXTURE_BINDING_1D, // nzImageType_1D
|
||||
GL_TEXTURE_BINDING_2D, // nzImageType_2D
|
||||
GL_TEXTURE_BINDING_3D, // nzImageType_3D
|
||||
GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap
|
||||
GL_TEXTURE_BINDING_1D, // nzImageType_1D
|
||||
GL_TEXTURE_BINDING_1D_ARRAY, // nzImageType_1D
|
||||
GL_TEXTURE_BINDING_2D, // nzImageType_2D
|
||||
GL_TEXTURE_BINDING_3D, // nzImageType_3D
|
||||
GL_TEXTURE_BINDING_CUBE_MAP // nzImageType_Cubemap
|
||||
};
|
||||
|
||||
GLenum openglTargetProxy[] =
|
||||
{
|
||||
GL_PROXY_TEXTURE_1D, // nzImageType_1D
|
||||
GL_PROXY_TEXTURE_1D_ARRAY, // nzImageType_1D_Array
|
||||
GL_PROXY_TEXTURE_2D, // nzImageType_2D
|
||||
GL_PROXY_TEXTURE_2D_ARRAY, // nzImageType_2D_Array
|
||||
GL_PROXY_TEXTURE_3D, // nzImageType_3D
|
||||
GL_PROXY_TEXTURE_CUBE_MAP // nzImageType_Cubemap
|
||||
};
|
||||
|
||||
struct OpenGLFormat
|
||||
@@ -142,16 +155,16 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
GLenum target;
|
||||
GLenum target = (proxy) ? openglTargetProxy[impl->type] : openglTarget[impl->type];
|
||||
GLint previous;
|
||||
glGetIntegerv(openglTargetBinding[impl->type], &previous);
|
||||
switch (impl->type)
|
||||
{
|
||||
case nzImageType_1D:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_1D : GL_PROXY_TEXTURE_1D;
|
||||
|
||||
/*if (glTexStorage1D)
|
||||
if (glTexStorage1D)
|
||||
glTexStorage1D(target, impl->levelCount, openGLFormat.internalFormat, impl->width);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int w = impl->width;
|
||||
for (nzUInt8 level = 0; level < impl->levelCount; ++level)
|
||||
@@ -164,13 +177,12 @@ namespace
|
||||
break;
|
||||
}
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_2D : GL_PROXY_TEXTURE_2D;
|
||||
|
||||
/*if (glTexStorage2D)
|
||||
if (glTexStorage2D)
|
||||
glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int w = impl->width;
|
||||
unsigned int h = impl->height;
|
||||
@@ -187,13 +199,12 @@ namespace
|
||||
break;
|
||||
}
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_3D : GL_PROXY_TEXTURE_3D;
|
||||
|
||||
/*if (glTexStorage3D)
|
||||
if (glTexStorage3D)
|
||||
glTexStorage3D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height, impl->depth);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int w = impl->width;
|
||||
unsigned int h = impl->height;
|
||||
@@ -216,11 +227,9 @@ namespace
|
||||
|
||||
case nzImageType_Cubemap:
|
||||
{
|
||||
target = (proxy) ? GL_TEXTURE_CUBE_MAP : GL_PROXY_TEXTURE_CUBE_MAP;
|
||||
|
||||
/*if (glTexStorage2D)
|
||||
if (glTexStorage2D)
|
||||
glTexStorage2D(target, impl->levelCount, openGLFormat.internalFormat, impl->width, impl->height);
|
||||
else*/
|
||||
else
|
||||
{
|
||||
unsigned int size = impl->width; // Les cubemaps ont une longueur et largeur identique
|
||||
for (nzUInt8 level = 0; level < impl->levelCount; ++level)
|
||||
@@ -234,15 +243,11 @@ namespace
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (proxy)
|
||||
{
|
||||
GLint internalFormat;
|
||||
GLint internalFormat = 0;
|
||||
glGetTexLevelParameteriv(target, 0, GL_TEXTURE_INTERNAL_FORMAT, &internalFormat);
|
||||
if (internalFormat == 0)
|
||||
return false;
|
||||
@@ -400,6 +405,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
if (depth > 1)
|
||||
{
|
||||
@@ -408,6 +414,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
break;
|
||||
|
||||
@@ -424,10 +431,6 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -454,7 +457,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
LockTexture(impl);
|
||||
|
||||
// Vérification du support par la carte graphique
|
||||
if (!CreateTexture(impl, true))
|
||||
/*if (!CreateTexture(impl, true))
|
||||
{
|
||||
NazaraError("Texture's parameters not supported by driver");
|
||||
UnlockTexture(impl);
|
||||
@@ -462,7 +465,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
delete impl;
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Création de la texture
|
||||
if (!CreateTexture(impl, false))
|
||||
@@ -603,16 +606,13 @@ unsigned int NzTexture::GetAnisotropyLevel() const
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Texture must be valid");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
{
|
||||
NazaraError("Anisotropic filter not supported");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
return 1;
|
||||
|
||||
LockTexture(m_impl);
|
||||
|
||||
GLint anisotropyLevel;
|
||||
@@ -937,7 +937,7 @@ bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter) && anistropyLevel > 1)
|
||||
{
|
||||
NazaraError("Anisotropic filter not supported");
|
||||
return false;
|
||||
@@ -1070,9 +1070,11 @@ bool NzTexture::SetWrapMode(nzTextureWrap wrap)
|
||||
case nzImageType_3D:
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_R, wrapMode);
|
||||
case nzImageType_2D:
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_Cubemap:
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode);
|
||||
case nzImageType_1D:
|
||||
case nzImageType_1D_Array:
|
||||
glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode);
|
||||
break;
|
||||
|
||||
@@ -1180,7 +1182,7 @@ bool NzTexture::Update(const nzUInt8* pixels, nzUInt8 level)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_impl->type == nzImageType_3D)
|
||||
if (m_impl->type == nzImageType_3D || m_impl->type == nzImageType_2D_Array)
|
||||
return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), level);
|
||||
else
|
||||
return Update(pixels, NzRectui(0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U)), 0, level);
|
||||
@@ -1268,16 +1270,19 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int
|
||||
glTexSubImage1D(GL_TEXTURE_1D, level, rect.x, rect.width, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
glTexSubImage2D(GL_TEXTURE_2D, level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
glTexSubImage2D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
glTexSubImage3D(GL_TEXTURE_3D, level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
glTexSubImage3D(openglTarget[m_impl->type], level, rect.x, height-rect.height-rect.y, z, rect.width, rect.height, 1, format.dataFormat, format.dataType, mirrored.GetConstPixels());
|
||||
break;
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled (0x" + NzString::Number(m_impl->type, 16) + ')');
|
||||
case nzImageType_Cubemap:
|
||||
NazaraError("Update used on a cubemap texture, please enable safe mode");
|
||||
break;
|
||||
}
|
||||
UnlockTexture(m_impl);
|
||||
|
||||
@@ -1363,16 +1368,19 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 leve
|
||||
glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, mirrored);
|
||||
break;
|
||||
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D:
|
||||
glTexSubImage2D(GL_TEXTURE_2D, level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored);
|
||||
glTexSubImage2D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, mirrored);
|
||||
break;
|
||||
|
||||
case nzImageType_2D_Array:
|
||||
case nzImageType_3D:
|
||||
glTexSubImage3D(GL_TEXTURE_3D, level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored);
|
||||
glTexSubImage3D(openglTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, mirrored);
|
||||
break;
|
||||
|
||||
default:
|
||||
NazaraInternalError("Image type not handled (0x" + NzString::Number(m_impl->type, 16) + ')');
|
||||
case nzImageType_Cubemap:
|
||||
NazaraError("Update used on a cubemap texture, please enable safe mode");
|
||||
break;
|
||||
}
|
||||
UnlockTexture(m_impl);
|
||||
|
||||
@@ -1531,7 +1539,7 @@ void NzTexture::Unlock()
|
||||
|
||||
unsigned int NzTexture::GetValidSize(unsigned int size)
|
||||
{
|
||||
if (NazaraRenderer->HasCapability(nzRendererCap_TextureNPOT))
|
||||
if (NzRenderer::HasCapability(nzRendererCap_TextureNPOT))
|
||||
return size;
|
||||
else
|
||||
{
|
||||
@@ -1596,9 +1604,16 @@ bool NzTexture::IsTypeSupported(nzImageType type)
|
||||
case nzImageType_Cubemap:
|
||||
return true; // Tous supportés nativement dans OpenGL 2
|
||||
|
||||
default:
|
||||
return false;
|
||||
case nzImageType_1D_Array:
|
||||
case nzImageType_2D_Array:
|
||||
{
|
||||
static bool supported = NzOpenGL::IsSupported(NzOpenGL::TextureArray);
|
||||
return supported;
|
||||
}
|
||||
}
|
||||
|
||||
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
void NzTexture::SetTarget(bool isTarget)
|
||||
|
||||
Reference in New Issue
Block a user