5
// Created by döme on 10.14.08.
6
// Copyright 2008 Doemoetoer Gulyas. All rights reserved.
9
#import <OpenGLES/ES2/gl.h>
14
void _LogGLError(NSString* str)
16
GLenum error = glGetError();
17
if (error != GL_NO_ERROR)
18
NSLog(@"%@: '%s'", str, gluErrorString(error));
22
static int _extension_supported(const char *extension)
24
return gluCheckExtension(
25
(const GLubyte *)extension,
26
glGetString(GL_EXTENSIONS));
30
static GLResourceDisposal* _sharedDisposal = nil;
32
@implementation GLResourceDisposal
36
if (!(self = [super init]))
43
// programs = calloc(1,1);
45
lock = [[NSRecursiveLock alloc] init];
53
kResourceTypeFramebuffer,
54
kResourceTypeVertexbuffer,
55
kResourceTypeRenderbuffer,
60
- (void) disposeOfResourcesWithTypes: (size_t) firstRsrc varArgs: (va_list) argumentList
62
size_t rsrc = firstRsrc;
68
size_t type = va_arg(argumentList, size_t);
71
case kResourceTypeTexture:
72
textures = realloc(textures, sizeof(*textures)*(numTextures+1));
73
textures[numTextures++] = rsrc;
75
case kResourceTypeVertexbuffer:
76
vbos = realloc(vbos, sizeof(*vbos)*(numVbos+1));
77
vbos[numVbos++] = rsrc;
79
case kResourceTypeFramebuffer:
80
fbos = realloc(fbos, sizeof(*fbos)*(numFbos+1));
81
fbos[numFbos++] = rsrc;
83
case kResourceTypeRenderbuffer:
84
rbos = realloc(rbos, sizeof(*rbos)*(numRbos+1));
85
rbos[numRbos++] = rsrc;
88
case kResourceTypeShader:
89
programs = realloc(programs, sizeof(*programs)*(numPrograms+1));
90
programs[numPrograms++] = (GLhandleARB)rsrc;
97
while ((rsrc = va_arg(argumentList, size_t)));
102
- (void) performDisposal
106
glDeleteTextures(numTextures, textures);
109
glDeleteFramebuffers(numFbos, fbos);
112
glDeleteRenderbuffers(numRbos, rbos);
115
glDeleteBuffers(numVbos, vbos);
119
for (size_t i = 0; i < numPrograms; ++i)
120
glDeleteObjectARB(programs[i]);
127
+ (void) performDisposal
129
if (!_sharedDisposal)
131
_sharedDisposal = [[GLResourceDisposal alloc] init];
133
[_sharedDisposal performDisposal];
136
+ (void) disposeOfResourcesWithTypes: (size_t) firstRsrc, ...
138
if (!_sharedDisposal)
140
_sharedDisposal = [[GLResourceDisposal alloc] init];
144
va_list argumentList;
145
va_start(argumentList, firstRsrc);
146
[_sharedDisposal disposeOfResourcesWithTypes: firstRsrc varArgs: argumentList];
147
va_end(argumentList);