vvopensource
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
VVBufferPool.h
1 #import <Cocoa/Cocoa.h>
2 #import <OpenGL/CGLMacro.h>
3 #import <pthread.h>
4 #import <VVBasics/VVBasics.h>
5 
6 #import "VVBufferPoolStringAdditions.h"
7 #import "VVBuffer.h"
8 #import "VVBufferAggregate.h"
9 #import "VVBufferGLView.h"
10 #import "RenderThread.h"
11 #import "VVSizingTool.h"
12 #import "GLScene.h"
13 #import "GLShaderScene.h"
14 #import "CIGLScene.h"
15 #import "VVQCComposition.h"
16 #import "QCGLScene.h"
17 #import "VVBufferCopier.h"
18 #import "HapSupport.h"
26 extern id _globalVVBufferPool; // retained, nil on launch- this is the "main" buffer pool, used to generate image resources for hardware-accelerated image processing. can't be created automatically, b/c it needs to be based on a shared context.
27 extern int _msaaMaxSamples;
28 extern BOOL _bufferPoolInitialized;
29 extern VVStopwatch *_bufferTimestampMaker;
30 
31 
32 
33 
34 //#define FOURCC(x) ((unsigned long)((*(x+0)<<24) + (*(x+1)<<16) + (*(x+2)<<8) + (*(x+3))))
35 //#define FOURCC(x) ((unsigned long)((*(x+0)) + (*(x+1)<<8) + (*(x+2)<<16) + (*(x+3)<<24)))
36 //#define FOURCC(x) ((x[0]<<24)|(x[1]<<16)|(x[2]<<8)|(x[3]))
37 #define FOURCC_PACK(a,b,c,d) ((unsigned long)((((uint32_t)d)) | (((uint32_t)c)<<8) | (((uint32_t)b)<<16) | (((uint32_t)a)<<24)))
38 
39 
40 
41 
43 
53 @interface VVBufferPool : GLScene {
54  MutLockArray *freeBuffers;
55  pthread_mutex_t contextLock; // makes sure context doesn't get accessed simultaneously on disparate threads
56  VVThreadLoop *housekeepingThread;
57 }
58 
62 + (int) msaaMaxSamples;
63 + (void) setGlobalVVBufferPool:(id)n;
64 
66 
69 + (void) createGlobalVVBufferPoolWithSharedContext:(NSOpenGLContext *)n;
71 + (id) globalVVBufferPool;
73 
76 + (void) timestampThisBuffer:(id)n;
77 
79 - (void) housekeeping;
80 - (void) startHousekeepingThread;
81 - (void) stopHousekeepingThread;
82 
83 // returns a RETAINED (retainCount is 1) instance of VVBuffer! must be explicitly released when done!
84 - (VVBuffer *) allocBufferForDescriptor:(VVBufferDescriptor *)d sized:(NSSize)s backingPtr:(void *)b backingSize:(NSSize)bs;
85 // returns a RETAINED (retainCount is 1) instance of VVBuffer, or nil!
86 - (VVBuffer *) _findFreeBufferMatchingDescriptor:(VVBufferDescriptor *)d sized:(NSSize)s;
87 
88 /* shortcuts for creating resources which are (relatively commonly) used. all these return RETAINED (retainCount is 1) instances of VVBuffer- they must be released manually by whatever creates them! */
90 - (VVBuffer *) allocFBO;
92 - (VVBuffer *) allocBGRTexSized:(NSSize)s;
96 
100 - (VVBuffer *) allocBGR2DPOTTexSized:(NSSize)s;
102 
105 - (VVBuffer *) allocBGRFloatTexSized:(NSSize)s;
107 
110 - (VVBuffer *) allocBGRFloat2DPOTTexSized:(NSSize)s;
112 
115 - (VVBuffer *) allocDepthSized:(NSSize)s;
117 
120 - (VVBuffer *) allocMSAAColorSized:(NSSize)s numOfSamples:(int)n;
122 
125 - (VVBuffer *) allocMSAADepthSized:(NSSize)s numOfSamples:(int)n;
126 
127 
128 - (VVBuffer *) allocBufferForNSImage:(NSImage *)img;
130 
134 - (VVBuffer *) allocBufferForNSImage:(NSImage *)img prefer2DTexture:(BOOL)prefer2D;
135 - (VVBuffer *) allocBufferForBitmapRep:(NSBitmapImageRep *)rep;
137 
141 - (VVBuffer *) allocBufferForBitmapRep:(NSBitmapImageRep *)rep prefer2DTexture:(BOOL)prefer2D;
143 
146 - (VVBuffer *) allocBufferForCVGLTex:(CVOpenGLTextureRef)cvt;
148 
151 #ifndef __LP64__
152 - (VVBuffer *) allocTexRangeForHapCVImageBuffer:(CVImageBufferRef)img;
153 #endif
154 
158 - (VVBuffer *) allocBufferForTexBackedIOSurfaceSized:(NSSize)s;
160 
163 - (VVBuffer *) allocBufferForIOSurfaceID:(IOSurfaceID)n;
164 
165 // DO NOT CALL THIS METHOD MANUALLY- ONLY FROM VVBUFFER'S DEALLOC METHOD
166 // called by instances of VVBuffer if its idleCount is 0 on dealloc
167 - (void) _returnBufferToPool:(VVBuffer *)b;
168 // DO NOT CALL THIS METHOD MANUALLY- ONLY FROM VVBUFFER'S DEALLOC METHOD
169 // called by instances of VVBuffer if its idleCount is > 0 on dealloc
170 - (void) _releaseBufferResource:(VVBuffer *)b;
171 
172 - (void) _lock;
173 - (void) _unlock;
174 
175 
176 @end
177 
178 
179 
180 
181 unsigned long VVPackFourCC_fromChar(char *charPtr);
182 void VVUnpackFourCC_toChar(unsigned long fourCC, char *destCharPtr);
Simple class for spawning a thread which executes at a specified interval- simpler and easier to work...
Definition: VVThreadLoop.h:25
VVBuffer represents a buffer- almost always in VRAM as a GL texture or renderbuffer- created and mana...
Definition: VVBuffer.h:134
Wrapper around a GL context with the intent of standardizing the more common render-to-texture operat...
Definition: GLScene.h:34
Creates VVBuffers. Should be the only way you create VVBuffers- most projects will only have a single...
Definition: VVBufferPool.h:53
This class is used to measure how long it takes to do things; much easier to work with than NSDate...
Definition: VVStopwatch.h:16
Similar to NSMutableArray, but thread-safe. Internally, uses an NSMutableArray and a rwlock...
Definition: MutLockArray.h:20
This C struct describes the basic characteristics of a VVBuffer's internal GL properties.
Definition: VVBuffer.h:83