Big skeletal animation update

Added MeshInfos demo
Added MD5Mesh/MD5Anim loader support
Added Node class
Fixed ResourceParams not being exported
Added support for skeletal animation
(Animation/Mesh/Joint/SkeletalMesh/Skeleton)
Meshes are now only stored with VertexStruct_XYZ_Normal_UV_Tangent type
Moved Sequence declaration to Sequence.hpp

-Animation:
Renamed Create to Create[Keyframe|Skeletal]

-AxisAlignedBox:
Added Contains method
Added GetCorner method
Added GetCube method
Added Transform method

-Cube/Rect:
Added GetPosition method
Added GetSize method
(Almost) Fixed ExtendTo method
Fixed GetCenter method

-File:
Added GetDirectory static function
Added GetPath method
Renamed GetDirectoryPath method to GetDirectory

-Math module:
Fixed constructor/methods taking a non-const array
GetNormal/Normalize methods now takes an optionnal integer pointer
(returning length)
Made all classes default constructor trivial
Inverse, MakeIdentity, MakeZero, Normalize, Set methods now returns
reference to object

-Matrix4:
Modified methods to avoid copies
Removed COW (Too much overhead)
Removed Concatenate[Affine] static function

-Mesh:
Renamed Create to Create[Keyframe|Skeletal|Static]
Renamed Skin to Material

-MeshParams:
No longer takes declaration argument
Renamed loadAnimations to animated
Storage default to BufferStorage_Hardware if supported and
BufferStorage_Software otherwise

-OpenGL:
Added glGetBooleanv function
Added glIsEnabled function

-Quaternion:
Added ComputeW method
Added Conjugate method

-Renderer:
Added IsEnabled static function
Fixed GetLineWidth function not being static
Removed SetVertexDeclaration

-RenderWindow:
Made CopyTo[Image|Texture] method constant

-Resource
Fixed RemoveResourceListener crash

-ResourceLoader:
Loaders are now used in a LIFO context

-Stream:
Renamed GetLine method to ReadLine

-String:
Fixed Simplified

-Utility module
Added configuration define for strict resource parsing

-VertexBuffer
Now takes a VertexDeclaration pointer

-VertexDeclaration
No longer throw an error when getting a non-existing element


Former-commit-id: f7358c1231d6af48b799d2f24f077a001e16785b
This commit is contained in:
Lynix
2012-11-21 17:23:50 +01:00
parent 84f73f2b6a
commit 70ef422950
99 changed files with 6270 additions and 1983 deletions

View File

@@ -0,0 +1,411 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/DebugDrawer.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <Nazara/Renderer/Debug.hpp>
///TODO: Améliorer
namespace
{
static NzColor primaryColor = NzColor::Red;
static NzColor secondaryColor = NzColor::Green;
static NzShader* shader = nullptr;
static NzVertexBuffer* vertexBuffer = nullptr;
static NzVertexDeclaration* vertexDeclaration = nullptr;
static bool depthTest = true;
static bool initialized = false;
static float lineWidth = 2.f;
static float pointSize = 3.f;
static int colorLocation = -1;
}
void NzDebugDrawer::Draw(const NzAxisAlignedBox& aabb)
{
if (!aabb.IsFinite())
return;
Draw(aabb.GetCube());
}
void NzDebugDrawer::Draw(const NzCubei& cube)
{
Draw(NzCubef(cube));
}
void NzDebugDrawer::Draw(const NzCubef& cube)
{
if (!initialized)
{
NazaraError("Debug drawer is not initialized");
return;
}
NzVertexStruct_XYZ* vertex = reinterpret_cast<NzVertexStruct_XYZ*>(vertexBuffer->Map(nzBufferAccess_DiscardAndWrite, 0, 24));
if (!vertex)
{
NazaraError("Failed to map buffer");
return;
}
NzVector3f max, min;
max = cube.GetPosition() + cube.GetSize();
min = cube.GetPosition();
vertex->position.Set(min.x, min.y, min.z);
vertex++;
vertex->position.Set(max.x, min.y, min.z);
vertex++;
vertex->position.Set(min.x, min.y, min.z);
vertex++;
vertex->position.Set(min.x, max.y, min.z);
vertex++;
vertex->position.Set(min.x, min.y, min.z);
vertex++;
vertex->position.Set(min.x, min.y, max.z);
vertex++;
vertex->position.Set(max.x, max.y, max.z);
vertex++;
vertex->position.Set(min.x, max.y, max.z);
vertex++;
vertex->position.Set(max.x, max.y, max.z);
vertex++;
vertex->position.Set(max.x, min.y, max.z);
vertex++;
vertex->position.Set(max.x, max.y, max.z);
vertex++;
vertex->position.Set(max.x, max.y, min.z);
vertex++;
vertex->position.Set(min.x, min.y, max.z);
vertex++;
vertex->position.Set(max.x, min.y, max.z);
vertex++;
vertex->position.Set(min.x, min.y, max.z);
vertex++;
vertex->position.Set(min.x, max.y, max.z);
vertex++;
vertex->position.Set(min.x, max.y, min.z);
vertex++;
vertex->position.Set(max.x, max.y, min.z);
vertex++;
vertex->position.Set(min.x, max.y, min.z);
vertex++;
vertex->position.Set(min.x, max.y, max.z);
vertex++;
vertex->position.Set(max.x, min.y, min.z);
vertex++;
vertex->position.Set(max.x, max.y, min.z);
vertex++;
vertex->position.Set(max.x, min.y, min.z);
vertex++;
vertex->position.Set(max.x, min.y, max.z);
vertex++;
if (!vertexBuffer->Unmap())
NazaraWarning("Failed to unmap buffer");
NzShader* oldShader = NzRenderer::GetShader();
if (!NzRenderer::SetShader(shader))
{
NazaraError("Failed to set debug shader");
return;
}
bool depthTestActive = NzRenderer::IsEnabled(nzRendererParameter_DepthTest);
if (depthTestActive != depthTest)
NzRenderer::Enable(nzRendererParameter_DepthTest, depthTest);
NzRenderer::SetVertexBuffer(vertexBuffer);
shader->SendColor(colorLocation, primaryColor);
NzRenderer::DrawPrimitives(nzPrimitiveType_LineList, 0, 24);
if (depthTestActive != depthTest)
NzRenderer::Enable(nzRendererParameter_DepthTest, depthTestActive);
if (!NzRenderer::SetShader(oldShader))
NazaraWarning("Failed to reset shader");
}
void NzDebugDrawer::Draw(const NzCubeui& cube)
{
Draw(NzCubef(cube));
}
void NzDebugDrawer::Draw(const NzSkeleton* skeleton)
{
if (!initialized)
{
NazaraError("Debug drawer is not initialized");
return;
}
unsigned int jointCount = skeleton->GetJointCount();
if (vertexBuffer->GetVertexCount() < jointCount*2)
{
NazaraError("Debug buffer not length enougth to draw object");
return;
}
NzVertexStruct_XYZ* vertex = reinterpret_cast<NzVertexStruct_XYZ*>(vertexBuffer->Map(nzBufferAccess_DiscardAndWrite, 0, jointCount*2));
if (!vertex)
{
NazaraError("Failed to map buffer");
return;
}
unsigned int vertexCount = 0;
for (unsigned int i = 0; i < jointCount; ++i)
{
const NzNode* joint = skeleton->GetJoint(i);
const NzNode* parent = joint->GetParent();
if (parent)
{
vertex->position = joint->GetDerivedTranslation();
vertex++;
vertex->position = parent->GetDerivedTranslation();
vertex++;
vertexCount += 2;
}
}
if (!vertexBuffer->Unmap())
NazaraWarning("Failed to unmap buffer");
if (vertexCount > 0)
{
NzShader* oldShader = NzRenderer::GetShader();
if (!NzRenderer::SetShader(shader))
{
NazaraError("Failed to set debug shader");
return;
}
bool depthTestActive = NzRenderer::IsEnabled(nzRendererParameter_DepthTest);
if (depthTestActive != depthTest)
NzRenderer::Enable(nzRendererParameter_DepthTest, depthTest);
NzRenderer::SetVertexBuffer(vertexBuffer);
shader->SendColor(colorLocation, primaryColor);
NzRenderer::DrawPrimitives(nzPrimitiveType_LineList, 0, vertexCount);
float oldPointSize = NzRenderer::GetPointSize();
NzRenderer::SetPointSize(pointSize);
shader->SendColor(colorLocation, secondaryColor);
NzRenderer::DrawPrimitives(nzPrimitiveType_PointList, 0, vertexCount);
NzRenderer::SetPointSize(oldPointSize);
if (depthTestActive != depthTest)
NzRenderer::Enable(nzRendererParameter_DepthTest, depthTestActive);
if (!NzRenderer::SetShader(oldShader))
NazaraWarning("Failed to reset shader");
}
}
bool NzDebugDrawer::Initialize()
{
if (!initialized)
{
// Shader
{
const char* fragmentSource110 =
"#version 110\n"
"uniform vec3 color;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(color, 1.0);\n"
"}\n";
const char* fragmentSource140 =
"#version 140\n"
"uniform vec3 color;\n"
"out vec4 RenderTarget0;\n"
"void main()\n"
"{\n"
" RenderTarget0 = vec4(color, 1.0);\n"
"}\n";
const char* vertexSource110 =
"#version 110\n"
"attribute vec3 Position;\n"
"uniform mat4 WorldViewProjMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjMatrix * vec4(Position, 1.0);\n"
"}\n";
const char* vertexSource140 =
"#version 140\n"
"in vec3 Position;\n"
"uniform mat4 WorldViewProjMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjMatrix * vec4(Position, 1.0);\n"
"}\n";
bool useGLSL140 = (NzOpenGL::GetVersion() >= 310);
shader = new NzShader(nzShaderLanguage_GLSL);
if (!shader->Load(nzShaderType_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110))
{
NazaraError("Failed to load fragment shader");
Uninitialize();
return false;
}
if (!shader->Load(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
{
NazaraError("Failed to load vertex shader");
Uninitialize();
return false;
}
if (!shader->Compile())
{
NazaraError("Failed to compile shader");
Uninitialize();
return false;
}
colorLocation = shader->GetUniformLocation("color");
}
// VertexDeclaration
{
NzVertexElement element;
element.offset = 0;
element.type = nzElementType_Float3;
element.usage = nzElementUsage_Position;
vertexDeclaration = new NzVertexDeclaration;
if (!vertexDeclaration->Create(&element, 1))
{
NazaraError("Failed to create declaration");
Uninitialize();
return false;
}
}
// VertexBuffer (Nécessite la déclaration)
{
vertexBuffer = new NzVertexBuffer(vertexDeclaration, 256, nzBufferStorage_Hardware, nzBufferUsage_Dynamic);
if (!vertexBuffer->GetBuffer()->IsValid())
{
NazaraError("Failed to create buffer");
Uninitialize();
return false;
}
}
initialized = true;
}
return true;
}
bool NzDebugDrawer::GetDepthTest()
{
return depthTest;
}
float NzDebugDrawer::GetLineWidth()
{
return lineWidth;
}
float NzDebugDrawer::GetPointSize()
{
return pointSize;
}
NzColor NzDebugDrawer::GetPrimaryColor()
{
return primaryColor;
}
NzColor NzDebugDrawer::GetSecondaryColor()
{
return secondaryColor;
}
void NzDebugDrawer::SetDepthTest(bool shouldTest)
{
depthTest = shouldTest;
}
void NzDebugDrawer::SetLineWidth(float width)
{
lineWidth = width;
}
void NzDebugDrawer::SetPointSize(float size)
{
pointSize = size;
}
void NzDebugDrawer::SetPrimaryColor(const NzColor& color)
{
primaryColor = color;
}
void NzDebugDrawer::SetSecondaryColor(const NzColor& color)
{
secondaryColor = color;
}
void NzDebugDrawer::Uninitialize()
{
if (shader)
{
delete shader;
shader = nullptr;
}
if (vertexBuffer)
{
delete vertexBuffer;
vertexBuffer = nullptr;
}
if (vertexDeclaration)
{
delete vertexDeclaration;
vertexDeclaration = nullptr;
}
initialized = false;
}

View File

@@ -23,12 +23,6 @@ m_parent(parent)
{
}
NzGLSLShader::~NzGLSLShader()
{
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
it->second.texture->RemoveResourceListener(this);
}
bool NzGLSLShader::Bind()
{
#if NAZARA_RENDERER_SAFE
@@ -165,11 +159,13 @@ void NzGLSLShader::Destroy()
NzContext::EnsureContext();
for (auto it = m_textures.begin(); it != m_textures.end(); ++it)
it->second.texture->RemoveResourceReference();
it->second.texture->RemoveResourceListener(this);
for (GLuint shader : m_shaders)
{
if (shader)
glDeleteShader(shader);
}
if (m_program)
glDeleteProgram(m_program);
@@ -730,4 +726,6 @@ void NzGLSLShader::OnResourceReleased(const NzResource* resource, int index)
{
if (m_textures.erase(index) == 0)
NazaraInternalError("Texture " + NzString::Pointer(resource) + " not found");
resource->RemoveResourceListener(this);
}

View File

@@ -20,7 +20,7 @@ class NzGLSLShader : public NzShaderImpl, NzResourceListener
{
public:
NzGLSLShader(NzShader* parent);
~NzGLSLShader();
~NzGLSLShader() = default;
bool Bind();
bool BindTextures();

View File

@@ -253,13 +253,14 @@ namespace NzOpenGL
glDrawBuffer = reinterpret_cast<PFNGLDRAWBUFFERPROC>(LoadEntry("glDrawBuffer"));
glDrawBuffers = reinterpret_cast<PFNGLDRAWBUFFERSPROC>(LoadEntry("glDrawBuffers"));
glDrawElements = reinterpret_cast<PFNGLDRAWELEMENTSPROC>(LoadEntry("glDrawElements"));
glFlush = reinterpret_cast<PFNGLFLUSHPROC>(LoadEntry("glFlush"));
glEnable = reinterpret_cast<PFNGLENABLEPROC>(LoadEntry("glEnable"));
glEnableVertexAttribArray = reinterpret_cast<PFNGLENABLEVERTEXATTRIBARRAYPROC>(LoadEntry("glEnableVertexAttribArray"));
glEndQuery = reinterpret_cast<PFNGLENDQUERYPROC>(LoadEntry("glEndQuery"));
glFlush = reinterpret_cast<PFNGLFLUSHPROC>(LoadEntry("glFlush"));
glGenBuffers = reinterpret_cast<PFNGLGENBUFFERSPROC>(LoadEntry("glGenBuffers"));
glGenQueries = reinterpret_cast<PFNGLGENQUERIESPROC>(LoadEntry("glGenQueries"));
glGenTextures = reinterpret_cast<PFNGLGENTEXTURESPROC>(LoadEntry("glGenTextures"));
glGetBooleanv = reinterpret_cast<PFNGLGETBOOLEANVPROC>(LoadEntry("glGetBooleanv"));
glGetBufferParameteriv = reinterpret_cast<PFNGLGETBUFFERPARAMETERIVPROC>(LoadEntry("glGetBufferParameteriv"));
glGetError = reinterpret_cast<PFNGLGETERRORPROC>(LoadEntry("glGetError"));
glGetFloatv = reinterpret_cast<PFNGLGETFLOATVPROC>(LoadEntry("glGetFloatv"));
@@ -278,6 +279,7 @@ namespace NzOpenGL
glGetTexParameterfv = reinterpret_cast<PFNGLGETTEXPARAMETERFVPROC>(LoadEntry("glGetTexParameterfv"));
glGetTexParameteriv = reinterpret_cast<PFNGLGETTEXPARAMETERIVPROC>(LoadEntry("glGetTexParameteriv"));
glGetUniformLocation = reinterpret_cast<PFNGLGETUNIFORMLOCATIONPROC>(LoadEntry("glGetUniformLocation"));
glIsEnabled = reinterpret_cast<PFNGLISENABLEDPROC>(LoadEntry("glIsEnabled"));
glLineWidth = reinterpret_cast<PFNGLLINEWIDTHPROC>(LoadEntry("glLineWidth"));
glLinkProgram = reinterpret_cast<PFNGLLINKPROGRAMPROC>(LoadEntry("glLinkProgram"));
glMapBuffer = reinterpret_cast<PFNGLMAPBUFFERPROC>(LoadEntry("glMapBuffer"));
@@ -919,6 +921,8 @@ PFNGLDRAWARRAYSPROC glDrawArrays = nullptr;
PFNGLDRAWBUFFERPROC glDrawBuffer = nullptr;
PFNGLDRAWBUFFERSPROC glDrawBuffers = nullptr;
PFNGLDRAWELEMENTSPROC glDrawElements = nullptr;
PFNGLENABLEPROC glEnable = nullptr;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr;
PFNGLENDQUERYPROC glEndQuery = nullptr;
PFNGLFLUSHPROC glFlush = nullptr;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = nullptr;
@@ -927,8 +931,6 @@ PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = nullptr;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr;
PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = nullptr;
PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = nullptr;
PFNGLENABLEPROC glEnable = nullptr;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray = nullptr;
PFNGLGENERATEMIPMAPPROC glGenerateMipmap = nullptr;
PFNGLGENBUFFERSPROC glGenBuffers = nullptr;
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr;
@@ -936,6 +938,7 @@ PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = nullptr;
PFNGLGENQUERIESPROC glGenQueries = nullptr;
PFNGLGENTEXTURESPROC glGenTextures = nullptr;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = nullptr;
PFNGLGETBOOLEANVPROC glGetBooleanv = nullptr;
PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv = nullptr;
PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog = nullptr;
PFNGLGETERRORPROC glGetError = nullptr;
@@ -957,6 +960,7 @@ PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv = nullptr;
PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv = nullptr;
PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv = nullptr;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = nullptr;
PFNGLISENABLEDPROC glIsEnabled = nullptr;
PFNGLLINEWIDTHPROC glLineWidth = nullptr;
PFNGLLINKPROGRAMPROC glLinkProgram = nullptr;
PFNGLMAPBUFFERPROC glMapBuffer = nullptr;

View File

@@ -725,4 +725,6 @@ void NzRenderTexture::OnResourceDestroy(const NzResource* resource, int index)
m_impl->checked = false;
m_impl->drawBuffersUpdated = false;
}
resource->RemoveResourceListener(this);
}

View File

@@ -43,7 +43,7 @@ NzRenderWindow::~NzRenderWindow()
OnWindowDestroy();
}
bool NzRenderWindow::CopyToImage(NzImage* image)
bool NzRenderWindow::CopyToImage(NzImage* image) const
{
#if NAZARA_RENDERER_SAFE
if (!m_context)
@@ -59,10 +59,14 @@ bool NzRenderWindow::CopyToImage(NzImage* image)
}
#endif
if (!m_context->SetActive(true))
NzContext* currentContext = NzContext::GetCurrent();
if (m_context != currentContext)
{
NazaraError("Failed to activate context");
return false;
if (!m_context->SetActive(true))
{
NazaraError("Failed to activate context");
return false;
}
}
NzVector2ui size = GetSize();
@@ -78,10 +82,21 @@ bool NzRenderWindow::CopyToImage(NzImage* image)
image->FlipVertically();
if (m_context != currentContext)
{
if (currentContext)
{
if (!currentContext->SetActive(true))
NazaraWarning("Failed to reset current context");
}
else
m_context->SetActive(false);
}
return true;
}
bool NzRenderWindow::CopyToTexture(NzTexture* texture)
bool NzRenderWindow::CopyToTexture(NzTexture* texture) const
{
#if NAZARA_RENDERER_SAFE
if (!m_context)
@@ -97,10 +112,14 @@ bool NzRenderWindow::CopyToTexture(NzTexture* texture)
}
#endif
if (!m_context->SetActive(true))
NzContext* currentContext = NzContext::GetCurrent();
if (m_context != currentContext)
{
NazaraError("Failed to activate context");
return false;
if (!m_context->SetActive(true))
{
NazaraError("Failed to activate context");
return false;
}
}
NzVector2ui size = GetSize();
@@ -113,6 +132,17 @@ bool NzRenderWindow::CopyToTexture(NzTexture* texture)
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size.x, size.y);
if (m_context != currentContext)
{
if (currentContext)
{
if (!currentContext->SetActive(true))
NazaraWarning("Failed to reset current context");
}
else
m_context->SetActive(false);
}
texture->Unlock();
return true;

View File

@@ -9,6 +9,7 @@
#include <Nazara/Core/Log.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/DebugDrawer.hpp>
#include <Nazara/Renderer/HardwareBuffer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/Shader.hpp>
@@ -102,6 +103,12 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
NazaraError("No active context");
return;
}
if (primitive > nzPrimitiveType_Max)
{
NazaraError("Primitive type out of enum");
return;
}
#endif
#if NAZARA_RENDERER_SAFE
@@ -156,6 +163,12 @@ void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVer
NazaraError("No active context");
return;
}
if (primitive > nzPrimitiveType_Max)
{
NazaraError("Primitive type out of enum");
return;
}
#endif
if (!EnsureStateUpdate())
@@ -175,6 +188,12 @@ void NzRenderer::Enable(nzRendererParameter parameter, bool enable)
NazaraError("No active context");
return;
}
if (parameter > nzRendererParameter_Max)
{
NazaraError("Renderer parameter out of enum");
return;
}
#endif
switch (parameter)
@@ -199,6 +218,14 @@ void NzRenderer::Enable(nzRendererParameter parameter, bool enable)
float NzRenderer::GetLineWidth()
{
#ifdef NAZARA_DEBUG
if (NzContext::GetCurrent() == nullptr)
{
NazaraError("No active context");
return 0.f;
}
#endif
float lineWidth;
glGetFloatv(GL_LINE_WIDTH, &lineWidth);
@@ -240,6 +267,14 @@ NzMatrix4f NzRenderer::GetMatrix(nzMatrixCombination combination)
*/
NzMatrix4f NzRenderer::GetMatrix(nzMatrixType type)
{
#ifdef NAZARA_DEBUG
if (type > nzMatrixType_Max)
{
NazaraError("Matrix type out of enum");
return NzMatrix4f();
}
#endif
return s_matrix[type];
}
@@ -260,6 +295,14 @@ unsigned int NzRenderer::GetMaxTextureUnits()
float NzRenderer::GetPointSize()
{
#ifdef NAZARA_DEBUG
if (NzContext::GetCurrent() == nullptr)
{
NazaraError("No active context");
return 0.f;
}
#endif
float pointSize;
glGetFloatv(GL_POINT_SIZE, &pointSize);
@@ -294,6 +337,14 @@ NzRectui NzRenderer::GetViewport()
bool NzRenderer::HasCapability(nzRendererCap capability)
{
#ifdef NAZARA_DEBUG
if (capability > nzRendererCap_Max)
{
NazaraError("Renderer capability out of enum");
return false;
}
#endif
return s_capabilities[capability];
}
@@ -393,11 +444,55 @@ bool NzRenderer::Initialize()
NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction);
#ifdef NAZARA_DEBUG
if (!NzDebugDrawer::Initialize())
NazaraWarning("Failed to initialize debug drawer");
#endif
NazaraNotice("Initialized: Renderer module");
return true;
}
bool NzRenderer::IsEnabled(nzRendererParameter parameter)
{
#ifdef NAZARA_DEBUG
if (NzContext::GetCurrent() == nullptr)
{
NazaraError("No active context");
return false;
}
if (parameter > nzRendererParameter_Max)
{
NazaraError("Renderer parameter out of enum");
return false;
}
#endif
switch (parameter)
{
case nzRendererParameter_ColorWrite:
{
GLboolean enabled;
glGetBooleanv(GL_COLOR_WRITEMASK, &enabled);
return enabled;
}
case nzRendererParameter_DepthWrite:
{
GLboolean enabled;
glGetBooleanv(GL_DEPTH_WRITEMASK, &enabled);
return enabled;
}
default:
return glIsEnabled(NzOpenGL::RendererParameter[parameter]);
}
}
bool NzRenderer::IsInitialized()
{
return s_moduleReferenceCouter != 0;
@@ -515,6 +610,14 @@ bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
void NzRenderer::SetLineWidth(float width)
{
#ifdef NAZARA_DEBUG
if (NzContext::GetCurrent() == nullptr)
{
NazaraError("No active context");
return;
}
#endif
#if NAZARA_RENDERER_SAFE
if (width <= 0.f)
{
@@ -528,6 +631,14 @@ void NzRenderer::SetLineWidth(float width)
void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix)
{
#ifdef NAZARA_DEBUG
if (type > nzMatrixType_Max)
{
NazaraError("Matrix type out of enum");
return;
}
#endif
s_matrix[type] = matrix;
// Invalidation des combinaisons
@@ -545,6 +656,14 @@ void NzRenderer::SetMatrix(nzMatrixType type, const NzMatrix4f& matrix)
void NzRenderer::SetPointSize(float size)
{
#ifdef NAZARA_DEBUG
if (NzContext::GetCurrent() == nullptr)
{
NazaraError("No active context");
return;
}
#endif
#if NAZARA_RENDERER_SAFE
if (size <= 0.f)
{
@@ -593,7 +712,7 @@ bool NzRenderer::SetShader(NzShader* shader)
s_matrixLocation[nzMatrixCombination_WorldView] = shader->GetUniformLocation("WorldViewMatrix");
s_matrixLocation[nzMatrixCombination_WorldViewProj] = shader->GetUniformLocation("WorldViewProjMatrix");
///FIXME: Peut VRAIMENT être optimisé
///FIXME: Peut être optimisé
for (unsigned int i = 0; i < totalMatrixCount; ++i)
s_matrixUpdated[i] = false;
}
@@ -605,6 +724,14 @@ bool NzRenderer::SetShader(NzShader* shader)
void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc)
{
#ifdef NAZARA_DEBUG
if (compareFunc > nzRendererComparison_Max)
{
NazaraError("Renderer comparison out of enum");
return;
}
#endif
if (compareFunc != s_stencilCompare)
{
s_stencilCompare = compareFunc;
@@ -614,6 +741,14 @@ void NzRenderer::SetStencilCompareFunction(nzRendererComparison compareFunc)
void NzRenderer::SetStencilFailOperation(nzStencilOperation failOperation)
{
#ifdef NAZARA_DEBUG
if (failOperation > nzStencilOperation_Max)
{
NazaraError("Stencil fail operation out of enum");
return;
}
#endif
if (failOperation != s_stencilFail)
{
s_stencilFail = failOperation;
@@ -632,6 +767,14 @@ void NzRenderer::SetStencilMask(nzUInt32 mask)
void NzRenderer::SetStencilPassOperation(nzStencilOperation passOperation)
{
#ifdef NAZARA_DEBUG
if (passOperation > nzStencilOperation_Max)
{
NazaraError("Stencil pass operation out of enum");
return;
}
#endif
if (passOperation != s_stencilPass)
{
s_stencilPass = passOperation;
@@ -650,6 +793,14 @@ void NzRenderer::SetStencilReferenceValue(unsigned int refValue)
void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation)
{
#ifdef NAZARA_DEBUG
if (zfailOperation > nzStencilOperation_Max)
{
NazaraError("Stencil zfail operation out of enum");
return;
}
#endif
if (zfailOperation != s_stencilZFail)
{
s_stencilZFail = zfailOperation;
@@ -705,17 +856,11 @@ bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer)
if (s_vertexBuffer != vertexBuffer)
{
s_vertexBuffer = vertexBuffer;
s_vaoUpdated = false;
}
return true;
}
const NzVertexDeclaration* vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
if (s_vertexDeclaration != vertexDeclaration)
s_vertexDeclaration = vertexDeclaration;
bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration)
{
if (s_vertexDeclaration != vertexDeclaration)
{
s_vertexDeclaration = vertexDeclaration;
s_vaoUpdated = false;
}
@@ -758,6 +903,10 @@ void NzRenderer::Uninitialize()
if (--s_moduleReferenceCouter != 0)
return; // Encore utilisé
#ifdef NAZARA_DEBUG
NzDebugDrawer::Uninitialize();
#endif
// Libération du module
NzContext::EnsureContext();
@@ -812,7 +961,8 @@ bool NzRenderer::EnsureStateUpdate()
// Cas spéciaux car il faut recalculer la matrice
if (!s_matrixUpdated[nzMatrixCombination_ViewProj])
{
s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View] * s_matrix[nzMatrixType_Projection];
s_matrix[nzMatrixCombination_ViewProj] = s_matrix[nzMatrixType_View];
s_matrix[nzMatrixCombination_ViewProj].Concatenate(s_matrix[nzMatrixType_Projection]);
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_ViewProj], s_matrix[nzMatrixCombination_ViewProj]);
s_matrixUpdated[nzMatrixCombination_ViewProj] = true;
@@ -820,7 +970,8 @@ bool NzRenderer::EnsureStateUpdate()
if (!s_matrixUpdated[nzMatrixCombination_WorldView])
{
s_matrix[nzMatrixCombination_WorldView] = NzMatrix4f::ConcatenateAffine(s_matrix[nzMatrixType_World], s_matrix[nzMatrixType_View]);
s_matrix[nzMatrixCombination_WorldView] = s_matrix[nzMatrixType_World];
s_matrix[nzMatrixCombination_WorldView].ConcatenateAffine(s_matrix[nzMatrixType_View]);
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldView], s_matrix[nzMatrixCombination_WorldView]);
s_matrixUpdated[nzMatrixCombination_WorldView] = true;
@@ -828,7 +979,8 @@ bool NzRenderer::EnsureStateUpdate()
if (!s_matrixUpdated[nzMatrixCombination_WorldViewProj])
{
s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView] * s_matrix[nzMatrixType_Projection];
s_matrix[nzMatrixCombination_WorldViewProj] = s_matrix[nzMatrixCombination_WorldView];
s_matrix[nzMatrixCombination_WorldViewProj].Concatenate(s_matrix[nzMatrixType_Projection]);
shaderImpl->SendMatrix(s_matrixLocation[nzMatrixCombination_WorldViewProj], s_matrix[nzMatrixCombination_WorldViewProj]);
s_matrixUpdated[nzMatrixCombination_WorldViewProj] = true;

View File

@@ -1382,7 +1382,6 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe
glTexSubImage2D(NzOpenGL::CubemapFace[face], level, rect.x, height-rect.height-rect.y, rect.width, rect.height, format.dataFormat, format.dataType, mirrored);
UnlockTexture(m_impl);
return true;
}
@@ -1480,7 +1479,8 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
case nzPixelFormat_Stencil16:
return false;
// Dépréciés depuis OpenGL 3 (FIXME: Il doit bien exister des remplaçants ..)
// Dépréciés depuis OpenGL 3
///FIXME: Il doit bien exister des remplaçants ..
case nzPixelFormat_L8:
case nzPixelFormat_LA8:
return false;