1 #ifndef VVGL_GLScene_hpp 2 #define VVGL_GLScene_hpp 4 #include "VVGL_Defines.hpp" 9 #include "GLBufferPool.hpp" 10 #include "GLCachedProperty.hpp" 12 #if defined(VVGL_SDK_MAC) 13 #import <TargetConditionals.h> 47 using RenderPrepCallback = std::function<void(const GLScene & inScene, const bool & inSceneReshaped, const bool & inPgmChanged)>;
52 GLBufferRef fbo =
nullptr;
54 GLBufferRef color =
nullptr;
56 GLBufferRef depth =
nullptr;
60 RenderTarget(
const GLBufferRef &f,
const GLBufferRef &c,
const GLBufferRef &d) { fbo=f;color=c;depth=d; };
63 inline uint32_t
fboName()
const {
return (fbo==
nullptr) ? 0 : fbo->name; };
65 inline uint32_t
colorName()
const {
return (color==
nullptr) ? 0 : color->name; };
67 inline uint32_t
colorTarget()
const {
return (color==
nullptr) ? GL_TEXTURE_2D : color->desc.target; };
69 inline uint32_t
depthName()
const {
return (depth==
nullptr) ? 0 : depth->name; };
71 inline uint32_t
depthTarget()
const {
return (depth==
nullptr) ? GL_TEXTURE_2D : depth->desc.target; };
77 recursive_mutex _renderLock;
78 GLContextRef _context =
nullptr;
80 bool _deleted =
false;
81 bool _initialized =
false;
82 bool _needsReshape =
true;
83 bool _alwaysNeedsReshape =
false;
86 RenderPrepCallback _renderPrepCallback =
nullptr;
88 RenderCallback _renderPreLinkCallback =
nullptr;
90 RenderCallback _renderCallback =
nullptr;
91 RenderCallback _renderCleanupCallback =
nullptr;
93 RenderTarget _renderTarget;
96 Size _orthoSize = { 0., 0. };
97 bool _orthoFlipped =
false;
98 GLCachedUni _orthoUni = GLCachedUni(
"vvglOrthoProj");
101 bool _performClear =
true;
102 GLColor _clearColor = GLColor(0., 0., 0., 0.);
103 bool _clearColorUpdated =
false;
106 string *_vsString =
nullptr;
107 string *_gsString =
nullptr;
108 string *_fsString =
nullptr;
109 bool _vsStringUpdated =
false;
110 bool _gsStringUpdated =
false;
111 bool _fsStringUpdated =
false;
112 uint32_t _program = 0;
118 map<string,string> _errDict;
121 GLBufferPoolRef _privatePool =
nullptr;
122 GLTexToTexCopierRef _privateCopier =
nullptr;
130 GLScene(
const GLContextRef & inCtx);
134 virtual void prepareToBeDeleted();
143 virtual GLBufferRef createAndRenderABuffer(
const Size & inSize=Size(640.,480.),
const GLBufferPoolRef & inPool=
nullptr);
145 virtual void renderToBuffer(
const GLBufferRef & inBuffer);
147 virtual void render(
const RenderTarget & inRenderTarget=RenderTarget());
149 virtual void renderBlackFrame(
const RenderTarget & inRenderTarget=RenderTarget());
151 virtual void renderOpaqueBlackFrame(
const RenderTarget & inRenderTarget=RenderTarget());
153 virtual void renderRedFrame(
const RenderTarget & inRenderTarget=RenderTarget());
159 inline GLContextRef
context()
const {
return _context; }
169 void setRenderPreLinkCallback(
const RenderCallback & n);
171 void setRenderPrepCallback(
const RenderPrepCallback & n);
173 void setRenderCallback(
const RenderCallback & n);
175 void setRenderCleanupCallback(
const RenderCallback & n);
187 void setAlwaysNeedsReshape(
const bool & n);
189 virtual void setOrthoSize(
const Size & n);
191 Size orthoSize()
const;
193 void setOrthoFlipped(
const bool & n);
195 bool orthoFlipped()
const;
206 void setClearColor(
const GLColor & n);
208 void setClearColor(
const float & r,
const float & g,
const float & b,
const float & a);
210 void setClearColor(
float * n);
212 void setPerformClear(
const bool & n);
225 virtual void setVertexShaderString(
const string & n);
227 virtual string vertexShaderString();
229 virtual void setGeometryShaderString(
const string & n);
231 virtual string geometryShaderString();
233 virtual void setFragmentShaderString(
const string & n);
235 virtual string fragmentShaderString();
237 inline uint32_t
program()
const {
return _program; }
243 inline GLVersion glVersion()
const {
if (_context==
nullptr)
return GLVersion_Unknown;
return _context->version; }
256 virtual void _renderPrep();
258 virtual void _initialize();
260 virtual void _reshape();
262 virtual void _renderCleanup();
This struct describes an RGBA color.
Definition: VVGL_Base.hpp:116
shared_ptr< GLScene > GLSceneRef
A GLSceneRef is a shared pointer around a GLScene.
Definition: VVGL_Base.hpp:65
Definition: GLBuffer.hpp:13
GLContextRef context() const
Returns the context used by this scene.
Definition: GLScene.hpp:159
GLSceneRef CreateGLSceneRefUsing(const GLContextRef &inCtx)
Creates and returns a GLScene. The scene uses the passed GL context to do its drawing.
Definition: GLScene.hpp:277
Basic struct for 2D size.
Definition: VVGL_Geom.hpp:46
std::function< void(const GLScene &inScene, const bool &inSceneReshaped, const bool &inPgmChanged)> RenderPrepCallback
This defines the interface for the render prep callback, which is executed prior to the render callba...
Definition: GLScene.hpp:47
GLSceneRef CreateGLSceneRef()
Creates and returns a GLScene. The scene makes a new GL context which shares the context of the globa...
Definition: GLScene.hpp:272
std::function< void(const GLScene &inScene)> RenderCallback
This defines the interface for a function/lambda that is used for encapsulating user-provided drawing...
Definition: GLScene.hpp:40
void setPrivateCopier(const GLTexToTexCopierRef &n)
Sets the receiver's private buffer copier (which should default to null). If non-null, this copier will be used to copy any resources that need to be copied- like setPrivatePool(), handy if you have a variety of GL contexts that aren't shared and you have to switch between them rapidly on a per-frame basis.
Definition: GLScene.hpp:250
Manages drawing in a GLContext, provides a simple interface for orthographic rendering, render-to-texture operations, and loading vert/geo/frag shaders.
Definition: GLScene.hpp:33
RenderTarget(const GLBufferRef &f, const GLBufferRef &c, const GLBufferRef &d)
Preferred constructor, populates all three attachments at once.
Definition: GLScene.hpp:60
uint32_t colorName() const
Returns the name of the buffer/texture to be used as the color attachment (returns 0 if there's no co...
Definition: GLScene.hpp:65
uint32_t program() const
Gets the program ID.
Definition: GLScene.hpp:237
uint32_t fboName() const
Returns the name of the FBO (or 0 if there's no FBO)
Definition: GLScene.hpp:63
GLTexToTexCopierRef privateCopier() const
Gets the receiver's private buffer copier- null by default, only non-null if something called setPriv...
Definition: GLScene.hpp:252
RenderTarget member vars are used to provide attachments for the GL framebuffer. These buffers need t...
Definition: GLScene.hpp:50
GLVersion
This enum is used to describe the GL environment of a GL context, which is determined at runtime...
Definition: VVGL_Base.hpp:94
void setPrivatePool(const GLBufferPoolRef &n)
Sets the receiver's private buffer pool (default is null). If non-null, this buffer pool will be used...
Definition: GLScene.hpp:246
GLBufferPoolRef privatePool() const
Gets the receiver's private buffer pool- null by default, only non-null if something called setPrivat...
Definition: GLScene.hpp:248
uint32_t depthTarget() const
Returns the texture target of the buffer/texture to be used as the depth attachment.
Definition: GLScene.hpp:71
GLVersion glVersion() const
Returns the version of OpenGL currently being used by this scene's GL context.
Definition: GLScene.hpp:243
uint32_t depthName() const
Returns the name of the buffer/texture to be used as the depth attachment (returns 0 if there's no de...
Definition: GLScene.hpp:69
uint32_t colorTarget() const
Returns the texture target of the buffer/texture to be used as the color attachment.
Definition: GLScene.hpp:67