Made Context/RenderTarget usage constant

Former-commit-id: 07a2655ea642664bc49ca335cf5147ebf9fb9f26
This commit is contained in:
Lynix 2013-03-02 19:09:13 +01:00
parent 2f85b258e9
commit cd48d70844
10 changed files with 27 additions and 28 deletions

View File

@ -26,13 +26,13 @@ class NAZARA_API NzContext : public NzResource
const NzContextParameters& GetParameters() const;
bool IsActive() const;
bool SetActive(bool active);
bool SetActive(bool active) const;
void SwapBuffers();
static bool EnsureContext();
static NzContext* GetCurrent();
static const NzContext* GetCurrent();
static const NzContext* GetReference();
static NzContext* GetThreadContext();
static const NzContext* GetThreadContext();
static bool Initialize();
static void Uninitialize();

View File

@ -34,8 +34,8 @@ class NAZARA_API NzRenderTarget
virtual bool HasContext() const = 0;
protected:
virtual bool Activate() = 0;
virtual void Desactivate();
virtual bool Activate() const = 0;
virtual void Desactivate() const;
};
#endif // NAZARA_RENDERTARGET_HPP

View File

@ -48,8 +48,8 @@ class NAZARA_API NzRenderTexture : public NzRenderTarget, NzResourceListener, Nz
static bool IsSupported();
protected:
bool Activate() override;
void Desactivate() override;
bool Activate() const override;
void Desactivate() const override;
private:
void OnResourceDestroy(const NzResource* resource, int index) override;

View File

@ -53,7 +53,7 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
bool HasContext() const;
protected:
bool Activate() override;
bool Activate() const override;
private:
bool OnWindowCreated() override;

View File

@ -55,7 +55,7 @@ class NAZARA_API NzRenderer
static unsigned int GetMaxTextureUnits();
static float GetPointSize();
static const NzShader* GetShader();
static NzRenderTarget* GetTarget();
static const NzRenderTarget* GetTarget();
static NzRectui GetViewport();
static bool HasCapability(nzRendererCap capability);
@ -84,7 +84,7 @@ class NAZARA_API NzRenderer
static void SetStencilPassOperation(nzStencilOperation passOperation);
static void SetStencilReferenceValue(unsigned int refValue);
static void SetStencilZFailOperation(nzStencilOperation zfailOperation);
static bool SetTarget(NzRenderTarget* target);
static bool SetTarget(const NzRenderTarget* target);
static void SetTexture(nzUInt8 unit, const NzTexture* texture);
static void SetTextureSampler(nzUInt8 textureUnit, const NzTextureSampler& sampler);
static bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);

View File

@ -22,8 +22,8 @@
namespace
{
NAZARA_THREADLOCAL NzContext* currentContext = nullptr;
NAZARA_THREADLOCAL NzContext* threadContext = nullptr;
NAZARA_THREADLOCAL const NzContext* currentContext = nullptr;
NAZARA_THREADLOCAL const NzContext* threadContext = nullptr;
std::vector<NzContext*> contexts;
@ -219,7 +219,7 @@ bool NzContext::IsActive() const
return currentContext == this;
}
bool NzContext::SetActive(bool active)
bool NzContext::SetActive(bool active) const
{
#ifdef NAZARA_RENDERER_SAFE
if (!m_impl)
@ -300,7 +300,7 @@ bool NzContext::EnsureContext()
return true;
}
NzContext* NzContext::GetCurrent()
const NzContext* NzContext::GetCurrent()
{
return currentContext;
}
@ -310,7 +310,7 @@ const NzContext* NzContext::GetReference()
return s_reference;
}
NzContext* NzContext::GetThreadContext()
const NzContext* NzContext::GetThreadContext()
{
EnsureContext();
@ -320,7 +320,6 @@ NzContext* NzContext::GetThreadContext()
bool NzContext::Initialize()
{
NzContextParameters parameters;
// parameters.compatibilityProfile = true;
parameters.shared = false; // Difficile de partager le contexte de référence avec lui-même
s_reference = new NzContext;

View File

@ -23,7 +23,7 @@ bool NzRenderTarget::SetActive(bool active)
return true;
}
void NzRenderTarget::Desactivate()
void NzRenderTarget::Desactivate() const
{
// Seuls les target sans contextes (ex: NzRenderTexture) nécessitent une désactivation
}

View File

@ -48,11 +48,11 @@ struct NzRenderTextureImpl
{
GLuint fbo;
std::vector<Attachment> attachements;
std::vector<GLenum> drawBuffers;
NzContext* context;
mutable std::vector<GLenum> drawBuffers;
const NzContext* context;
bool checked = false;
bool complete = false;
bool drawBuffersUpdated = true;
mutable bool drawBuffersUpdated = true;
unsigned int height;
unsigned int width;
};
@ -665,7 +665,7 @@ bool NzRenderTexture::IsSupported()
return NzRenderer::HasCapability(nzRendererCap_RenderTexture);
}
bool NzRenderTexture::Activate()
bool NzRenderTexture::Activate() const
{
#if NAZARA_RENDERER_SAFE
if (NzContext::GetCurrent() != m_impl->context)
@ -694,7 +694,7 @@ bool NzRenderTexture::Activate()
return true;
}
void NzRenderTexture::Desactivate()
void NzRenderTexture::Desactivate() const
{
#if NAZARA_RENDERER_SAFE
if (NzContext::GetCurrent() != m_impl->context)

View File

@ -59,7 +59,7 @@ bool NzRenderWindow::CopyToImage(NzImage* image) const
}
#endif
NzContext* currentContext = NzContext::GetCurrent();
const NzContext* currentContext = NzContext::GetCurrent();
if (m_context != currentContext)
{
if (!m_context->SetActive(true))
@ -112,7 +112,7 @@ bool NzRenderWindow::CopyToTexture(NzTexture* texture) const
}
#endif
NzContext* currentContext = NzContext::GetCurrent();
const NzContext* currentContext = NzContext::GetCurrent();
if (m_context != currentContext)
{
if (!m_context->SetActive(true))
@ -258,7 +258,7 @@ bool NzRenderWindow::HasContext() const
return true;
}
bool NzRenderWindow::Activate()
bool NzRenderWindow::Activate() const
{
if (m_context->SetActive(true))
{

View File

@ -74,7 +74,7 @@ namespace
nzUInt8 s_maxAnisotropyLevel;
nzUInt32 s_stencilMask;
const NzIndexBuffer* s_indexBuffer;
NzRenderTarget* s_target;
const NzRenderTarget* s_target;
const NzShader* s_shader;
const NzVertexBuffer* s_vertexBuffer;
const NzVertexDeclaration* s_vertexDeclaration;
@ -479,7 +479,7 @@ const NzShader* NzRenderer::GetShader()
return s_shader;
}
NzRenderTarget* NzRenderer::GetTarget()
const NzRenderTarget* NzRenderer::GetTarget()
{
return s_target;
}
@ -1048,7 +1048,7 @@ void NzRenderer::SetStencilZFailOperation(nzStencilOperation zfailOperation)
}
}
bool NzRenderer::SetTarget(NzRenderTarget* target)
bool NzRenderer::SetTarget(const NzRenderTarget* target)
{
if (s_target == target)
return true;