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:
@@ -1,243 +0,0 @@
|
||||
// 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/Renderer/Buffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/HardwareBuffer.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/SoftwareBuffer.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
nzRendererCap storageToCapability[] = {
|
||||
nzRendererCap_HardwareBuffer, // nzBufferStorage_Hardware
|
||||
nzRendererCap_SoftwareBuffer, // nzBufferStorage_Software
|
||||
};
|
||||
}
|
||||
|
||||
NzBuffer::NzBuffer(nzBufferType type) :
|
||||
m_type(type),
|
||||
m_typeSize(0),
|
||||
m_impl(nullptr),
|
||||
m_length(0)
|
||||
{
|
||||
}
|
||||
|
||||
NzBuffer::NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferUsage usage) :
|
||||
m_type(type),
|
||||
m_impl(nullptr)
|
||||
{
|
||||
Create(length, typeSize, usage);
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Failed to create buffer");
|
||||
throw std::runtime_error("Constructor failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
NzBuffer::~NzBuffer()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool NzBuffer::CopyContent(NzBuffer& buffer)
|
||||
{
|
||||
void* ptr = buffer.Map(nzBufferAccess_ReadOnly);
|
||||
if (!ptr)
|
||||
{
|
||||
NazaraError("Failed to map source buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool r = Fill(ptr, 0, m_length);
|
||||
|
||||
if (!buffer.Unmap())
|
||||
NazaraWarning("Failed to unmap source buffer");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
bool NzBuffer::Create(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
// On tente d'abord de faire un buffer hardware, si supporté
|
||||
if (NazaraRenderer->HasCapability(nzRendererCap_HardwareBuffer))
|
||||
{
|
||||
m_impl = new NzHardwareBuffer(this, m_type);
|
||||
if (!m_impl->Create(length*typeSize, usage))
|
||||
{
|
||||
NazaraWarning("Failed to create hardware buffer, trying to create software buffer...");
|
||||
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_impl)
|
||||
{
|
||||
if (!NazaraRenderer->HasCapability(nzRendererCap_SoftwareBuffer))
|
||||
{
|
||||
// Ne devrait jamais arriver
|
||||
NazaraError("Software buffer not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl = new NzSoftwareBuffer(this, m_type);
|
||||
if (!m_impl->Create(length*typeSize, usage))
|
||||
{
|
||||
NazaraError("Failed to create software buffer");
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_length = length;
|
||||
m_typeSize = typeSize;
|
||||
m_usage = usage;
|
||||
|
||||
// Si on arrive ici c'est que tout s'est bien passé.
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzBuffer::Destroy()
|
||||
{
|
||||
if (m_impl)
|
||||
{
|
||||
m_impl->Destroy();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzBuffer::Fill(const void* data, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not created");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (offset+length > m_length)
|
||||
{
|
||||
NazaraError("Exceeding buffer size");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Fill(data, offset*m_typeSize, length*m_typeSize);
|
||||
}
|
||||
|
||||
void* NzBuffer::GetBufferPtr()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not created");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetBufferPtr();
|
||||
}
|
||||
|
||||
const void* NzBuffer::GetBufferPtr() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not created");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetBufferPtr();
|
||||
}
|
||||
|
||||
NzBufferImpl* NzBuffer::GetImpl() const
|
||||
{
|
||||
return m_impl;
|
||||
}
|
||||
|
||||
unsigned int NzBuffer::GetLength() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
||||
unsigned int NzBuffer::GetSize() const
|
||||
{
|
||||
return m_length*m_typeSize;
|
||||
}
|
||||
|
||||
nzBufferStorage NzBuffer::GetStorage() const
|
||||
{
|
||||
return m_storage;
|
||||
}
|
||||
|
||||
nzBufferType NzBuffer::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
nzUInt8 NzBuffer::GetTypeSize() const
|
||||
{
|
||||
return m_typeSize;
|
||||
}
|
||||
|
||||
nzBufferUsage NzBuffer::GetUsage() const
|
||||
{
|
||||
return m_usage;
|
||||
}
|
||||
|
||||
bool NzBuffer::IsHardware() const
|
||||
{
|
||||
return m_storage == nzBufferStorage_Hardware;
|
||||
}
|
||||
|
||||
void* NzBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not created");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset+length > m_length)
|
||||
{
|
||||
NazaraError("Exceeding buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Map(access, offset*m_typeSize, length*m_typeSize);
|
||||
}
|
||||
|
||||
bool NzBuffer::Unmap()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not created");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Unmap();
|
||||
}
|
||||
|
||||
bool NzBuffer::IsSupported(nzBufferStorage storage)
|
||||
{
|
||||
return NazaraRenderer->HasCapability(storageToCapability[storage]);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
// 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/BufferImpl.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzBufferImpl::~NzBufferImpl() = default;
|
||||
@@ -1,33 +0,0 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_BUFFERIMPL_HPP
|
||||
#define NAZARA_BUFFERIMPL_HPP
|
||||
|
||||
#include <Nazara/Renderer/Buffer.hpp>
|
||||
|
||||
class NzBufferImpl
|
||||
{
|
||||
public:
|
||||
NzBufferImpl() = default;
|
||||
virtual ~NzBufferImpl();
|
||||
|
||||
virtual void Bind() = 0;
|
||||
|
||||
virtual bool Create(unsigned int size, nzBufferUsage usage = nzBufferUsage_Static) = 0;
|
||||
virtual void Destroy() = 0;
|
||||
|
||||
virtual bool Fill(const void* data, unsigned int offset, unsigned int size) = 0;
|
||||
|
||||
virtual void* GetBufferPtr() = 0;
|
||||
|
||||
virtual bool IsHardware() const = 0;
|
||||
|
||||
virtual void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) = 0;
|
||||
virtual bool Unmap() = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_BUFFERIMPL_INCLUDED
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/VertexDeclaration.hpp>
|
||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
@@ -24,7 +24,7 @@ namespace
|
||||
4 // nzElementUsage_TexCoord
|
||||
};
|
||||
|
||||
const GLenum shaderType[nzShaderType_Count] = {
|
||||
const GLenum shaderType[nzShaderType_Max+1] = {
|
||||
GL_FRAGMENT_SHADER, // nzShaderType_Fragment
|
||||
GL_GEOMETRY_SHADER, // nzShaderType_Geometry
|
||||
GL_VERTEX_SHADER // nzShaderType_Vertex
|
||||
@@ -136,7 +136,7 @@ bool NzGLSLShader::Create()
|
||||
glBindAttribLocation(m_program, attribIndex[nzElementUsage_TexCoord]+i, uniformName.GetConstBuffer());
|
||||
}
|
||||
|
||||
for (int i = 0; i < nzShaderType_Count; ++i)
|
||||
for (int i = 0; i <= nzShaderType_Max; ++i)
|
||||
m_shaders[i] = 0;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -63,7 +63,7 @@ class NzGLSLShader : public NzShaderImpl
|
||||
mutable std::map<NzString, GLint> m_idCache;
|
||||
std::map<GLint, TextureSlot> m_textures;
|
||||
GLuint m_program;
|
||||
GLuint m_shaders[nzShaderType_Count];
|
||||
GLuint m_shaders[nzShaderType_Max+1];
|
||||
NzShader* m_parent;
|
||||
NzString m_log;
|
||||
};
|
||||
|
||||
@@ -188,7 +188,7 @@ bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int
|
||||
return true;
|
||||
}
|
||||
|
||||
void* NzHardwareBuffer::GetBufferPtr()
|
||||
void* NzHardwareBuffer::GetPointer()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NAZARA_HARDWAREBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/BufferImpl.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Utility/BufferImpl.hpp>
|
||||
|
||||
class NzHardwareBuffer : public NzBufferImpl
|
||||
{
|
||||
@@ -24,7 +24,7 @@ class NzHardwareBuffer : public NzBufferImpl
|
||||
|
||||
bool Fill(const void* data, unsigned int offset, unsigned int length);
|
||||
|
||||
void* GetBufferPtr();
|
||||
void* GetPointer();
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
// 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/IndexBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzIndexBuffer::NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount) :
|
||||
m_buffer(buffer),
|
||||
m_ownsBuffer(false),
|
||||
m_indexCount(indexCount),
|
||||
m_startIndex(startIndex)
|
||||
{
|
||||
if (m_buffer)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
nzUInt8 indexSize = m_buffer->GetSize();
|
||||
if (indexSize != 1 && indexSize != 2 && indexSize != 4)
|
||||
{
|
||||
NazaraError("Invalid index size (" + NzString::Number(indexSize) + ')');
|
||||
m_buffer = nullptr;
|
||||
|
||||
throw std::runtime_error("Constructor failed");
|
||||
}
|
||||
#endif
|
||||
|
||||
m_buffer->AddResourceReference();
|
||||
}
|
||||
}
|
||||
|
||||
NzIndexBuffer::NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferUsage usage) :
|
||||
m_ownsBuffer(true),
|
||||
m_indexCount(length),
|
||||
m_startIndex(0)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (indexSize != 1 && indexSize != 2 && indexSize != 4)
|
||||
{
|
||||
NazaraError("Invalid index size");
|
||||
m_buffer = nullptr;
|
||||
|
||||
throw std::runtime_error("Constructor failed");
|
||||
}
|
||||
#endif
|
||||
|
||||
m_buffer = new NzBuffer(nzBufferType_Index, length, indexSize, usage);
|
||||
m_buffer->AddResourceReference();
|
||||
m_buffer->SetPersistent(false);
|
||||
}
|
||||
|
||||
NzIndexBuffer::NzIndexBuffer(const NzIndexBuffer& indexBuffer) :
|
||||
m_buffer(indexBuffer.m_buffer),
|
||||
m_indexCount(indexBuffer.m_indexCount),
|
||||
m_startIndex(indexBuffer.m_startIndex)
|
||||
{
|
||||
if (m_buffer)
|
||||
{
|
||||
if (m_ownsBuffer)
|
||||
{
|
||||
m_buffer = new NzBuffer(nzBufferType_Index, indexBuffer.m_buffer->GetLength(), indexBuffer.m_buffer->GetSize(), indexBuffer.m_buffer->GetUsage());
|
||||
m_buffer->AddResourceReference();
|
||||
m_buffer->SetPersistent(false);
|
||||
m_buffer->CopyContent(*indexBuffer.m_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer = indexBuffer.m_buffer;
|
||||
m_buffer->AddResourceReference();
|
||||
}
|
||||
}
|
||||
else
|
||||
m_buffer = nullptr;
|
||||
}
|
||||
|
||||
NzIndexBuffer::~NzIndexBuffer()
|
||||
{
|
||||
if (m_buffer)
|
||||
m_buffer->RemoveResourceReference();
|
||||
}
|
||||
|
||||
bool NzIndexBuffer::Fill(const void* data, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Impossible to fill sequential buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (offset+length > m_indexCount)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Fill(data, m_startIndex+offset, length);
|
||||
}
|
||||
|
||||
NzBuffer* NzIndexBuffer::GetBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
void* NzIndexBuffer::GetBufferPtr()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Sequential index buffer: Buffer has no pointer");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return reinterpret_cast<nzUInt8*>(m_buffer->GetBufferPtr()) + m_startIndex*m_buffer->GetTypeSize();
|
||||
}
|
||||
|
||||
const void* NzIndexBuffer::GetBufferPtr() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Sequential index buffer: Buffer has no pointer");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return reinterpret_cast<const nzUInt8*>(m_buffer->GetBufferPtr()) + m_startIndex*m_buffer->GetTypeSize();
|
||||
}
|
||||
|
||||
nzUInt8 NzIndexBuffer::GetIndexSize() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Sequential index buffer: Buffer has no index size");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->GetTypeSize();
|
||||
}
|
||||
|
||||
unsigned int NzIndexBuffer::GetIndexCount() const
|
||||
{
|
||||
return m_indexCount;
|
||||
}
|
||||
|
||||
unsigned int NzIndexBuffer::GetStartIndex() const
|
||||
{
|
||||
return m_startIndex;
|
||||
}
|
||||
|
||||
bool NzIndexBuffer::IsHardware() const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Sequential index buffer is neither hardware or software");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->IsHardware();
|
||||
}
|
||||
|
||||
bool NzIndexBuffer::IsSequential() const
|
||||
{
|
||||
return m_buffer == nullptr;
|
||||
}
|
||||
|
||||
void* NzIndexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Impossible to map sequential index buffer");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset+length > m_indexCount)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Map(access, m_startIndex+offset, (length) ? length : m_indexCount-offset);
|
||||
}
|
||||
|
||||
bool NzIndexBuffer::Unmap()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("Impossible to unlock sequential index buffer");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Unmap();
|
||||
}
|
||||
@@ -400,6 +400,9 @@ bool NzOpenGL::Initialize()
|
||||
}
|
||||
}
|
||||
|
||||
// PixelBufferObject
|
||||
openGLextensions[NzOpenGL::PixelBufferObject] = (openGLversion >= 210 || IsSupported("GL_ARB_pixel_buffer_object"));
|
||||
|
||||
// SeparateShaderObjects
|
||||
if (openGLversion >= 400 || IsSupported("GL_ARB_gpu_shader_fp64"))
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
// 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/Renderer/SoftwareBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
GLenum bufferTarget[] = {
|
||||
GL_ELEMENT_ARRAY_BUFFER, // nzBufferType_Index,
|
||||
GL_ARRAY_BUFFER, // nzBufferType_Vertex
|
||||
};
|
||||
}
|
||||
|
||||
NzSoftwareBuffer::NzSoftwareBuffer(NzBuffer* parent, nzBufferType type) :
|
||||
m_type(type)
|
||||
{
|
||||
NazaraUnused(parent);
|
||||
}
|
||||
|
||||
NzSoftwareBuffer::~NzSoftwareBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
void NzSoftwareBuffer::Bind()
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (NzContext::GetCurrent() == nullptr)
|
||||
{
|
||||
NazaraError("No active context");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
glBindBuffer(bufferTarget[m_type], 0);
|
||||
}
|
||||
|
||||
bool NzSoftwareBuffer::Create(unsigned int size, nzBufferUsage usage)
|
||||
{
|
||||
NazaraUnused(usage);
|
||||
|
||||
// Cette allocation est protégée car sa taille dépend directement de paramètres utilisateurs
|
||||
try
|
||||
{
|
||||
m_buffer = new nzUInt8[size];
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
NazaraError("Failed to allocate software buffer (" + NzString(e.what()) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mapped = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzSoftwareBuffer::Destroy()
|
||||
{
|
||||
delete[] m_buffer;
|
||||
}
|
||||
|
||||
bool NzSoftwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (m_mapped)
|
||||
{
|
||||
NazaraError("Buffer already mapped");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::memcpy(&m_buffer[offset], data, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void* NzSoftwareBuffer::GetBufferPtr()
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
bool NzSoftwareBuffer::IsHardware() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void* NzSoftwareBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int size)
|
||||
{
|
||||
NazaraUnused(access);
|
||||
NazaraUnused(size);
|
||||
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (m_mapped)
|
||||
{
|
||||
NazaraError("Buffer already mapped");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_mapped = true;
|
||||
|
||||
return &m_buffer[offset];
|
||||
}
|
||||
|
||||
bool NzSoftwareBuffer::Unmap()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!m_mapped)
|
||||
{
|
||||
NazaraError("Buffer not mapped");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_mapped = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SOFTWAREBUFFER_HPP
|
||||
#define NAZARA_SOFTWAREBUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/BufferImpl.hpp>
|
||||
|
||||
class NzSoftwareBuffer : public NzBufferImpl
|
||||
{
|
||||
public:
|
||||
NzSoftwareBuffer(NzBuffer* parent, nzBufferType type);
|
||||
~NzSoftwareBuffer();
|
||||
|
||||
void Bind();
|
||||
|
||||
bool Create(unsigned int size, nzBufferUsage usage = nzBufferUsage_Static);
|
||||
void Destroy();
|
||||
|
||||
bool Fill(const void* data, unsigned int offset, unsigned int length);
|
||||
|
||||
void* GetBufferPtr();
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
private:
|
||||
nzBufferType m_type;
|
||||
nzUInt8* m_buffer;
|
||||
bool m_mapped;
|
||||
};
|
||||
|
||||
#endif // NAZARA_SOFTWAREBUFFER_HPP
|
||||
@@ -124,7 +124,6 @@ namespace
|
||||
return true;
|
||||
|
||||
case nzPixelFormat_Undefined:
|
||||
case nzPixelFormat_Count:
|
||||
NazaraInternalError("Invalid pixel format");
|
||||
return false;
|
||||
}
|
||||
@@ -252,8 +251,8 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
static unsigned short lockedLevel[nzImageType_Count] = {0};
|
||||
static GLuint lockedPrevious[nzImageType_Count] = {0};
|
||||
static unsigned short lockedLevel[nzImageType_Max+1] = {0};
|
||||
static GLuint lockedPrevious[nzImageType_Max+1] = {0};
|
||||
|
||||
void LockTexture(NzTextureImpl* impl)
|
||||
{
|
||||
@@ -1576,7 +1575,6 @@ bool NzTexture::IsFormatSupported(nzPixelFormat format)
|
||||
}
|
||||
|
||||
case nzPixelFormat_Undefined:
|
||||
case nzPixelFormat_Count:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
// 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/VertexBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzVertexBuffer::NzVertexBuffer(NzBuffer* buffer, unsigned int startVertex, unsigned int vertexCount) :
|
||||
m_buffer(buffer),
|
||||
m_ownsBuffer(false),
|
||||
m_startVertex(startVertex),
|
||||
m_vertexCount(vertexCount)
|
||||
{
|
||||
m_buffer->AddResourceReference();
|
||||
}
|
||||
|
||||
NzVertexBuffer::NzVertexBuffer(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage) :
|
||||
m_ownsBuffer(true),
|
||||
m_startVertex(0),
|
||||
m_vertexCount(length)
|
||||
{
|
||||
m_buffer = new NzBuffer(nzBufferType_Vertex, length, typeSize, usage);
|
||||
m_buffer->AddResourceReference();
|
||||
m_buffer->SetPersistent(false);
|
||||
}
|
||||
|
||||
NzVertexBuffer::NzVertexBuffer(const NzVertexBuffer& vertexBuffer) :
|
||||
m_ownsBuffer(vertexBuffer.m_ownsBuffer),
|
||||
m_startVertex(vertexBuffer.m_startVertex),
|
||||
m_vertexCount(vertexBuffer.m_vertexCount)
|
||||
{
|
||||
if (m_ownsBuffer)
|
||||
{
|
||||
m_buffer = new NzBuffer(nzBufferType_Vertex, vertexBuffer.m_buffer->GetLength(), vertexBuffer.m_buffer->GetSize(), vertexBuffer.m_buffer->GetUsage());
|
||||
m_buffer->AddResourceReference();
|
||||
m_buffer->SetPersistent(false);
|
||||
m_buffer->CopyContent(*vertexBuffer.m_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer = vertexBuffer.m_buffer;
|
||||
m_buffer->AddResourceReference();
|
||||
}
|
||||
}
|
||||
|
||||
NzVertexBuffer::~NzVertexBuffer()
|
||||
{
|
||||
m_buffer->RemoveResourceReference();
|
||||
}
|
||||
|
||||
bool NzVertexBuffer::Fill(const void* data, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (offset+length > m_vertexCount)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Fill(data, m_startVertex+offset, length);
|
||||
}
|
||||
|
||||
NzBuffer* NzVertexBuffer::GetBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
void* NzVertexBuffer::GetBufferPtr()
|
||||
{
|
||||
return reinterpret_cast<nzUInt8*>(m_buffer->GetBufferPtr()) + m_startVertex*m_buffer->GetTypeSize();
|
||||
}
|
||||
|
||||
const void* NzVertexBuffer::GetBufferPtr() const
|
||||
{
|
||||
return reinterpret_cast<const nzUInt8*>(m_buffer->GetBufferPtr()) + m_startVertex*m_buffer->GetTypeSize();
|
||||
}
|
||||
|
||||
unsigned int NzVertexBuffer::GetStartVertex() const
|
||||
{
|
||||
return m_startVertex;
|
||||
}
|
||||
|
||||
nzUInt8 NzVertexBuffer::GetTypeSize() const
|
||||
{
|
||||
return m_buffer->GetTypeSize();
|
||||
}
|
||||
|
||||
unsigned int NzVertexBuffer::GetVertexCount() const
|
||||
{
|
||||
return m_vertexCount;
|
||||
}
|
||||
|
||||
bool NzVertexBuffer::IsHardware() const
|
||||
{
|
||||
return m_buffer->IsHardware();
|
||||
}
|
||||
|
||||
void* NzVertexBuffer::Map(nzBufferAccess access, unsigned int offset, unsigned int length)
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (offset+length > m_vertexCount)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Map(access, m_startVertex+offset, (length) ? length : m_vertexCount-offset);
|
||||
}
|
||||
|
||||
bool NzVertexBuffer::Unmap()
|
||||
{
|
||||
return m_buffer->Unmap();
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
// 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/VertexDeclaration.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
const unsigned int size[] =
|
||||
{
|
||||
4, // nzElementType_Color
|
||||
8, // nzElementType_Double1
|
||||
16, // nzElementType_Double2
|
||||
24, // nzElementType_Double3
|
||||
32, // nzElementType_Double4
|
||||
4, // nzElementType_Float1
|
||||
8, // nzElementType_Float2
|
||||
12, // nzElementType_Float3
|
||||
16 // nzElementType_Float4
|
||||
};
|
||||
}
|
||||
|
||||
bool NzVertexDeclaration::Create(const NzVertexElement* elements, unsigned int elementCount)
|
||||
{
|
||||
for (unsigned int i = 0; i < elementCount; ++i)
|
||||
{
|
||||
unsigned int stream = elements[i].stream;
|
||||
|
||||
if (stream >= m_streams.size())
|
||||
m_streams.resize(stream+1);
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
else // Seulement si le stream ne vient pas d'être créé (Autrement c'est inutile)
|
||||
{
|
||||
bool fp64 = NazaraRenderer->HasCapability(nzRendererCap_FP64);
|
||||
|
||||
for (unsigned int j = 0; j < i; ++j)
|
||||
{
|
||||
if (elements[j].stream == stream && elements[j].usage == elements[i].usage && elements[j].usageIndex == elements[i].usageIndex)
|
||||
{
|
||||
NazaraError("Element usage (" + NzString::Number(elements[j].usage, 16) + ") collision on stream " + NzString::Number(stream) + " with usage index " + NzString::Number(elements[j].usageIndex));
|
||||
return false;
|
||||
}
|
||||
else if (!fp64 && elements[j].type >= nzElementType_Double1 && elements[j].type <= nzElementType_Double4)
|
||||
{
|
||||
NazaraError("FP64 not supported");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Element element;
|
||||
element.offset = elements[i].offset;
|
||||
element.type = elements[i].type;
|
||||
element.usage = elements[i].usage;
|
||||
element.usageIndex = elements[i].usageIndex;
|
||||
|
||||
m_streams[stream].elements.push_back(element);
|
||||
}
|
||||
|
||||
for (Stream& stream : m_streams)
|
||||
{
|
||||
stream.stride = 0;
|
||||
for (const Element& element : stream.elements)
|
||||
stream.stride += size[element.type];
|
||||
|
||||
#if NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32
|
||||
stream.stride = ((static_cast<int>(stream.stride)-1)/32+1)*32;
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const NzVertexDeclaration::Element* NzVertexDeclaration::GetElement(unsigned int i, unsigned int stream) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (stream >= m_streams.size())
|
||||
{
|
||||
NazaraError("Stream out of range");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (i >= m_streams[stream].elements.size())
|
||||
{
|
||||
NazaraError("Index out of range");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return &m_streams[stream].elements[i];
|
||||
}
|
||||
|
||||
unsigned int NzVertexDeclaration::GetElementCount(unsigned int stream) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (stream >= m_streams.size())
|
||||
{
|
||||
NazaraError("Stream out of range");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_streams[stream].elements.size();
|
||||
}
|
||||
|
||||
unsigned int NzVertexDeclaration::GetStreamCount() const
|
||||
{
|
||||
return m_streams.size();
|
||||
}
|
||||
|
||||
unsigned int NzVertexDeclaration::GetStride(unsigned int stream) const
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (stream >= m_streams.size())
|
||||
{
|
||||
NazaraError("Stream out of range");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_streams[stream].stride;
|
||||
}
|
||||
Reference in New Issue
Block a user