Fixed compilation in debug mode
This commit is contained in:
parent
a215920818
commit
8c420b48c3
|
|
@ -31,6 +31,7 @@ class NAZARA_API NzContext
|
|||
|
||||
static const NzContext* GetCurrent();
|
||||
static const NzContext* GetReference();
|
||||
static const NzContext* GetThreadContext();
|
||||
static bool InitializeReference();
|
||||
static void UninitializeReference();
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class NAZARA_API NzRenderer
|
|||
void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount);
|
||||
void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount);
|
||||
|
||||
unsigned int GetMaxTextureUnits() const;
|
||||
NzShader* GetShader() const;
|
||||
NzRenderTarget* GetTarget() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
///TODO: Thread-local
|
||||
NzContext* currentContext = nullptr;
|
||||
NzContext* threadContext = nullptr;
|
||||
}
|
||||
|
||||
NzContext::NzContext() :
|
||||
|
|
@ -31,7 +33,7 @@ NzContext::~NzContext()
|
|||
{
|
||||
if (m_impl)
|
||||
{
|
||||
if (m_impl->IsActive())
|
||||
if (currentContext == this)
|
||||
NzContextImpl::Desactivate();
|
||||
|
||||
m_impl->Destroy();
|
||||
|
|
@ -92,7 +94,7 @@ bool NzContext::IsActive() const
|
|||
}
|
||||
#endif
|
||||
|
||||
return m_impl->IsActive();
|
||||
return currentContext == this;
|
||||
}
|
||||
|
||||
bool NzContext::SetActive(bool active)
|
||||
|
|
@ -105,13 +107,24 @@ bool NzContext::SetActive(bool active)
|
|||
}
|
||||
#endif
|
||||
|
||||
// Si le contexte est déjà activé/désactivé
|
||||
if ((currentContext == this) == active)
|
||||
return true;
|
||||
|
||||
if (active)
|
||||
{
|
||||
if (!m_impl->IsActive())
|
||||
return m_impl->Activate();
|
||||
if (!m_impl->Activate())
|
||||
return false;
|
||||
|
||||
currentContext = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!NzContextImpl::Desactivate())
|
||||
return false;
|
||||
|
||||
currentContext = nullptr;
|
||||
}
|
||||
else if (m_impl->IsActive())
|
||||
return NzContextImpl::Desactivate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -135,11 +148,21 @@ void NzContext::SwapBuffers()
|
|||
m_impl->SwapBuffers();
|
||||
}
|
||||
|
||||
const NzContext* NzContext::GetCurrent()
|
||||
{
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
const NzContext* NzContext::GetReference()
|
||||
{
|
||||
return s_reference;
|
||||
}
|
||||
|
||||
const NzContext* NzContext::GetThreadContext()
|
||||
{
|
||||
return threadContext;
|
||||
}
|
||||
|
||||
bool NzContext::InitializeReference()
|
||||
{
|
||||
NzContextParameters parameters;
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ namespace
|
|||
};
|
||||
|
||||
GLenum bufferTargetBinding[] = {
|
||||
GL_ELEMENT_ARRAY_BUFFER_BINDING, // BufferType_Index,
|
||||
GL_ARRAY_BUFFER_BINDING, // BufferType_Vertex
|
||||
GL_ELEMENT_ARRAY_BUFFER_BINDING, // nzBufferType_Index,
|
||||
GL_ARRAY_BUFFER_BINDING, // nzBufferType_Vertex
|
||||
};
|
||||
|
||||
GLenum bufferUsage[] = {
|
||||
// J'ai choisi DYNAMIC_DRAW à la place de STREAM_DRAW car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus"
|
||||
// J'ai choisi DYNAMIC à la place de STREAM car DYNAMIC semble plus adapté au profil "une mise à jour pour quelques rendus"
|
||||
// Ce qui est je pense le scénario qui arrivera le plus souvent (Prévoir une option pour permettre d'utiliser le STREAM_DRAW ?)
|
||||
// Source: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=160839
|
||||
GL_DYNAMIC_DRAW, // nzBufferUsage_Dynamic
|
||||
|
|
@ -145,8 +145,8 @@ bool NzHardwareBuffer::Fill(const void* data, unsigned int offset, unsigned int
|
|||
if (size < 32*1024)
|
||||
{
|
||||
// http://www.opengl.org/wiki/Vertex_Specification_Best_Practices
|
||||
if (size == m_parent->GetLength()) // Discard
|
||||
glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetStorage()]);
|
||||
if (size == m_parent->GetLength())
|
||||
glBufferData(bufferTarget[m_type], m_parent->GetSize(), nullptr, bufferUsage[m_parent->GetStorage()]); // Discard
|
||||
|
||||
glBufferSubData(bufferTarget[m_type], offset, size, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Renderer/IndexBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzIndexBuffer::NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount) :
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/BufferImpl.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/IndexBuffer.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
|
|
@ -81,7 +82,7 @@ void NzRenderer::DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int f
|
|||
#ifdef NAZARA_DEBUG
|
||||
if (!m_indexBuffer)
|
||||
{
|
||||
UngineError("No index buffer");
|
||||
NazaraError("No index buffer");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -134,6 +135,20 @@ void NzRenderer::DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVer
|
|||
glDrawArrays(openglPrimitive[primitive], firstVertex, vertexCount);
|
||||
}
|
||||
|
||||
unsigned int NzRenderer::GetMaxTextureUnits() const
|
||||
{
|
||||
static int maxTextureUnits = -1;
|
||||
if (maxTextureUnits == -1)
|
||||
{
|
||||
if (m_capabilities[nzRendererCap_TextureMulti])
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
|
||||
else
|
||||
maxTextureUnits = 1;
|
||||
}
|
||||
|
||||
return maxTextureUnits;
|
||||
}
|
||||
|
||||
NzShader* NzRenderer::GetShader() const
|
||||
{
|
||||
return m_shader;
|
||||
|
|
|
|||
|
|
@ -209,11 +209,6 @@ void NzContextImpl::Destroy()
|
|||
DestroyWindow(m_window);
|
||||
}
|
||||
|
||||
bool NzContextImpl::IsActive() const
|
||||
{
|
||||
return wglGetCurrentContext() == m_context;
|
||||
}
|
||||
|
||||
void NzContextImpl::SwapBuffers()
|
||||
{
|
||||
::SwapBuffers(m_deviceContext);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ class NzContextImpl
|
|||
bool Activate();
|
||||
bool Create(NzContextParameters& parameters);
|
||||
void Destroy();
|
||||
bool IsActive() const;
|
||||
void SwapBuffers();
|
||||
|
||||
static bool Desactivate();
|
||||
|
|
|
|||
Loading…
Reference in New Issue