Moved buffers to Utility

Fixed NzVector4::operator/
Replaced enumName_Count by enumName_Max
Renamed (Index/Vertex)Buffer::GetBufferPtr by GetPointer
This commit is contained in:
Lynix
2012-06-21 09:49:47 +02:00
parent be0a5d2819
commit ec9470ceb6
31 changed files with 291 additions and 258 deletions

View File

@@ -6,16 +6,17 @@
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Renderer/BufferImpl.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/IndexBuffer.hpp>
#include <Nazara/Renderer/HardwareBuffer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderImpl.hpp>
#include <Nazara/Renderer/VertexBuffer.hpp>
#include <Nazara/Renderer/VertexDeclaration.hpp>
#include <Nazara/Utility/BufferImpl.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <stdexcept>
#include <Nazara/Renderer/Debug.hpp>
@@ -128,6 +129,11 @@ namespace
GL_REPLACE, // nzStencilOperation_Replace
GL_ZERO // nzStencilOperation_Zero
};
NzBufferImpl* HardwareBufferFunction(NzBuffer* parent, nzBufferType type)
{
return new NzHardwareBuffer(parent, type);
}
}
NzRenderer::NzRenderer()
@@ -219,7 +225,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
return;
}
glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(m_indexBuffer->GetBufferPtr()) + firstIndex*indexSize);
glDrawElements(openglPrimitive[primitive], indexCount, type, reinterpret_cast<const nzUInt8*>(m_indexBuffer->GetPointer()) + firstIndex*indexSize);
}
void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount)
@@ -333,15 +339,13 @@ bool NzRenderer::Initialize()
m_utilityModule = new NzUtility;
m_utilityModule->Initialize();
}
else
m_utilityModule = nullptr;
if (NzOpenGL::Initialize())
{
NzContext::EnsureContext();
const NzContext* context = NzContext::GetReference();
bool compatibility = context->GetParameters().compatibilityProfile;
m_vaoUpdated = false;
m_indexBuffer = nullptr;
m_shader = nullptr;
m_stencilCompare = nzRendererComparison_Always;
@@ -353,6 +357,7 @@ bool NzRenderer::Initialize()
m_stencilReference = 0;
m_stencilZFail = nzStencilOperation_Keep;
m_target = nullptr;
m_vaoUpdated = false;
m_vertexBuffer = nullptr;
m_vertexDeclaration = nullptr;
@@ -362,7 +367,7 @@ bool NzRenderer::Initialize()
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_SoftwareBuffer] = compatibility || NzOpenGL::GetVersion() <= 300; // Déprécié en OpenGL 3
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
@@ -398,6 +403,8 @@ bool NzRenderer::Initialize()
else
m_maxTextureUnit = 1;
NzBuffer::SetBufferFunction(nzBufferStorage_Hardware, HardwareBufferFunction);
s_initialized = true;
return true;
@@ -497,9 +504,16 @@ void NzRenderer::SetFaceFilling(nzFaceFilling fillingMode)
glPolygonMode(GL_FRONT_AND_BACK, faceFillingMode[fillingMode]);
}
bool NzRenderer::SetIndexBuffer(const NzIndexBuffer* indexBuffer)
{
#if NAZARA_RENDERER_SAFE
if (indexBuffer && !indexBuffer->IsHardware())
{
NazaraError("Buffer must be hardware");
return false;
}
#endif
if (indexBuffer != m_indexBuffer)
{
m_indexBuffer = indexBuffer;
@@ -635,6 +649,14 @@ bool NzRenderer::SetTarget(NzRenderTarget* target)
bool NzRenderer::SetVertexBuffer(const NzVertexBuffer* vertexBuffer)
{
#if NAZARA_RENDERER_SAFE
if (vertexBuffer && !vertexBuffer->IsHardware())
{
NazaraError("Buffer must be hardware");
return false;
}
#endif
if (m_vertexBuffer != vertexBuffer)
{
m_vertexBuffer = vertexBuffer;
@@ -675,13 +697,7 @@ void NzRenderer::SetViewport(const NzRectui& viewport)
}
unsigned int width = m_target->GetWidth();
if (viewport.x+viewport.width >= width)
{
NazaraError("Rectangle dimensions are out of bounds");
return;
}
if (viewport.y+viewport.height >= height)
if (viewport.x+viewport.width > width || viewport.y+viewport.height > height)
{
NazaraError("Rectangle dimensions are out of bounds");
return;
@@ -812,9 +828,10 @@ bool NzRenderer::EnsureStateUpdate()
if (update)
{
m_vertexBuffer->GetBuffer()->GetImpl()->Bind();
NzHardwareBuffer* vertexBuffer = static_cast<NzHardwareBuffer*>(m_vertexBuffer->GetBuffer()->GetImpl());
vertexBuffer->Bind();
const nzUInt8* buffer = reinterpret_cast<const nzUInt8*>(m_vertexBuffer->GetBufferPtr());
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
@@ -836,7 +853,10 @@ bool NzRenderer::EnsureStateUpdate()
}
if (m_indexBuffer)
m_indexBuffer->GetBuffer()->GetImpl()->Bind();
{
NzHardwareBuffer* indexBuffer = static_cast<NzHardwareBuffer*>(m_indexBuffer->GetBuffer()->GetImpl());
indexBuffer->Bind();
}
}
if (vaoSupported)