This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
glDisplayList.c
220 lines (188 loc) · 5.9 KB
/
glDisplayList.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// functions dealing with display lists
#include "pspgl_internal.h"
//GLint __pspgl_is_in_glNewList = 0; // equal 1 if we are in glNewList / glEndList
//GLint __pspgl_nblists = 0; // number of lists
//GLuint __pspgl_calllists_base = 0; // display-list base for glCallLists
struct stDisplayLists *__pspgl_displaylists; // where Display lists will be stored
struct stDisplayLists *__pspgl_actuallist; // display list opened with glNewList
// functions' array
void __pspglBegin(struct stDisplayElement *de) {
glBegin(de->parami1);
}
void __pspglEnd(struct stDisplayElement *de) {
glEnd();
}
void __pspglTexCoord(struct stDisplayElement *de) {
glTexCoord4f(de->paramf1, de->paramf2, de->paramf3, de->paramf4);
}
void __pspglVertex(struct stDisplayElement *de){
glVertex3f(de->paramf1, de->paramf2, de->paramf3);
}
void __pspglColor(struct stDisplayElement *de){
__pspgl_update_color(de->parami1);
}
void __pspglEnable(struct stDisplayElement *de){
__pspgl_enable_state (de->parami1, de->parami2);
}
void __pspglTranslate(struct stDisplayElement *de){
glTranslatef (de->paramf1, de->paramf2, de->paramf3);
}
void (*__pspglFunctionToCall[])(struct stDisplayElement *de) = {
__pspglBegin, __pspglEnd, __pspglTexCoord, __pspglVertex, __pspglColor,
__pspglEnable, __pspglTranslate
};
// external functions for display list
GLAPI GLboolean GLAPIENTRY glIsList( GLuint list )
{
if (list < pspgl_curctx->displaylists.nblists)
return __pspgl_displaylists[list].is_used;
else
return GL_FALSE;
}
GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range )
{
int i;
struct stDisplayElement *curr, *temp;
for(i=list; i < (list+range); i++) {
curr = __pspgl_displaylists[i].first;
while (curr){
temp = curr;
curr = curr->next;
free(temp);
}
__pspgl_displaylists[i].is_used = GL_FALSE;
__pspgl_displaylists[i].first = NULL;
__pspgl_displaylists[i].last = NULL;
}
}
GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range )
{
int lastnblists;
int i;
lastnblists = pspgl_curctx->displaylists.nblists;
pspgl_curctx->displaylists.nblists += range;
if (lastnblists) // if display lists are existing
__pspgl_displaylists = realloc (__pspgl_displaylists, pspgl_curctx->displaylists.nblists * sizeof(struct stDisplayLists) );
else
__pspgl_displaylists = malloc (sizeof(struct stDisplayLists) * pspgl_curctx->displaylists.nblists);
// init new lists
for (i=lastnblists; i< pspgl_curctx->displaylists.nblists; i++){
__pspgl_displaylists[i].is_used = GL_FALSE;
__pspgl_displaylists[i].first = NULL;
__pspgl_displaylists[i].last = NULL;
}
return lastnblists;
}
GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode )
{
if (list < pspgl_curctx->displaylists.nblists){ // verif if "list" is in displaylists range...
if (__pspgl_displaylists[list].is_used != GL_FALSE) // use it only if free !
return;
}
else { // ...else create it
glGenLists(1);
}
__pspgl_actuallist = &__pspgl_displaylists[list];
__pspgl_actuallist->is_used = GL_TRUE;
pspgl_curctx->displaylists.is_in_glNewList = mode;
pspgl_curctx->displaylists.index = list;
}
GLAPI void GLAPIENTRY glEndList( void )
{
pspgl_curctx->displaylists.is_in_glNewList = 0;
__pspgl_actuallist = NULL;
pspgl_curctx->displaylists.index = 0;
}
GLAPI void GLAPIENTRY glCallList( GLuint list )
{
struct stDisplayElement *curr;
curr = __pspgl_displaylists[list].first;
while (curr){
(__pspglFunctionToCall[curr->command_num])(curr);
curr = curr->next;
}
}
/*
* Translate the nth element of list from type to GLuint.
* used by glCallLists
*/
static GLuint __pspglTranslate_id( GLsizei n, GLenum type, const GLvoid *list )
{
GLbyte *bptr;
GLubyte *ubptr;
GLshort *sptr;
GLushort *usptr;
GLint *iptr;
GLuint *uiptr;
GLfloat *fptr;
switch (type) {
case GL_BYTE:
bptr = (GLbyte *) list;
return (GLuint) *(bptr+n);
case GL_UNSIGNED_BYTE:
ubptr = (GLubyte *) list;
return (GLuint) *(ubptr+n);
case GL_SHORT:
sptr = (GLshort *) list;
return (GLuint) *(sptr+n);
case GL_UNSIGNED_SHORT:
usptr = (GLushort *) list;
return (GLuint) *(usptr+n);
case GL_INT:
iptr = (GLint *) list;
return (GLuint) *(iptr+n);
case GL_UNSIGNED_INT:
uiptr = (GLuint *) list;
return (GLuint) *(uiptr+n);
case GL_FLOAT:
fptr = (GLfloat *) list;
return (GLuint) *(fptr+n);
case GL_2_BYTES:
ubptr = ((GLubyte *) list) + 2*n;
return (GLuint) *ubptr * 256 + (GLuint) *(ubptr+1);
case GL_3_BYTES:
ubptr = ((GLubyte *) list) + 3*n;
return (GLuint) *ubptr * 65536
+ (GLuint) *(ubptr+1) * 256
+ (GLuint) *(ubptr+2);
case GL_4_BYTES:
ubptr = ((GLubyte *) list) + 4*n;
return (GLuint) *ubptr * 16777216
+ (GLuint) *(ubptr+1) * 65536
+ (GLuint) *(ubptr+2) * 256
+ (GLuint) *(ubptr+3);
default:
return 0;
}
}
GLAPI void GLAPIENTRY glCallLists( GLsizei n, GLenum type,
const GLvoid *lists )
{
GLint i;
switch (type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FLOAT:
case GL_2_BYTES:
case GL_3_BYTES:
case GL_4_BYTES:
break;
default:
type = GL_UNSIGNED_BYTE;
}
for (i=0;i<n;i++) {
// transform array element in GLuint
GLuint list = __pspglTranslate_id( i, type, lists );
list += pspgl_curctx->displaylists.calllists_base; // display-list base for glCallLists
// Call the right list
glCallList(list);
}
}
GLAPI void GLAPIENTRY glListBase( GLuint base )
{
pspgl_curctx->displaylists.calllists_base = base; // display-list base for glCallLists
}