JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
GearsObjectES1.java
Go to the documentation of this file.
1/**
2 * Copyright (C) 2011 JogAmp Community. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21package com.jogamp.opengl.test.junit.jogl.demos.es1;
22
23import java.nio.FloatBuffer;
24
25import com.jogamp.opengl.GL;
26import com.jogamp.opengl.GL2ES1;
27import com.jogamp.opengl.GLBufferStorage;
28import com.jogamp.opengl.GLException;
29import com.jogamp.opengl.fixedfunc.GLLightingFunc;
30import com.jogamp.opengl.fixedfunc.GLPointerFunc;
31
32import com.jogamp.opengl.test.junit.jogl.demos.GearsObject;
33import com.jogamp.opengl.util.GLArrayDataServer;
34
35/**
36 * GearsObjectES1.java <BR>
37 * @author Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
38 */
39public class GearsObjectES1 extends GearsObject {
40
41 public GearsObjectES1(final GL gl, final boolean useMappedBuffers, final FloatBuffer gearColor, final float inner_radius,
42 final float outer_radius, final float width, final int teeth, final float tooth_depth, final boolean validateBuffers) {
43 super(gl, useMappedBuffers, gearColor, inner_radius, outer_radius, width, teeth, tooth_depth, validateBuffers);
44 }
45
46 public GearsObjectES1(final GearsObject shared) {
47 super(shared);
48 }
49
50 @Override
51 public GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage) {
52 if( useMappedBuffers ) {
53 return GLArrayDataServer.createFixedInterleavedMapped(comps, dataType, normalized, initialSize, vboUsage);
54 } else {
55 return GLArrayDataServer.createFixedInterleaved(comps, dataType, normalized, initialSize, vboUsage);
56 }
57 }
58
59 @Override
60 public void addInterleavedVertexAndNormalArrays(final GLArrayDataServer array, final int components) {
63 }
64
65 private void draw(final GL2ES1 gl, final GLArrayDataServer array, final int mode) {
66 if( !isShared || gl.glIsBuffer(array.getVBOName()) ) {
67 array.enableBuffer(gl, true);
68 if( validateBuffers ) {
69 final int bufferTarget = array.getVBOTarget();
70 final int bufferName = array.getVBOName();
71 final long bufferSize = array.getByteCount();
72 final int hasBufferName = gl.getBoundBuffer(bufferTarget);
73 final GLBufferStorage hasStorage = gl.getBufferStorage(hasBufferName);
74 final boolean ok = bufferName == hasBufferName &&
75 bufferName == hasStorage.getName() &&
76 bufferSize == hasStorage.getSize();
77 if( !ok ) {
78 throw new GLException("GLBufferStorage Validation Error: Target[exp 0x"+Integer.toHexString(bufferTarget)+", has 0x"+Integer.toHexString(bufferTarget)+
79 ", Name[exp "+bufferName+", has "+hasBufferName+", Size exp "+bufferSize+", Storage "+hasStorage+"]");
80 }
81 }
82 gl.glDrawArrays(mode, 0, array.getElemCount());
83 array.enableBuffer(gl, false);
84 }
85 }
86
87 @Override
88 public void draw(final GL _gl, final float x, final float y, final float angle) {
89 final GL2ES1 gl = _gl.getGL2ES1();
90 gl.glPushMatrix();
91 gl.glTranslatef(x, y, 0f);
92 gl.glRotatef(angle, 0f, 0f, 1f);
94
97 draw(gl, frontSide, GL.GL_TRIANGLES);
98 draw(gl, backFace, GL.GL_TRIANGLE_STRIP);
99 draw(gl, backSide, GL.GL_TRIANGLES);
103 gl.glPopMatrix();
104 }
105}
OpenGL buffer storage object reflecting it's.
final int getName()
Return the buffer name.
final long getSize()
Return the buffer's storage size.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
void draw(final GL _gl, final float x, final float y, final float angle)
void addInterleavedVertexAndNormalArrays(final GLArrayDataServer array, final int components)
GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage)
GearsObjectES1(final GL gl, final boolean useMappedBuffers, final FloatBuffer gearColor, final float inner_radius, final float outer_radius, final float width, final int teeth, final float tooth_depth, final boolean validateBuffers)
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createFixedInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for fixed function interleaved array data starting with a new created Buffer object with...
GLArrayData addFixedSubArray(final int index, final int comps, final int vboTarget)
Configure a segment of this fixed function interleaved array (see createFixedInterleaved(int,...
static GLArrayDataServer createFixedInterleavedMapped(final int compsPerElement, final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
Create a VBO for fixed function interleaved array data intended for GPU buffer storage mapping,...
final int getByteCount()
Returns the byte position (written elements) if not sealed() or the byte limit (available to read) af...
final int getElemCount()
Returns the element position (written elements) if not sealed() or the element limit (available to re...
final int getVBOName()
The VBO name or 0 if not a VBO.
final int getVBOTarget()
The VBO target or 0 if not a VBO.
GL2ES1 getGL2ES1()
Casts this object to the GL2ES1 interface.
int getBoundBuffer(int target)
GLBufferStorage getBufferStorage(int bufferName)
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_TRIANGLES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLES" with expre...
Definition: GL.java:145
boolean glIsBuffer(int buffer)
Entry point to C language function: GLboolean {@native glIsBuffer}(GLuint buffer) Part of GL_VERSI...
static final int GL_FRONT_AND_BACK
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FRONT_AND_BACK" with ...
Definition: GL.java:619
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with ...
Definition: GL.java:760
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...
Definition: GL.java:633
void glMaterialfv(int face, int pname, java.nio.FloatBuffer params)
void glPushMatrix()
Push the current matrix to it's stack, while preserving it's values.
void glPopMatrix()
Pop the current matrix from it's stack.
void glTranslatef(float x, float y, float z)
Translate the current matrix.
void glRotatef(float angle, float x, float y, float z)
Rotate the current matrix.