forked from jsgf/pspgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glArrayElement.c
98 lines (76 loc) · 1.92 KB
/
glArrayElement.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
#include "pspgl_internal.h"
#include "pspgl_buffers.h"
static const
GLfloat scale_factor [] = {
1.0f/127.0f,
1.0f/255.0f,
1.0f/32767.0f,
1.0f/65535.0f,
1.0f/2147483647.0f,
1.0f/4294967295.0f
};
static
void dereference (struct pspgl_vertex_array *a, GLint idx,
void (*glfunc) (const GLfloat *v), int scale)
{
const void *ptr;
GLfloat val [4];
GLfloat factor;
int i;
if (!a->enabled)
return;
ptr = __pspgl_bufferobj_map(a->buffer, GL_READ_ONLY_ARB, (void *)a->ptr);
ptr += a->stride * idx;
if (scale && a->type >= GL_BYTE && a->type <= GL_UNSIGNED_INT)
factor = scale_factor[a->type - GL_BYTE];
else
factor = 1.0f;
/* be prepared for incomplete initialisations... */
val[2] = 0.0f;
val[3] = 1.0f;
switch (a->type) {
case GL_BYTE:
for (i=0; i<a->size; i++)
val[i] = ((GLbyte *) ptr)[i] * factor;
break;
case GL_UNSIGNED_BYTE:
for (i=0; i<a->size; i++)
val[i] = ((GLubyte *) ptr)[i] * factor;
break;
case GL_SHORT:
for (i=0; i<a->size; i++)
val[i] = ((GLshort *) ptr)[i] * factor;
break;
case GL_UNSIGNED_SHORT:
for (i=0; i<a->size; i++)
val[i] = ((GLushort *) ptr)[i] * factor;
break;
case GL_INT:
for (i=0; i<a->size; i++)
val[i] = ((GLint *) ptr)[i] * factor;
break;
case GL_UNSIGNED_INT:
for (i=0; i<a->size; i++)
val[i] = ((GLuint *) ptr)[i] * factor;
break;
case GL_FLOAT:
for (i=0; i<a->size; i++)
val[i] = ((GLfloat *) ptr)[i];
break;
case GL_DOUBLE:
for (i=0; i<a->size; i++)
val[i] = ((GLdouble *) ptr)[i];
break;
default:
GLERROR(GL_INVALID_ENUM);
}
(*glfunc)(val);
__pspgl_bufferobj_unmap(a->buffer, GL_READ_ONLY_ARB);
}
void glArrayElement (GLint i)
{
dereference(&pspgl_curctx->vertex_array.texcoord, i, glTexCoord4fv, 1);
dereference(&pspgl_curctx->vertex_array.color, i, glColor4fv, 1);
dereference(&pspgl_curctx->vertex_array.normal, i, glNormal3fv, 1);
dereference(&pspgl_curctx->vertex_array.vertex, i, glVertex4fv, 0);
}