vvopensource
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
VVBuffer.h
Go to the documentation of this file.
1 
6 #import <Cocoa/Cocoa.h>
7 #import <OpenGL/CGLMacro.h>
8 #import <CoreVideo/CoreVideo.h>
9 #import <IOSurface/IOSurface.h>
10 
11 
12 
14 typedef enum _VVBufferType {
19  VVBufferType_PBO, // PBO
20  VVBufferType_VBO, // VBO
21  VVBufferType_DispList, // display list
22 } VVBufferType;
24 typedef enum _VVBufferIntFormat {
26  VVBufferIF_Lum8 = GL_LUMINANCE8,
27  VVBufferIF_LumFloat = GL_LUMINANCE32F_ARB,
28  VVBufferIF_R = GL_RED,
29  VVBufferIF_RGB = GL_RGB,
30  VVBufferIF_RGBA = GL_RGBA,
31  VVBufferIF_RGBA8 = GL_RGBA8,
32  VVBufferIF_Depth24 = GL_DEPTH_COMPONENT24,
33  VVBufferIF_RGBA32F = GL_RGBA32F_ARB,
34  VVBufferIF_RGB_DXT1 = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
35  VVBufferIF_RGBA_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
36  VVBufferIF_YCoCg_DXT5 = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
39 typedef enum _VVBufferPixFormat {
41  VVBufferPF_Depth = GL_DEPTH_COMPONENT,
42  VVBufferPF_Lum = GL_LUMINANCE,
43  VVBufferPF_R = GL_RED,
44  VVBufferPF_RGBA = GL_RGBA,
45  VVBufferPF_BGRA = GL_BGRA,
46  VVBufferPF_YCBCR_422 = GL_YCBCR_422_APPLE,
49 typedef enum _VVBufferPixType {
51  VVBufferPT_Float = GL_FLOAT,
52  VVBufferPT_U_Byte = GL_UNSIGNED_BYTE,
53  VVBufferPT_U_Int_8888_Rev = GL_UNSIGNED_INT_8_8_8_8_REV,
54  VVBufferPT_U_Short_88 = GL_UNSIGNED_SHORT_8_8_APPLE,
57 typedef enum _VVBufferCPUBack {
63 typedef enum _VVBufferGPUBack {
69 
72 typedef enum _VVBufferBackID {
74  VVBufferBackID_GWorld, //< the buffer was created from a gworld
83 typedef struct _VVBufferDescriptor {
85  GLuint target;
91  GLuint name;
92  BOOL texRangeFlag;
94  GLuint msAmount;
95  unsigned long localSurfaceID;
97 
98 
99 
100 
111 
112 
113 
114 
116 
120 typedef void (*VVBufferBackingReleaseCallback)(id VVBufferBeingFreed, void *callbackContext);
127 
134 @interface VVBuffer : NSObject <NSCopying> {
135  VVBufferDescriptor descriptor; // struct that describes the GL resource this instance of VVBuffer represents
136 
137  BOOL preferDeletion; // NO by default. if YES, this instance will be freed immediately (rather than put back in a pool). note that some resources will be freed immediately no matter what- even if this is NO!
138  NSSize size; // the dimensions of the GL resource, expressed in pixels (even if it's a 2D texture- this is pixel-based!)
139  NSRect srcRect; // rect describing the area of this buffer to use. again, always pixel-based, even when the target is GL_TEXTURE_2D.
140  BOOL flipped; // if YES, the area described by "srcRect" should be flipped vertically before display
141  NSSize backingSize; // sometimes, the backing has a different size (gworlds backing compressed textures)
142  GLfloat *auxTransMatrix; // "retained", nil by default. sometimes it's convenient to store transform matrices necessary to do scaling/translation/perspective distortion with the buffers that use them.
143  GLfloat auxOpacity; // like "auxTransMatrix", sometimes it's convenient to store an auxiliary "opacity" value. this opacity value isn't reflected by the contents of this VVBuffer- rather, it's intended to store a value for later application to this buffer.
144  struct timeval contentTimestamp; // set by the buffer pool's class method. this variable is *NOT* set automatically- its use is entirely optional and up to the implementation
145  id userInfo; // RETAINED, nil by default. not used by this class- stick whatever you want here and it will be retained for the lifetime of this buffer. retained if you copy the buffer!
146 
147  VVBufferBackID backingID; // totally optional, used to describe where the backing came from. sometimes you want to know what kind of backing a VVBuffer has, and access it. there's an enum describing some of the more common sources, and you can define and use your own values here.
148  void *cpuBackingPtr; // weak ref, only non-nil if there's a cpu backing for the GL resource. ptr to the raw pixel data (this ptr is passed to GL upload/download functions)
149 
150  /* this callback and callback context are used when the VVBuffer and its resources need to be freed. these can be used to quickly and easily add support for other image processing frameworks (using VVBuffer to wrap opaque image types) */
151  VVBufferBackingReleaseCallback backingReleaseCallback; // this function is called when the image resources need to be released
152  void *backingReleaseCallbackContext; // weak ref. this is an arbitrary data pointer that is stored with a buffer for use with the buffer release callback
153 
154  /* if this instance of VVBuffer has a corresponding IOSurfaceRef, it's retained here. these will always be valid- even if you copy a VVBuffer. */
155  IOSurfaceRef localSurfaceRef; // RETAINED, nil by default. the "local" surface ref was created by this process.
156  IOSurfaceRef remoteSurfaceRef; // RETAINED, nil by default. the "remote" surface ref was created by another process (so this should probably be released immediately).
157 
158  /* these variables pertain to the buffer in its pool- idle counts, the original buffer for this resource (in the case of copied buffers), that sort of thing. */
159  id parentBufferPool; // RETAINED! the pool exists until all its buffers are gone!
160  id copySourceBuffer; // RETAINED, nil by default. if you copy a VVBuffer using the NSCopying protocol, the original buffer is retained here (so the underlying resources don't get freed until all VVBuffer instances referring to them get freed).
161  int idleCount; // when a buffer's in a pool waiting to be re-used, its idleCount is incremented- if it gets high enough, the buffer is actually freed and its resources released
162 }
163 
164 + (id) createWithPool:(id)p;
165 - (id) initWithPool:(id)p;
166 
168 - (VVBufferDescriptor *) descriptorPtr;
169 - (void) setDescriptorFromPtr:(VVBufferDescriptor *)n;
170 @property (assign, readwrite) BOOL preferDeletion;
172 @property (readonly) NSSize size;
173 - (void) setSize:(NSSize)n;
175 @property (assign, readwrite) NSRect srcRect;
177 @property (assign, readwrite) BOOL flipped;
179 @property (assign, readwrite) NSSize backingSize;
181 - (struct timeval *) contentTimestampPtr;
183 - (void) getContentTimestamp:(struct timeval *)n;
184 - (void) setContentTimestampFromPtr:(struct timeval *)n;
186 - (void) setUserInfo:(id)n;
188 - (id) userInfo;
189 - (void) setAuxTransMatrix:(GLfloat *)n;
190 - (GLfloat *) auxTransMatrix;
191 @property (assign, readwrite) GLfloat auxOpacity;
193 @property (readonly) NSRect normalizedSrcRect;
195 @property (readonly) NSRect glReadySrcRect;
197 
202 - (NSRect) srcRectCroppedWith:(NSRect)cropRect takingFlipIntoAccount:(BOOL)f;
204 @property (readonly) BOOL isFullFrame;
206 @property (readonly) GLuint name;
208 @property (readonly) GLuint target;
210 @property (readonly) BOOL safeToPublishToSyphon;
212 - (BOOL) isContentMatchToBuffer:(VVBuffer *)n;
213 
214 - (GLuint *) pixels;
216 - (CVPixelBufferRef) cvPixBuf;
218 - (CVOpenGLTextureRef) cvTexRef;
220 - (NSBitmapImageRep *) bitmapRep;
221 - (void *) externalBacking;
222 #ifndef __LP64__
223 - (GWorldPtr) gWorld;
224 #endif
225 
227 @property (assign,readwrite) VVBufferBackID backingID;
228 - (void) setCpuBackingPtr:(void *)n;
230 - (void *) cpuBackingPtr;
232 
235 - (void) setBackingReleaseCallback:(VVBufferBackingReleaseCallback)n;
236 - (VVBufferBackingReleaseCallback) backingReleaseCallback;
238 
241 - (void) setBackingReleaseCallbackContext:(void *)n;
242 - (void *) backingReleaseCallbackContext;
244 - (IOSurfaceRef) localSurfaceRef;
245 - (void) setLocalSurfaceRef:(IOSurfaceRef)n;
246 - (IOSurfaceRef) remoteSurfaceRef;
247 - (void) setRemoteSurfaceRef:(IOSurfaceRef)n;
248 
249 @property (retain,readwrite) id copySourceBuffer;
250 @property (assign,readwrite) int idleCount;
251 - (void) _incrementIdleCount;
252 
253 
254 @end
255 
256 
257 
258 
259 void VVBuffer_ReleasePixelsCallback(id b, void *c);
260 void VVBuffer_ReleaseCVGLT(id b, void *c);
261 void VVBuffer_ReleaseCVPixBuf(id b, void *c);
262 void VVBuffer_ReleaseBitmapRep(id b, void *c);
263 #ifndef __LP64__
264 void VVBuffer_ReleaseGWorld(id b, void *c);
265 #endif
unsigned long VVBufferDescriptorCalculateCPUBackingForSize(VVBufferDescriptor *b, NSSize s)
Calculates the size (in bytes) that would be required to create a CPU-based backing for a buffer of t...
Definition: VVBuffer.m:91
BOOL VVBufferDescriptorCompareForRecycling(VVBufferDescriptor *a, VVBufferDescriptor *b)
Compares the passed buffers for the purpose of recycling, returns a YES if they are close enough of a...
Definition: VVBuffer.m:61
GLuint msAmount
the number of multisamples (where appropriate- only applies to renderbuffers- 0 by default) ...
Definition: VVBuffer.h:94
depth
Definition: VVBuffer.h:41
float- used for rendering high-precision stuff
Definition: VVBuffer.h:51
the buffer was wholly created by this framework- there's no backing
Definition: VVBuffer.h:73
standard four channel/8 bits per channel/unsigned byte format. fast on os x, (probably most common) ...
Definition: VVBuffer.h:53
VVBufferGPUBack gpuBackingType
the GPU backing type
Definition: VVBuffer.h:90
VVBufferType type
what kind of buffer (what kind of GL resource) this holds
Definition: VVBuffer.h:84
renderbuffer
Definition: VVBuffer.h:16
none/unknown/unused
Definition: VVBuffer.h:50
the GPU-based resource was created outside of this framework, and this buffer should be freed immedia...
Definition: VVBuffer.h:66
three channel, 8 bit per channel
Definition: VVBuffer.h:29
unsigned long localSurfaceID
if 0, the buffer doesn't have an associated IOSurfaceRef; otherwise the surfaceID of the local surfac...
Definition: VVBuffer.h:95
void VVBufferDescriptorPopulateDefault(VVBufferDescriptor *d)
Populates the passed VVBufferDescriptor pointer with default values.
Definition: VVBuffer.m:7
four channel, 32 bit per channel
Definition: VVBuffer.h:33
enum _VVBufferBackID VVBufferBackID
The "VVBufferBackID" is an arbitrary enum that isn't used functionally by this framework. This enum- and VVBuffer's corresponding "backingID" member- exist to help track where a VVBuffer came from (if it was made from pixels, from another object, etc).
single channel, 8 bit per pixel
Definition: VVBuffer.h:26
BGRA. faston os x, (probably most common)
Definition: VVBuffer.h:45
there is no GPU-based resource
Definition: VVBuffer.h:64
the buffer was created from some kind of external pointer passed in from another API (this can be use...
Definition: VVBuffer.h:80
_VVBufferType
These are the different kinds of VVBuffers.
Definition: VVBuffer.h:14
there is no CPU-based backing
Definition: VVBuffer.h:58
void * cpuBackingPtr()
If a VVBuffer was created from a CPU-based resource, this will always return a ptr to the raw pixels ...
Definition: VVBuffer.m:485
two channel/8 bits per channel/unsigned byte format. usually used for YCbCr textures.
Definition: VVBuffer.h:54
id userInfo()
Returns the buffer's "userInfo" (if there is one).
Definition: VVBuffer.m:360
_VVBufferGPUBack
The origin of any GPU-based content.
Definition: VVBuffer.h:63
enum _VVBufferType VVBufferType
These are the different kinds of VVBuffers.
NSSize size
This returns the size of the underlying GL resource. The value returned by this method is always usin...
Definition: VVBuffer.h:138
VVBuffer represents a buffer- almost always in VRAM as a GL texture or renderbuffer- created and mana...
Definition: VVBuffer.h:134
none/unknown/unused
Definition: VVBuffer.h:15
depth- single channel, 24 bit per pixel
Definition: VVBuffer.h:32
the buffer was created from an NSBitmapImageRep
Definition: VVBuffer.h:78
struct _VVBufferDescriptor VVBufferDescriptor
This C struct describes the basic characteristics of a VVBuffer's internal GL properties.
enum _VVBufferPixType VVBufferPixType
This describes the pixel type of the GL resource represented by a VVBuffer.
IOSurfaceRef localSurfaceRef()
If the receiver is a GL texture backed by an IOSurfaceRef, this returns the IOSurfaceRef. If you want to send a texture to another process, you want to call -[VVBufferPool allocBufferForTexBackedIOSurfaceSized:], render into the returned buffer, and then call "localSurfaceRef" to retrieve the IOSurface to be sent to another process.
Definition: VVBuffer.m:488
none/unknown/unused
Definition: VVBuffer.h:25
VVBufferPixType pixelType
the type of data in the pixel format; usually U_Int_8888_Rev
Definition: VVBuffer.h:88
four channel, 8 bit per channel. fast on os x, probably most common)
Definition: VVBuffer.h:31
the buffer was created from a CVOpenGLTextureRef
Definition: VVBuffer.h:77
FBO.
Definition: VVBuffer.h:17
BOOL texClientStorageFlag
if YES, the texture was created with GL_UNPACK_CLIENT_STORAGE_APPLE set to TRUE: this will prevent Op...
Definition: VVBuffer.h:93
GLuint name
the actual name (identifier) of GL resource this holds
Definition: VVBuffer.h:91
packed YCbCr
Definition: VVBuffer.h:46
four channel, 8 bit per channel
Definition: VVBuffer.h:30
NSSize backingSize
If the buffer has some kind of backing, these are its dimensions. Stored here as a different size to ...
Definition: VVBuffer.h:141
BOOL texRangeFlag
if YES, it's a texture range (where appropriate)
Definition: VVBuffer.h:92
enum _VVBufferCPUBack VVBufferCPUBack
The origin of any CPU-based content.
BOOL flipped
Whether or not the image represented by this buffer is flipped vertically. Like "srcRect", it's safe and quick to both set and get this value- changing it does not cause any graphic operatings to occur, the value is only used when you want to do something with this VVBuffer.
Definition: VVBuffer.h:140
RGBA.
Definition: VVBuffer.h:44
buffer backing is CPU-based, and the CPU resource was created by this framework
Definition: VVBuffer.h:59
_VVBufferIntFormat
This desribes the internal format of the GL resource represented by a VVBuffer.
Definition: VVBuffer.h:24
VVBufferIntFormat internalFormat
the format in which the pixel data is stored in opengl; usually RGBA8
Definition: VVBuffer.h:86
single channel, 32 bit float per pixel
Definition: VVBuffer.h:27
luminance
Definition: VVBuffer.h:42
VVBufferPixFormat pixelFormat
the pixel format; usually BGRA
Definition: VVBuffer.h:87
NSRect srcRect
The "srcRect" is the region of the GL resource that contains an image- this value is always measured ...
Definition: VVBuffer.h:139
usually used for depth buffer/luminance/single-channel stuff
Definition: VVBuffer.h:52
enum _VVBufferGPUBack VVBufferGPUBack
The origin of any GPU-based content.
BOOL VVBufferDescriptorCompare(VVBufferDescriptor *a, VVBufferDescriptor *b)
Compares the passed buffers, returns a YES if they are completely identical.
Definition: VVBuffer.m:41
enum _VVBufferIntFormat VVBufferIntFormat
This desribes the internal format of the GL resource represented by a VVBuffer.
single channel, 8 bit per pixel
Definition: VVBuffer.h:28
VVBufferCPUBack cpuBackingType
the CPU backing type
Definition: VVBuffer.h:89
enum _VVBufferPixFormat VVBufferPixFormat
This describes the pixel format of the GL resource represented by a VVBuffer.
void(* VVBufferBackingReleaseCallback)(id VVBufferBeingFreed, void *callbackContext)
This is a function pointer- it gets called when the VVBuffer that owns it is being deallocated and ne...
Definition: VVBuffer.h:120
the buffer was created from a CVPixelBufferRef
Definition: VVBuffer.h:76
the buffer was created from a pointer to pixels which were also allocated by this framework ...
Definition: VVBuffer.h:75
non/unknown/unused
Definition: VVBuffer.h:40
GLuint target
GL_TEXTURE_RECTANGLE_EXT by default, sometimes GL_TEXTURE_2D or GL_RENDERBUFFER_EXT. 0 if not used.
Definition: VVBuffer.h:85
_VVBufferPixType
This describes the pixel type of the GL resource represented by a VVBuffer.
Definition: VVBuffer.h:49
_VVBufferBackID
The "VVBufferBackID" is an arbitrary enum that isn't used functionally by this framework. This enum- and VVBuffer's corresponding "backingID" member- exist to help track where a VVBuffer came from (if it was made from pixels, from another object, etc).
Definition: VVBuffer.h:72
texture (probably most common)
Definition: VVBuffer.h:18
void VVBufferDescriptorCopy(VVBufferDescriptor *src, VVBufferDescriptor *dst)
Copies the contents of the src to dst.
Definition: VVBuffer.m:24
_VVBufferPixFormat
This describes the pixel format of the GL resource represented by a VVBuffer.
Definition: VVBuffer.h:39
buffer backing is CPU-based, and the CPU resource was created outside this framework ...
Definition: VVBuffer.h:60
_VVBufferCPUBack
The origin of any CPU-based content.
Definition: VVBuffer.h:57
Hap.
Definition: VVBuffer.h:34
the GPU-based resource was created by this framework (and should be deleted by this framework) ...
Definition: VVBuffer.h:65
VVBufferBackID backingID
The VVBufferBackID doesn't play a functional role in the processing of VVBuffer- it's an enum that ex...
Definition: VVBuffer.h:147
the buffer was created from an remote IOSurfaceRef (the IOSurface was generated in another process) ...
Definition: VVBuffer.h:79
Hap Alpha.
Definition: VVBuffer.h:35
HapQ. not a typo, same as RGBA_DXT5!
Definition: VVBuffer.h:36
This C struct describes the basic characteristics of a VVBuffer's internal GL properties.
Definition: VVBuffer.h:83
red (same idea as luminance, just seems to be slightly more compatible with stuff) ...
Definition: VVBuffer.h:43