Added Meshes and Animations (And many more)
Added NzTexture::IsMipmappingSupported Color::(FromTo)HSV now takes hue and saturation in degrees Fixed Context::EnsureContext Fixed COW thread-safety (String, Image, Matrix4) Fixed Quatenion<T>::operator*(const Vector3<T>&) Fixed ResourceLoader Fixed String::Resize with a size of 0 Fixed Texture mipmapping crash Fixed per-class thread-safety IndexBuffer and VertexBuffer are now resources It is now possible to use more than 8 texcoords per shader Moved all enumerations into separate files (Core/Enums.hpp, Utility/Enums.hpp, ..) Removed NzContextParameters::defaultWindow VertexDeclaration has been rewritten (New interface/COW)
This commit is contained in:
@@ -290,7 +290,8 @@ bool NzContext::EnsureContext()
|
||||
|
||||
threadContext = context;
|
||||
}
|
||||
else if (!threadContext->SetActive(true))
|
||||
|
||||
if (!threadContext->SetActive(true))
|
||||
{
|
||||
NazaraError("Failed to active thread context");
|
||||
return false;
|
||||
|
||||
@@ -6,15 +6,27 @@
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
nzUInt8 NzContextParameters::defaultMajorVersion; // Initialisé par NzOpenGL
|
||||
nzUInt8 NzContextParameters::defaultMinorVersion; // Initialisé par NzOpenGL
|
||||
// Version majeure d'OpenGL, initialisé par NzOpenGL::Initialize()
|
||||
nzUInt8 NzContextParameters::defaultMajorVersion;
|
||||
|
||||
// Version majeure d'OpenGL, initialisé par NzOpenGL::Initialize()
|
||||
nzUInt8 NzContextParameters::defaultMinorVersion;
|
||||
|
||||
// Contexte de partage par défaut, initialisé par NzOpenGL::Initialize()
|
||||
const NzContext* NzContextParameters::defaultShareContext = nullptr;
|
||||
NzWindowHandle NzContextParameters::defaultWindow = 0;
|
||||
|
||||
// Si possible, garder la compatibilité avec les fonctionnalités dépréciées
|
||||
bool NzContextParameters::defaultCompatibilityProfile = false;
|
||||
|
||||
// Mode debug d'OpenGL par défaut
|
||||
#if NAZARA_RENDERER_OPENGL_DEBUG || defined(NAZARA_DEBUG)
|
||||
bool NzContextParameters::defaultDebugMode = true;
|
||||
#else
|
||||
bool NzContextParameters::defaultDebugMode = false;
|
||||
#endif
|
||||
|
||||
// Active le double-buffering sur les contextes
|
||||
bool NzContextParameters::defaultDoubleBuffered = false;
|
||||
|
||||
// Active le partage des ressources entre contextes (Via le defaultShareContext)
|
||||
bool NzContextParameters::defaultShared = true;
|
||||
|
||||
@@ -130,10 +130,11 @@ bool NzGLSLShader::Create()
|
||||
glBindAttribLocation(m_program, attribIndex[nzElementUsage_Diffuse], "Diffuse");
|
||||
glBindAttribLocation(m_program, attribIndex[nzElementUsage_Tangent], "Tangent");
|
||||
|
||||
NzString uniformName = "TexCoord*";
|
||||
for (unsigned int i = 0; i < 8; ++i)
|
||||
NzString uniform = "TexCoord";
|
||||
unsigned int maxTexCoords = NazaraRenderer->GetMaxTextureUnits();
|
||||
for (unsigned int i = 0; i < maxTexCoords; ++i)
|
||||
{
|
||||
uniformName[8] = '0'+i;
|
||||
NzString uniformName = uniform + NzString::Number(i);
|
||||
glBindAttribLocation(m_program, attribIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer());
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +298,8 @@ bool NzOpenGL::Initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fonctions optionnelles
|
||||
/****************************************Extensions****************************************/
|
||||
|
||||
glGetStringi = reinterpret_cast<PFNGLGETSTRINGIPROC>(LoadEntry("glGetStringi", false));
|
||||
glMapBufferRange = reinterpret_cast<PFNGLMAPBUFFERRANGEPROC>(LoadEntry("glMapBufferRange", false));
|
||||
|
||||
@@ -310,8 +311,6 @@ bool NzOpenGL::Initialize()
|
||||
glXSwapInterval = reinterpret_cast<PFNGLXSWAPINTERVALSGIPROC>(LoadEntry("glXSwapIntervalSGI", false));
|
||||
#endif
|
||||
|
||||
/****************************************Extensions****************************************/
|
||||
|
||||
if (!glGetStringi || !LoadExtensions3())
|
||||
{
|
||||
if (openGLversion >= 300) // Dans le cas contraire c'est normal
|
||||
@@ -353,7 +352,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to load GL_ARB_debug_output: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load GL_ARB_debug_output: " + NzString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +370,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to load ARB_gpu_shader_fp64: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load ARB_gpu_shader_fp64: " + NzString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +395,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")");
|
||||
NazaraWarning("Failed to load ARB_framebuffer_object: (" + NzString(e.what()) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,7 +451,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to load EXT_texture3D: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load EXT_texture3D: " + NzString(e.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,7 +472,7 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to load ARB_texture_storage: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load ARB_texture_storage: " + NzString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,10 +489,14 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to load ARB_vertex_array_object: " + NzString(e.what()));
|
||||
NazaraWarning("Failed to load ARB_vertex_array_object: " + NzString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
// Fonctions de substitut
|
||||
if (!glGenerateMipmap)
|
||||
glGenerateMipmap = reinterpret_cast<PFNGLGENERATEMIPMAPEXTPROC>(LoadEntry("glGenerateMipmapEXT", false));
|
||||
|
||||
/****************************************Contexte de référence****************************************/
|
||||
|
||||
///FIXME: Utiliser le contexte de chargement comme référence ? (Vérifier mode debug)
|
||||
@@ -505,6 +508,8 @@ bool NzOpenGL::Initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
NzContextParameters::defaultShareContext = NzContext::GetReference();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace
|
||||
1, // nzElementUsage_Normal
|
||||
0, // nzElementUsage_Position
|
||||
3, // nzElementUsage_Tangent
|
||||
4 // nzElementUsage_TexCoord
|
||||
|
||||
4 // nzElementUsage_TexCoord (Doit être le dernier de la liste car extensible)
|
||||
};
|
||||
|
||||
|
||||
@@ -403,7 +404,11 @@ bool NzRenderer::Initialize()
|
||||
GLint maxTextureUnits;
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
|
||||
m_maxTextureUnit = static_cast<unsigned int>(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;
|
||||
@@ -836,23 +841,23 @@ bool NzRenderer::EnsureStateUpdate()
|
||||
|
||||
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(m_vertexBuffer->GetPointer());
|
||||
|
||||
///FIXME: Améliorer les déclarations pour permettre de faire ça plus simplement
|
||||
for (int i = 0; i < 12; ++i) // Solution temporaire, à virer
|
||||
glDisableVertexAttribArray(i); // Chaque itération tue un chaton :(
|
||||
|
||||
unsigned int stride = m_vertexDeclaration->GetStride();
|
||||
unsigned int elementCount = m_vertexDeclaration->GetElementCount();
|
||||
for (unsigned int i = 0; i < elementCount; ++i)
|
||||
unsigned int stride = m_vertexDeclaration->GetStride(nzElementStream_VertexData);
|
||||
for (unsigned int i = 0; i <= nzElementUsage_Max; ++i)
|
||||
{
|
||||
const NzVertexDeclaration::Element* element = m_vertexDeclaration->GetElement(i);
|
||||
const NzVertexElement* element = m_vertexDeclaration->GetElement(nzElementStream_VertexData, static_cast<nzElementUsage>(i));
|
||||
|
||||
glEnableVertexAttribArray(attribIndex[element->usage]+element->usageIndex);
|
||||
glVertexAttribPointer(attribIndex[element->usage]+element->usageIndex,
|
||||
openglSize[element->type],
|
||||
openglType[element->type],
|
||||
(element->type == nzElementType_Color) ? GL_TRUE : GL_FALSE,
|
||||
stride,
|
||||
&buffer[element->offset]);
|
||||
if (element)
|
||||
{
|
||||
glEnableVertexAttribArray(attribIndex[i]);
|
||||
glVertexAttribPointer(attribIndex[i],
|
||||
openglSize[element->type],
|
||||
openglType[element->type],
|
||||
(element->type == nzElementType_Color) ? GL_TRUE : GL_FALSE,
|
||||
stride,
|
||||
&buffer[element->offset]);
|
||||
}
|
||||
else
|
||||
glDisableVertexAttribArray(attribIndex[i]);
|
||||
}
|
||||
|
||||
if (m_indexBuffer)
|
||||
|
||||
@@ -341,7 +341,7 @@ bool NzTexture::Bind() const
|
||||
|
||||
glBindTexture(openglTarget[m_impl->type], m_impl->id);
|
||||
|
||||
if (!m_impl->mipmapsUpdated)
|
||||
if (m_impl->mipmapping && !m_impl->mipmapsUpdated)
|
||||
{
|
||||
glGenerateMipmap(openglTarget[m_impl->type]);
|
||||
m_impl->mipmapsUpdated = true;
|
||||
@@ -433,7 +433,13 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
|
||||
NzContext::EnsureContext();
|
||||
|
||||
levelCount = std::min(levelCount, NzImage::GetMaxLevel(width, height, depth));
|
||||
if (IsMipmappingSupported())
|
||||
levelCount = std::min(levelCount, NzImage::GetMaxLevel(width, height, depth));
|
||||
else if (levelCount > 1)
|
||||
{
|
||||
NazaraWarning("Mipmapping not supported, reducing level count to 1");
|
||||
levelCount = 1;
|
||||
}
|
||||
|
||||
NzTextureImpl* impl = new NzTextureImpl;
|
||||
glGenTextures(1, &impl->id);
|
||||
@@ -477,10 +483,7 @@ bool NzTexture::Create(nzImageType type, nzPixelFormat format, unsigned int widt
|
||||
SetWrapMode(nzTextureWrap_Repeat);
|
||||
|
||||
if (m_impl->levelCount > 1U)
|
||||
{
|
||||
m_impl->mipmapping = true;
|
||||
m_impl->mipmapsUpdated = false;
|
||||
}
|
||||
EnableMipmapping(true);
|
||||
|
||||
if (!lock)
|
||||
UnlockTexture(impl);
|
||||
@@ -577,25 +580,17 @@ bool NzTexture::EnableMipmapping(bool enable)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!glGenerateMipmap)
|
||||
if (m_impl->levelCount == 1)
|
||||
return true;
|
||||
|
||||
if (!IsMipmappingSupported())
|
||||
{
|
||||
NazaraError("Mipmapping not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_impl->mipmapping && enable)
|
||||
{
|
||||
GLint tex;
|
||||
glGetIntegerv(openglTargetBinding[m_impl->type], &tex);
|
||||
|
||||
if (m_impl->id == static_cast<GLuint>(tex))
|
||||
{
|
||||
glGenerateMipmap(openglTarget[m_impl->type]);
|
||||
m_impl->mipmapsUpdated = true;
|
||||
}
|
||||
else
|
||||
m_impl->mipmapsUpdated = false;
|
||||
}
|
||||
m_impl->mipmapsUpdated = false;
|
||||
|
||||
m_impl->mipmapping = enable;
|
||||
|
||||
@@ -848,7 +843,6 @@ bool NzTexture::LoadFromImage(const NzImage& image)
|
||||
if (!IsFormatSupported(format))
|
||||
{
|
||||
nzPixelFormat newFormat = (NzPixelFormat::HasAlpha(format)) ? nzPixelFormat_BGRA8 : nzPixelFormat_BGR8;
|
||||
|
||||
NazaraWarning("Format not supported, trying to convert it to " + NzPixelFormat::ToString(newFormat) + "...");
|
||||
|
||||
if (NzPixelFormat::IsConversionSupported(format, newFormat))
|
||||
@@ -872,14 +866,13 @@ bool NzTexture::LoadFromImage(const NzImage& image)
|
||||
}
|
||||
|
||||
nzImageType type = newImage.GetType();
|
||||
nzUInt8 levelCount = newImage.GetLevelCount();
|
||||
if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), levelCount, true))
|
||||
if (!Create(type, format, newImage.GetWidth(), newImage.GetHeight(), newImage.GetDepth(), newImage.GetLevelCount(), true))
|
||||
{
|
||||
NazaraError("Failed to create texture");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (nzUInt8 level = 0; level < levelCount; ++level)
|
||||
for (nzUInt8 level = 0; level < m_impl->levelCount; ++level)
|
||||
{
|
||||
if (!Update(newImage.GetConstPixels(level), level))
|
||||
{
|
||||
@@ -942,13 +935,13 @@ bool NzTexture::SetAnisotropyLevel(unsigned int anistropyLevel)
|
||||
NazaraError("Texture must be valid");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter))
|
||||
{
|
||||
NazaraError("Anisotropic filter not supported");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
LockTexture(m_impl);
|
||||
|
||||
@@ -981,7 +974,7 @@ bool NzTexture::SetFilterMode(nzTextureFilter filter)
|
||||
switch (filter)
|
||||
{
|
||||
case nzTextureFilter_Bilinear:
|
||||
if (m_impl->levelCount > 1)
|
||||
if (m_impl->mipmapping > 1)
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
else
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
@@ -990,7 +983,7 @@ bool NzTexture::SetFilterMode(nzTextureFilter filter)
|
||||
break;
|
||||
|
||||
case nzTextureFilter_Nearest:
|
||||
if (m_impl->levelCount > 1)
|
||||
if (m_impl->mipmapping > 1)
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
else
|
||||
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
@@ -1588,6 +1581,11 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NzTexture::IsMipmappingSupported()
|
||||
{
|
||||
return glGenerateMipmap != nullptr;
|
||||
}
|
||||
|
||||
bool NzTexture::IsTypeSupported(nzImageType type)
|
||||
{
|
||||
switch (type)
|
||||
|
||||
Reference in New Issue
Block a user