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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
*/
package com.sun.opengl.util.glsl.fixed;
import javax.media.opengl.*;
import javax.media.opengl.sub.*;
import javax.media.opengl.sub.fixed.*;
import javax.media.opengl.util.*;
import javax.media.opengl.glu.*;
import com.sun.gluegen.runtime.BufferFactory;
import com.sun.opengl.util.glsl.*;
import com.sun.opengl.impl.glsl.fixed.*;
import java.nio.*;
public class FixedFuncHook implements GLFixedFuncHookIf {
public static final int MAX_TEXTURE_UNITS = 8;
protected FixedFuncPipeline fixedFunction=null;
protected PMVMatrix pmvMatrix=null;
protected GL2ES2 gl=null;
public FixedFuncHook (GL2ES2 gl) {
this(gl, null);
}
public FixedFuncHook (GL2ES2 gl, PMVMatrix matrix) {
this.gl = gl;
pmvMatrix = (null!=matrix)?matrix:new PMVMatrix();
fixedFunction = new FixedFuncPipeline(gl, pmvMatrix);
}
public FixedFuncHook(GL2ES2 gl, PMVMatrix matrix,
Class shaderRootClass, String shaderSrcRoot, String shaderBinRoot,
String vertexColorFile,
String vertexColorLightFile,
String fragmentColorFile,
String fragmentColorTextureFile) {
this.gl = gl;
pmvMatrix = matrix;
fixedFunction = new FixedFuncPipeline(gl, pmvMatrix,
shaderRootClass, shaderSrcRoot, shaderBinRoot,
vertexColorFile, vertexColorLightFile, fragmentColorFile, fragmentColorTextureFile);
}
public void destroy() {
fixedFunction.destroy(gl);
fixedFunction = null;
}
public PMVMatrix getMatrix() { return pmvMatrix; }
//
// FixedFuncHookIf - hooks
//
public void glDrawArrays(int mode, int first, int count) {
fixedFunction.validate(gl);
gl.glDrawArrays(mode, first, count);
}
public void glDrawElements(int mode, int count, int type, java.nio.Buffer indices) {
fixedFunction.validate(gl);
gl.glDrawElements(mode, count, type, indices);
}
public void glDrawElements(int mode, int count, int type, long indices_buffer_offset) {
fixedFunction.validate(gl);
gl.glDrawElements(mode, count, type, indices_buffer_offset);
}
public void glActiveTexture(int texture) {
fixedFunction.glActiveTexture(gl, texture);
gl.glActiveTexture(texture);
}
public void glEnable(int cap) {
if(fixedFunction.glEnable(gl, cap, true)) {
gl.glEnable(cap);
}
}
public void glDisable(int cap) {
if(fixedFunction.glEnable(gl, cap, false)) {
gl.glDisable(cap);
}
}
public void glCullFace(int faceName) {
fixedFunction.glCullFace(gl, faceName);
gl.glCullFace(faceName);
}
public void glGetFloatv(int pname, java.nio.FloatBuffer params) {
if(pmvMatrix.isMatrixGetName(pname)) {
pmvMatrix.glGetFloatv(pname, params);
return;
}
gl.glGetFloatv(pname, params);
}
public void glGetFloatv(int pname, float[] params, int params_offset) {
if(pmvMatrix.isMatrixGetName(pname)) {
pmvMatrix.glGetFloatv(pname, params, params_offset);
return;
}
gl.glGetFloatv(pname, params, params_offset);
}
public void glGetIntegerv(int pname, IntBuffer params) {
if(pmvMatrix.isMatrixGetName(pname)) {
pmvMatrix.glGetIntegerv(pname, params);
return;
}
gl.glGetIntegerv(pname, params);
}
public void glGetIntegerv(int pname, int[] params, int params_offset) {
if(pmvMatrix.isMatrixGetName(pname)) {
pmvMatrix.glGetIntegerv(pname, params, params_offset);
return;
}
gl.glGetIntegerv(pname, params, params_offset);
}
//
// MatrixIf
//
public int glGetMatrixMode() {
return pmvMatrix.glGetMatrixMode();
}
public void glMatrixMode(int mode) {
pmvMatrix.glMatrixMode(mode);
}
public void glLoadMatrixf(java.nio.FloatBuffer m) {
pmvMatrix.glLoadMatrixf(m);
}
public void glLoadMatrixf(float[] m, int m_offset) {
glLoadMatrixf(BufferUtil.newFloatBuffer(m, m_offset));
}
public void glPopMatrix() {
pmvMatrix.glPopMatrix();
}
public void glPushMatrix() {
pmvMatrix.glPushMatrix();
}
public void glLoadIdentity() {
pmvMatrix.glLoadIdentity();
}
public void glMultMatrixf(java.nio.FloatBuffer m) {
pmvMatrix.glMultMatrixf(m);
}
public void glMultMatrixf(float[] m, int m_offset) {
glMultMatrixf(BufferUtil.newFloatBuffer(m, m_offset));
}
public void glTranslatef(float x, float y, float z) {
pmvMatrix.glTranslatef(x, y, z);
}
public void glRotatef(float angdeg, float x, float y, float z) {
pmvMatrix.glRotatef(angdeg, x, y, z);
}
public void glScalef(float x, float y, float z) {
pmvMatrix.glScalef(x, y, z);
}
public void glOrthof(float left, float right, float bottom, float top, float zNear, float zFar) {
pmvMatrix.glOrthof(left, right, bottom, top, zNear, zFar);
}
public void glFrustumf(float left, float right, float bottom, float top, float zNear, float zFar) {
pmvMatrix.glFrustumf(left, right, bottom, top, zNear, zFar);
}
//
// LightingIf
//
public void glColor4f(float red, float green, float blue, float alpha) {
fixedFunction.glColor4fv(gl, BufferUtil.newFloatBuffer(new float[] { red, green, blue, alpha }));
}
public void glLightfv(int light, int pname, java.nio.FloatBuffer params) {
fixedFunction.glLightfv(gl, light, pname, params);
}
public void glLightfv(int light, int pname, float[] params, int params_offset) {
glLightfv(light, pname, BufferUtil.newFloatBuffer(params, params_offset));
}
public void glMaterialfv(int face, int pname, java.nio.FloatBuffer params) {
fixedFunction.glMaterialfv(gl, face, pname, params);
}
public void glMaterialfv(int face, int pname, float[] params, int params_offset) {
glMaterialfv(face, pname, BufferUtil.newFloatBuffer(params, params_offset));
}
public void glMaterialf(int face, int pname, float param) {
glMaterialfv(face, pname, BufferUtil.newFloatBuffer(new float[] { param }));
}
public void glShadeModel(int mode) {
fixedFunction.glShadeModel(gl, mode);
}
//
// PointerIf
//
public void glEnableClientState(int glArrayIndex) {
fixedFunction.glEnableClientState(gl, glArrayIndex);
}
public void glDisableClientState(int glArrayIndex) {
fixedFunction.glDisableClientState(gl, glArrayIndex);
}
public void glVertexPointer(GLArrayData array) {
if(array.isVBO()) {
if(!gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not enabled: "+array);
}
} else {
if(gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not disabled: "+array);
}
BufferFactory.rangeCheck(array.getBuffer(), 1);
if (!BufferFactory.isDirect(array.getBuffer())) {
throw new GLException("Argument \"pointer\" was not a direct buffer"); }
}
fixedFunction.glVertexPointer(gl, array);
}
public void glVertexPointer(int size, int type, int stride, java.nio.Buffer pointer) {
glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false, stride, pointer, 0, 0));
}
public void glVertexPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glVertexPointer(GLArrayDataWrapper.createFixed(GL_VERTEX_ARRAY, size, type, false,
stride, null, vboName, pointer_buffer_offset));
}
public void glColorPointer(GLArrayData array) {
if(array.isVBO()) {
if(!gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not enabled: "+array);
}
} else {
if(gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not disabled: "+array);
}
BufferFactory.rangeCheck(array.getBuffer(), 1);
if (!BufferFactory.isDirect(array.getBuffer())) {
throw new GLException("Argument \"pointer\" was not a direct buffer"); }
}
fixedFunction.glColorPointer(gl, array);
}
public void glColorPointer(int size, int type, int stride, java.nio.Buffer pointer) {
glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false,
stride, pointer, 0, 0));
}
public void glColorPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glColorPointer(GLArrayDataWrapper.createFixed(GL_COLOR_ARRAY, size, type, false,
stride, null, vboName, pointer_buffer_offset));
}
public void glNormalPointer(GLArrayData array) {
if(array.getComponentNumber()!=3) {
throw new GLException("Only 3 components per normal allowed");
}
if(array.isVBO()) {
if(!gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not enabled: "+array);
}
} else {
if(gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not disabled: "+array);
}
BufferFactory.rangeCheck(array.getBuffer(), 1);
if (!BufferFactory.isDirect(array.getBuffer())) {
throw new GLException("Argument \"pointer\" was not a direct buffer"); }
}
fixedFunction.glNormalPointer(gl, array);
}
public void glNormalPointer(int type, int stride, java.nio.Buffer pointer) {
glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false,
stride, pointer, 0, 0));
}
public void glNormalPointer(int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glNormalPointer(GLArrayDataWrapper.createFixed(GL_NORMAL_ARRAY, 3, type, false,
stride, null, vboName, pointer_buffer_offset));
}
public void glTexCoordPointer(GLArrayData array) {
if(array.isVBO()) {
if(!gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not enabled: "+array);
}
} else {
if(gl.glIsVBOArrayEnabled()) {
throw new GLException("VBO array is not disabled: "+array);
}
BufferFactory.rangeCheck(array.getBuffer(), 1);
if (!BufferFactory.isDirect(array.getBuffer())) {
throw new GLException("Argument \"pointer\" was not a direct buffer"); }
}
fixedFunction.glTexCoordPointer(gl, array);
}
public void glTexCoordPointer(int size, int type, int stride, java.nio.Buffer pointer) {
glTexCoordPointer(
GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false, stride, pointer, 0,0));
}
public void glTexCoordPointer(int size, int type, int stride, long pointer_buffer_offset) {
int vboName = gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER);
if(vboName==0) {
throw new GLException("no GL_ARRAY_BUFFER VBO bound");
}
glTexCoordPointer(
GLArrayDataWrapper.createFixed(GL_TEXTURE_COORD_ARRAY, size, type, false,
stride, null, vboName, pointer_buffer_offset) );
}
public final String toString() {
StringBuffer buf = new StringBuffer();
buf.append(getClass().getName()+" (");
if(null!=pmvMatrix) {
buf.append(", matrixDirty: "+pmvMatrix.isDirty());
}
buf.append("\n\t, FixedFunction: "+fixedFunction);
buf.append(gl);
buf.append(" )");
return buf.toString();
}
}
|