vvopensource
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
GLScene.h
1 #import <Cocoa/Cocoa.h>
2 #import <OpenGL/OpenGL.h>
3 #import <OpenGL/CGLMacro.h>
4 #import <VVBasics/VVBasics.h>
5 #import "VVBuffer.h"
6 
7 
8 
9 
10 extern OSSpinLock _glSceneStatLock;
11 extern NSMutableArray *_gpuVendorArray;
12 extern BOOL _integratedGPUFlag; // whether or not the scene is rendering on an integrated GPU
13 extern BOOL _nvidiaGPUFlag; // whether or not the scene is rendering on an NVIDIA GPU
14 
15 typedef enum {
16  VVGLFlushModeGL = 0, // glFlush()
17  VVGLFlushModeCGL = 1, // CGLFlushDrawable()
18  VVGLFlushModeNS = 2, // [context flushBuffer]
19  VVGLFlushModeApple = 3, // glFlushRenderAPPLE()
20  VVGLFlushModeFinish = 4 // glFinish()
21 } VVGLFlushMode;
22 
23 
24 
26 
34 @interface GLScene : NSObject {
35  BOOL deleted;
36  BOOL initialized;
37  BOOL needsReshape;
38  OSSpinLock renderThreadLock; // used to serialize access to "renderThreadDeleteArray", making it thread-safe
39  MutLockArray *renderThreadDeleteArray; // NOT RETAINED! weak ref to an array you can add items to such that the items will be released on the thread that renders the scene. useful if you need to ensure that rendering resources are released on the same thread that did the rendering. only non-nil if this scene is being rendered on a thread created by a RenderThread class
40 
41  NSOpenGLContext *sharedContext; // NOT retained! weak ref to the shared context, which is assumed to be retained elsewhere.
42  NSOpenGLContext *context; // RETAINED- the context i render into!
43  NSOpenGLPixelFormat *customPixelFormat; // the pixel format used by my context
44  CGColorSpaceRef colorSpace;
45 
46  id renderTarget; // NOT RETAINED- the target of my render method
47  SEL renderSelector; // this method gets called when i render; ONLY does the actual drawing- does NOT do setup/cleanup (use _renderPrep and _renderCleanup)!
48 
49  GLuint fbo; // the framebuffer my context renders into- only valid when the render method is called!
50  GLuint tex; // the fbo renders into this texture- only valid when the render method is called!
51  GLuint texTarget; // either GL_TEXTURE_RECTANGLE_EXT or GL_TEXTURE_2D. both 'tex' and 'depth' much be using this target!
52  GLuint depth; // the depth buffer for context- only valid when the render method is called!
53 
54  GLuint fboMSAA; // this fbo has renderbuffers which support MSAA attached to it- only valid when the render method is called!
55  GLuint colorMSAA; // the color renderbuffer attached to the msaa fbo- only valid when the render method is called!
56  GLuint depthMSAA; // the depth renderbuffer attached to the msaa fbo- only valid when the render method is called!
57 
58  NSSize size; // the size of the this scene/the texture/framebuffer/viewport/etc
59  BOOL flipped; // whether or not the context renders upside-down. NO by default, but some subclasses just render upside-down...
60 
61  BOOL performClear;
62  GLfloat clearColor[4];
63  BOOL clearColorUpdated;
64  VVGLFlushMode flushMode; // 0=glFlush(), 1=CGLFlushDrawable(), 2=[context flushBuffer]
65  int swapInterval;
66 }
67 
69 + (NSMutableArray *) gpuVendorArray;
71 + (BOOL) integratedGPUFlag;
73 + (BOOL) nvidiaGPUFlag;
75 + (GLuint) glDisplayMaskForAllScreens;
77 + (NSOpenGLPixelFormat *) defaultPixelFormat;
78 + (NSOpenGLPixelFormat *) doubleBufferPixelFormat;
79 + (NSOpenGLPixelFormat *) defaultQTPixelFormat;
80 + (NSOpenGLPixelFormat *) fsaaPixelFormat;
81 + (NSOpenGLPixelFormat *) doubleBufferFSAAPixelFormat;
82 
84 - (id) initWithSharedContext:(NSOpenGLContext *)c;
86 - (id) initWithSharedContext:(NSOpenGLContext *)c sized:(NSSize)s;
88 - (id) initWithSharedContext:(NSOpenGLContext *)c pixelFormat:(NSOpenGLPixelFormat *)p;
90 - (id) initWithSharedContext:(NSOpenGLContext *)c pixelFormat:(NSOpenGLPixelFormat *)p sized:(NSSize)s;
91 - (void) prepareToBeDeleted;
92 
94 - (VVBuffer *) allocAndRenderABuffer;
95 - (void) render;
96 - (void) renderInFBO:(GLuint)f colorTex:(GLuint)t depthTex:(GLuint)d;
97 - (void) renderInMSAAFBO:(GLuint)mf colorRB:(GLuint)mc depthRB:(GLuint)md fbo:(GLuint)f colorTex:(GLuint)t depthTex:(GLuint)d;
99 
108 - (void) renderInMSAAFBO:(GLuint)mf colorRB:(GLuint)mc depthRB:(GLuint)md fbo:(GLuint)f colorTex:(GLuint)t depthTex:(GLuint)d target:(GLuint)texTarget;
109 - (void) renderBlackFrameInFBO:(GLuint)f colorTex:(GLuint)t target:(GLuint)tt;
110 - (void) renderOpaqueBlackFrameInFBO:(GLuint)f colorTex:(GLuint)t target:(GLuint)tt;
111 - (void) renderRedFrameInFBO:(GLuint)f colorTex:(GLuint)t target:(GLuint)tt;
112 - (void) _renderPrep;
113 - (void) _initialize;
114 - (void) _reshape;
115 - (void) _renderCleanup;
116 
117 - (NSOpenGLContext *) sharedContext;
118 - (NSOpenGLContext *) context;
119 - (CGLContextObj) CGLContextObj;
120 - (NSOpenGLPixelFormat *) customPixelFormat;
121 - (CGColorSpaceRef) colorSpace;
123 @property (assign,readwrite) NSSize size;
124 - (void) setFlipped:(BOOL)n;
125 - (BOOL) flipped;
126 
127 - (void) setPerformClear:(BOOL)n;
129 - (void) setClearNSColor:(NSColor *)c;
131 - (void) setClearColor:(GLfloat *)c;
133 - (void) setClearColors:(GLfloat)r :(GLfloat)g :(GLfloat)b :(GLfloat)a;
134 
135 @property (assign,readwrite) BOOL initialized;
137 @property (assign, readwrite) id renderTarget;
139 @property (assign, readwrite) SEL renderSelector;
140 @property (assign, readwrite) VVGLFlushMode flushMode;
141 @property (assign, readwrite) int swapInterval;
142 
143 @end
SEL renderSelector
Every time this scene renders, the "renderSelector" is called on "renderTarget". You put your drawing...
Definition: GLScene.h:47
VVBuffer represents a buffer- almost always in VRAM as a GL texture or renderbuffer- created and mana...
Definition: VVBuffer.h:134
NSSize size
Set the size at which this scene should render.
Definition: GLScene.h:58
Wrapper around a GL context with the intent of standardizing the more common render-to-texture operat...
Definition: GLScene.h:34
id renderTarget
Every time this scene renders, the "renderSelector" is called on "renderTarget".
Definition: GLScene.h:46
Similar to NSMutableArray, but thread-safe. Internally, uses an NSMutableArray and a rwlock...
Definition: MutLockArray.h:20