Index

zydeco / master

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1008 Dec 2023 15:215a717feFractal renderer update for articleJosh Stockin1557G

Blob @ zydeco / src / render / gl / GLRenderObject.cpp

text/plain1654 bytesdownload raw
1#include <list>
2
3#include "ZydecoCommon.hpp"
4#include "GLRenderObject.hpp"
5#include "GLProgram.hpp"
6#include "GLTexture.hpp"
7
8
9static Logger LOGGER("GLRenderObject");
10
11// static initialize
12std::map<uint64_t, std::list<GLRenderObject*>> GLRenderObject::s_renderObjects = {};
13
14
15GLRenderObject::GLRenderObject(std::string gl_program_name, uint64_t render_order):
16 m_renderOrder(render_order),
17 m_renderEnabled(true)
18{
19 if (gl_program_name != "")
20 {
21 m_glProgram = GLProgram::GetGLProgram(gl_program_name);
22 if (m_glProgram == nullptr) { ZydecoFault("GLRenderObject(): Program '{}' is nonexistent", gl_program_name); }
23 }
24
25 s_renderObjects.insert(std::pair<uint64_t, std::list<GLRenderObject*>>(render_order, {}));
26 s_renderObjects.at(render_order).push_back(this);
27}
28
29GLRenderObject::~GLRenderObject()
30{
31 s_renderObjects.at(m_renderOrder).remove(this);
32 if (s_renderObjects.at(m_renderOrder).empty())
33 {
34 s_renderObjects.erase(m_renderOrder);
35 }
36}
37
38void GLRenderObject::RenderEnable()
39{
40 m_renderEnabled = true;
41}
42
43void GLRenderObject::RenderDisable()
44{
45 m_renderEnabled = false;
46}
47
48void GLRenderObject::AddTexture(uint64_t texture_unit, GLTexture *texture)
49{
50 m_textures[texture_unit] = texture;
51}
52
53void GLRenderObject::GLTargetSetup()
54{
55 int program = m_glProgram->GetGLProgramID();
56
57 glUseProgram(program);
58
59 UploadUniforms(program);
60
61 for (std::pair<uint64_t, GLTexture*> texture : m_textures)
62 {
63 texture.second->BindAsTexture(texture.first);
64 }
65}
66
67std::map<uint64_t, std::list<GLRenderObject*>>& GLRenderObject::GetRenderObjects()
68{
69 return s_renderObjects;
70}
71