9#ifndef AVARA3D_RENDER_BACKEND_OPENGL_OGLRENDERER_H
10#define AVARA3D_RENDER_BACKEND_OPENGL_OGLRENDERER_H
12#include "a3d/render/Renderer.h"
13#include "a3d/render/backend/opengl/GLTypes.h"
14#include "a3d/render/backend/opengl/ImguiContext.h"
15#include "a3d/render/backend/opengl/OGLDebugLines.h"
16#include "a3d/render/backend/opengl/OGLDrawTimer.h"
17#include "a3d/render/backend/opengl/OGLMemoryTracker.h"
18#include "a3d/render/backend/opengl/OGLResourceCache.h"
19#include "a3d/render/backend/opengl/StatsOverlay.h"
32 class OGLRenderer :
public Renderer {
38 PipelineId pipelineId = INVALID_PIPELINE_ID;
39 gl::uint_t program = 0;
40 const Material* material =
nullptr;
41 uint32_t indexCount = 0;
46 gl::sizei_t indexCount = 0;
47 gl::enum_t indexType = gl::value::unsigned_int;
48 gl::sizei_t vertexCount = 0;
53 using GLGetProcAddress =
void* (*) (
const char* name);
54 static bool InitGL(GLGetProcAddress getProcAddress);
60 OGLRenderer(
const OGLRenderer& other) =
delete;
61 OGLRenderer& operator=(
const OGLRenderer& other) =
delete;
63 OGLRenderer(OGLRenderer&& other) =
delete;
64 OGLRenderer& operator=(OGLRenderer&& other) =
delete;
66 ~OGLRenderer()
override;
70 bool initialize(
const RenderContext& context)
override;
71 bool isInitialized()
const override;
73 const Renderer::Capabilities& capabilities()
const override;
75 void beginFrame(
const Scene& scene,
76 const RenderContext& context,
79 Profiler& profiler)
override;
80 void endFrame(
const Scene& scene,
81 const RenderContext& context,
85 const FrameStatsHistory& statsHistory)
override;
87 void preTraversal(
const Scene& scene,
88 const RenderContext& context,
90 FrameStats& stats)
override;
91 void postTraversal(
const Scene& scene,
92 const RenderContext& context,
93 const math::mat4& view,
94 const std::vector<Node*>& lightNodes,
96 FrameStats& stats)
override;
98 void clear(
const ClearCommand& cmd,
const RenderContext& context)
override;
100 void renderPacket(DrawPacket& packet,
const FrameParams& frame)
override;
102 std::unique_ptr<Image> snapshot(
const RenderContext& context)
const override;
107 void drawBackground(
const BackgroundPass& backgroundPass,
108 const math::mat4& view,
109 const math::mat4& proj)
override;
110 void drawGround(
const GroundPass& groundPass,
const math::mat4& view,
const math::mat4& proj)
override;
111 void bindPipeline(PipelineId pipelineId)
override;
112 void bindMaterial(
const Material& material)
override;
113 void bindMeshElement(
const MeshElement& element)
override;
114 void applyMVP(
const math::mat4& model,
const math::mat4& view,
const math::mat4& proj)
override;
115 void drawElements()
override;
116 void drawLines(
const LinesPass& pass,
117 const RenderContext& context,
118 const math::mat4& view,
119 const math::mat4& proj)
override;
120 void resolvePacket(DrawPacket& packet,
const FrameParams& frame)
override;
121 void drawPacket(
const DrawPacket& packet,
const FrameParams& frame)
override;
126 struct Capabilities {
127 bool polygonMode {
false};
128 bool drawTimer {
false};
133 GLSLProgram& programForShaderKind(ShaderKind kind)
const;
134 void drawDebugLines(
const math::mat4& model,
const math::mat4& view,
const math::mat4& proj);
135 void syncImguiMemoryStats();
140 OGLRenderer::Capabilities _glCapabilities;
141 Renderer::Capabilities _capabilities;
142 unsigned _glEnvironmentUBO;
143 std::unique_ptr<GLSLProgram> _skyboxProgram;
144 std::unique_ptr<GLSLProgram> _groundProgram;
145 std::unique_ptr<GLSLProgram> _defaultProgram;
146 std::unique_ptr<GLSLProgram> _wireframeProgram;
147 std::unique_ptr<GLSLProgram> _linesProgram;
148 OGLMemoryTracker _memoryTracker;
149 OGLResourceCache _resourceCache;
151 BoundElement _boundElement;
152 std::unique_ptr<Mesh> _skyboxMesh;
153 gl::uint_t _fullscreenTriangleVao;
154 OGLDebugLines _debugLines;
155 ImguiContext _imguiContext;
156 StatsOverlay _statsOverlay;
157 OGLDrawTimer _drawTimer;
DebugOptions
Scene-wide debug visualization options.