RSS

(root)/iphone/common : 66 : source/gfx.m

To get this branch, use:
bzr branch /browse/iphone/common

« back to all changes in this revision

Viewing changes to source/gfx.m

Dömötör Gulyás
2010-07-07 13:18:11
Revision ID: dognotdog@gmail.com-20100707111811-v0bkv813ukxe2d7d
adds gfx.h/m from RemoteDriver; extends geometry.h with size scaling, point lerp and rotation

Show diffs side-by-side

added added

removed removed

 
1
//
 
2
//  gfx.m
 
3
//  TestTools
 
4
//
 
5
//  Created by döme on 10.14.08.
 
6
//  Copyright 2008 Doemoetoer Gulyas. All rights reserved.
 
7
//
 
8
 
 
9
#import <OpenGLES/ES2/gl.h>
 
10
#import "gfx.h"
 
11
 
 
12
#define USE_VBOS 1
 
13
/*
 
14
void    _LogGLError(NSString* str)
 
15
{
 
16
        GLenum error = glGetError();
 
17
        if (error != GL_NO_ERROR)
 
18
                NSLog(@"%@: '%s'", str, gluErrorString(error));
 
19
}
 
20
 
 
21
 
 
22
static int _extension_supported(const char *extension)
 
23
{
 
24
    return gluCheckExtension(
 
25
        (const GLubyte *)extension,
 
26
        glGetString(GL_EXTENSIONS));
 
27
}
 
28
*/
 
29
 
 
30
static GLResourceDisposal* _sharedDisposal = nil;
 
31
 
 
32
@implementation GLResourceDisposal
 
33
 
 
34
- (id) init
 
35
{
 
36
        if (!(self = [super init]))
 
37
                return nil;
 
38
        
 
39
        vbos = NULL;
 
40
        fbos = NULL;
 
41
        rbos = NULL;
 
42
        textures = NULL;
 
43
//      programs = calloc(1,1);
 
44
        
 
45
        lock = [[NSRecursiveLock alloc] init]; 
 
46
        
 
47
        return self;
 
48
}
 
49
 
 
50
enum
 
51
{
 
52
        kResourceTypeTexture,
 
53
        kResourceTypeFramebuffer,
 
54
        kResourceTypeVertexbuffer,
 
55
        kResourceTypeRenderbuffer,
 
56
        kResourceTypeShader,
 
57
        kResourceType_
 
58
};
 
59
 
 
60
- (void) disposeOfResourcesWithTypes: (size_t) firstRsrc varArgs: (va_list) argumentList
 
61
{
 
62
        size_t rsrc = firstRsrc;
 
63
        if (rsrc)
 
64
        {
 
65
                [lock lock];
 
66
                do
 
67
                {
 
68
                        size_t type = va_arg(argumentList, size_t);
 
69
                        switch(type)
 
70
                        {
 
71
                                case kResourceTypeTexture:
 
72
                                        textures = realloc(textures, sizeof(*textures)*(numTextures+1));
 
73
                                        textures[numTextures++] = rsrc;
 
74
                                        break;
 
75
                                case kResourceTypeVertexbuffer:
 
76
                                        vbos = realloc(vbos, sizeof(*vbos)*(numVbos+1));
 
77
                                        vbos[numVbos++] = rsrc;
 
78
                                        break;
 
79
                                case kResourceTypeFramebuffer:
 
80
                                        fbos = realloc(fbos, sizeof(*fbos)*(numFbos+1));
 
81
                                        fbos[numFbos++] = rsrc;
 
82
                                        break;
 
83
                                case kResourceTypeRenderbuffer:
 
84
                                        rbos = realloc(rbos, sizeof(*rbos)*(numRbos+1));
 
85
                                        rbos[numRbos++] = rsrc;
 
86
                                        break;
 
87
/*
 
88
                                case kResourceTypeShader:
 
89
                                        programs = realloc(programs, sizeof(*programs)*(numPrograms+1));
 
90
                                        programs[numPrograms++] = (GLhandleARB)rsrc;
 
91
                                        break;
 
92
*/
 
93
                                default:
 
94
                                        assert(0);
 
95
                        }
 
96
                }
 
97
                while ((rsrc = va_arg(argumentList, size_t)));
 
98
 
 
99
                [lock unlock];
 
100
        }
 
101
}
 
102
- (void) performDisposal
 
103
{
 
104
        [lock lock];
 
105
 
 
106
        glDeleteTextures(numTextures, textures);
 
107
        numTextures = 0;
 
108
        
 
109
        glDeleteFramebuffers(numFbos, fbos);
 
110
        numFbos = 0;
 
111
 
 
112
        glDeleteRenderbuffers(numRbos, rbos);
 
113
        numRbos = 0;
 
114
 
 
115
        glDeleteBuffers(numVbos, vbos);
 
116
        numVbos = 0;
 
117
 
 
118
/*
 
119
        for (size_t i = 0; i < numPrograms; ++i)
 
120
                glDeleteObjectARB(programs[i]);
 
121
        numPrograms = 0;
 
122
*/
 
123
 
 
124
        [lock unlock];
 
125
}
 
126
 
 
127
+ (void) performDisposal
 
128
{
 
129
        if (!_sharedDisposal)
 
130
        {
 
131
                _sharedDisposal = [[GLResourceDisposal alloc] init];
 
132
        }
 
133
        [_sharedDisposal performDisposal];
 
134
}
 
135
 
 
136
+ (void) disposeOfResourcesWithTypes: (size_t) firstRsrc, ...
 
137
{
 
138
        if (!_sharedDisposal)
 
139
        {
 
140
                _sharedDisposal = [[GLResourceDisposal alloc] init];
 
141
        }
 
142
        if (firstRsrc)
 
143
        {
 
144
                va_list argumentList;
 
145
                va_start(argumentList, firstRsrc);
 
146
                [_sharedDisposal disposeOfResourcesWithTypes: firstRsrc varArgs: argumentList];
 
147
                va_end(argumentList);
 
148
        }
 
149
}
 
150
 
 
151
 
 
152
@end
 
153
 
 
154
 
 
155
 
 
156
 
 
157
 

Loggerhead 1.17 is a web-based interface for Bazaar branches