Pioneer
Loading...
Searching...
No Matches
RenderStateCache.h
Go to the documentation of this file.
1// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#pragma once
5
6#include "Color.h"
7#include "OpenGLLibs.h"
8#include "graphics/Graphics.h"
11
12#include <vector>
13
14namespace Graphics {
15 class RendererOGL;
16
17 namespace OGL {
18 class TextureGL;
19 class RenderTarget;
20 class Program;
21 class IndexBuffer;
22 class UniformBuffer;
23 class VertexBuffer;
24 struct UniformBufferBinding;
25
27 public:
28 size_t GetActiveRenderStateHash() const { return m_activeRenderStateHash; }
29 const RenderStateDesc &GetActiveRenderState() const { return m_activeRenderState; }
30
31 GLuint GetVertexArrayObject(size_t hash);
32
33 void SetRenderState(size_t hash);
34 void SetTexture(uint32_t index, TextureGL *texture);
35 void SetBufferBinding(uint32_t index, BufferBinding<UniformBuffer> binding);
36 void SetProgram(Program *program);
37
38 void SetRenderTarget(RenderTarget *target);
39 void SetRenderTarget(RenderTarget *target, ViewportExtents extents);
40 RenderTarget *GetActiveRenderTarget() const { return m_activeRT; }
41 ViewportExtents GetActiveViewport() const { return m_currentExtents; }
42
43 void SetScissor(ViewportExtents scissor);
44 void ClearBuffers(bool colorBuffer, bool depthBuffer, Color clearColor);
45
46 private:
48 RenderStateCache() = default;
49
50 const RenderStateDesc &GetRenderState(size_t hash) const;
51 size_t InternRenderState(const RenderStateDesc &rsd);
52
53 // Cache the given vertex format descriptor and create the associated
54 // vertex array object needed to draw it.
55 size_t CacheVertexDesc(const Graphics::VertexBufferDesc &desc);
56
57 // Create the canonical representation of the given vertex attribute set
58 // and cache the VAO needed for it.
59 size_t InternVertexAttribSet(Graphics::AttributeSet attribSet);
60
61 void ApplyRenderState(const RenderStateDesc &rsd);
62 void ResetFrame();
63
64 std::vector<TextureGL *> m_textureCache;
65 std::vector<BufferBinding<UniformBuffer>> m_bufferCache;
66
67 size_t m_activeRenderStateHash = 0;
68 RenderStateDesc m_activeRenderState;
69 std::vector<std::pair<size_t, RenderStateDesc>> m_stateDescCache;
70
71 // contains a mapping of hash->VAO on a per-vertex-format basis
72 std::vector<std::pair<size_t, GLuint>> m_vtxDescObjectCache;
73
74 GLuint m_activeProgram = 0;
75 RenderTarget *m_activeRT = 0;
76 ViewportExtents m_currentExtents;
77 ViewportExtents m_currentScissor;
78 };
79
80 } // namespace OGL
81} // namespace Graphics
Definition Program.h:25
Definition RenderStateCache.h:26
const RenderStateDesc & GetActiveRenderState() const
Definition RenderStateCache.h:29
void ClearBuffers(bool colorBuffer, bool depthBuffer, Color clearColor)
Definition RenderStateCache.cpp:262
GLuint GetVertexArrayObject(size_t hash)
Definition RenderStateCache.cpp:166
RenderTarget * GetActiveRenderTarget() const
Definition RenderStateCache.h:40
void SetRenderTarget(RenderTarget *target)
Definition RenderStateCache.cpp:233
size_t GetActiveRenderStateHash() const
Definition RenderStateCache.h:28
void SetRenderState(size_t hash)
Definition RenderStateCache.cpp:31
void SetTexture(uint32_t index, TextureGL *texture)
Definition RenderStateCache.cpp:187
ViewportExtents GetActiveViewport() const
Definition RenderStateCache.h:41
void SetBufferBinding(uint32_t index, BufferBinding< UniformBuffer > binding)
Definition RenderStateCache.cpp:209
void SetProgram(Program *program)
Definition RenderStateCache.cpp:223
void SetScissor(ViewportExtents scissor)
Definition RenderStateCache.cpp:253
Definition RenderTargetGL.h:21
Definition TextureGL.h:12
Definition RendererGL.h:37
Definition Background.h:14
Definition Color.h:66
Definition Types.h:27
Definition BufferCommon.h:63
Definition RenderState.h:10
Definition VertexBuffer.h:43
Definition Graphics.h:59