Java Code Examples for com.jogamp.opengl.GL2GL3#glBindBuffer()
The following examples show how to use
com.jogamp.opengl.GL2GL3#glBindBuffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextureView.java From jaamsim with Apache License 2.0 | 6 votes |
private void updateTexCoordBuffer(Renderer renderer) { GL2GL3 gl = renderer.getGL(); int texCoordBuffSize = _texCoords.size()*2*4; _texCoordHandle = renderer.getTexMemManager().allocateBuffer(texCoordBuffSize, gl); int buffID = _texCoordHandle.bind(); FloatBuffer texData = FloatBuffer.allocate(_texCoords.size()*2); for (Vec2d v : _texCoords) { texData.put((float)v.x); texData.put((float)v.y); } texData.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, buffID); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, texCoordBuffSize, texData, GL2GL3.GL_STATIC_DRAW); int texCoordVar = gl.glGetAttribLocation(progHandle, "texCoord"); gl.glEnableVertexAttribArray(texCoordVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, buffID); gl.glVertexAttribPointer(texCoordVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); }
Example 2
Source File: Polygon.java From jaamsim with Apache License 2.0 | 6 votes |
private void renderOutline(GL2GL3 gl) { // The vertex list is just the closed loop of points if (lineWidth == 0) { return; } gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _vertBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, fb.limit() * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); if (!gl.isGLcore()) gl.glLineWidth((float)lineWidth); else gl.glLineWidth(1.0f); gl.glDrawArrays(GL2GL3.GL_LINE_LOOP, 0, _points.size()); gl.glLineWidth(1.0f); }
Example 3
Source File: Skybox.java From jaamsim with Apache License 2.0 | 5 votes |
public static void loadGPUAssets(Renderer r) { GL2GL3 gl = r.getGL(); int[] buffs = new int[1]; gl.glGenBuffers(1, buffs, 0); vertBuff = buffs[0]; progHandle = r.getShader(Renderer.ShaderHandle.SKYBOX).getProgramHandle(); projMatVar = gl.glGetUniformLocation(progHandle, "projMat"); invViewMatVar = gl.glGetUniformLocation(progHandle, "invViewMat"); texVar = gl.glGetUniformLocation(progHandle, "tex"); FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f); verts.put( 0.5f); verts.put(-0.5f); verts.put(-0.5f); verts.put( 0.5f); verts.put( 0.5f); verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f); verts.put(-0.5f); verts.put( 0.5f); verts.put( 0.5f); verts.put(-0.5f); verts.put(-0.5f); verts.put( 0.5f); verts.put(-0.5f); verts.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); isLoaded = true; }
Example 4
Source File: RenderUtils.java From jaamsim with Apache License 2.0 | 5 votes |
static void nioBuffToGL(GL2GL3 gl, Renderer r, int bufferHandle, int itemSize, Buffer buff) { buff.flip(); int size = buff.limit() * itemSize; gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, bufferHandle); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, size, buff, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); r.usingVRAM(size); }
Example 5
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 5 votes |
private void loadGPUSubLine(GL2GL3 gl, Renderer renderer, MeshData.SubLineData data) { Shader s = renderer.getShader(Renderer.ShaderHandle.DEBUG); assert (s.isGood()); SubLine sub = new SubLine(); sub._progHandle = s.getProgramHandle(); int[] is = new int[1]; gl.glGenBuffers(1, is, 0); sub._vertexBuffer = is[0]; sub._numVerts = data.verts.size(); sub._hull = data.hull; // Init vertices FloatBuffer fb = FloatBuffer.allocate(data.verts.size() * 3); // for (Vec3d v : data.verts) { RenderUtils.putPointXYZ(fb, v); } fb.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, sub._vertexBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, sub._numVerts * 3 * 4, fb, GL2GL3.GL_STATIC_DRAW); // Bind the shader variables sub._modelViewMatVar = gl.glGetUniformLocation(sub._progHandle, "modelViewMat"); sub._projMatVar = gl.glGetUniformLocation(sub._progHandle, "projMat"); sub._diffuseColor = new Color4d(data.diffuseColor); sub._colorVar = gl.glGetUniformLocation(sub._progHandle, "color"); sub._cVar = gl.glGetUniformLocation(sub._progHandle, "C"); sub._fcVar = gl.glGetUniformLocation(sub._progHandle, "FC"); _subLines.add(sub); }
Example 6
Source File: TextureView.java From jaamsim with Apache License 2.0 | 5 votes |
private void setupVAO(int contextID, Renderer renderer) { GL2GL3 gl = renderer.getGL(); int vao = renderer.generateVAO(contextID, gl); VAOMap.put(contextID, vao); gl.glBindVertexArray(vao); // Position int posVar = gl.glGetAttribLocation(progHandle, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff); gl.glVertexAttribPointer(posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); // Normals int normalVar = gl.glGetAttribLocation(progHandle, "normal"); gl.glEnableVertexAttribArray(normalVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, normalBuff); gl.glVertexAttribPointer(normalVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); // TexCoords if (_texCoords == null) { // Use default buffer if custom coords have not been included int texCoordVar = gl.glGetAttribLocation(progHandle, "texCoord"); gl.glEnableVertexAttribArray(texCoordVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, texCoordBuff); gl.glVertexAttribPointer(texCoordVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); } gl.glBindVertexArray(0); }
Example 7
Source File: TessString.java From jaamsim with Apache License 2.0 | 4 votes |
@Override public void render(int contextID, Renderer renderer, Camera cam, Ray pickRay) { GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); // Render the string Shader s = renderer.getShader(Renderer.ShaderHandle.FONT); s.useShader(gl); int prog = s.getProgramHandle(); // Setup uniforms for this object Mat4d modelViewProjMat = new Mat4d(); cam.getViewMat4d(modelViewProjMat); modelViewProjMat.mult4(_trans); Mat4d projMat = cam.getProjMat4d(); modelViewProjMat.mult4(projMat, modelViewProjMat); int modelViewProjMatVar = gl.glGetUniformLocation(prog, "modelViewProjMat"); gl.glUniformMatrix4fv(modelViewProjMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewProjMat), 0); int colorVar = gl.glGetUniformLocation(prog, "color"); gl.glUniform4fv(colorVar, 1, _color, 0); int cVar = gl.glGetUniformLocation(prog, "C"); gl.glUniform1f(cVar, Camera.C); int fcVar = gl.glGetUniformLocation(prog, "FC"); gl.glUniform1f(fcVar, Camera.FC); int advanceVar = gl.glGetUniformLocation(prog, "advance"); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl)); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); // Send out one draw call per character float advance = 0; gl.glDisable(GL2GL3.GL_CULL_FACE); for (int i = 0; i < _contents.length; ++i) { gl.glUniform1f(advanceVar, advance); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, starts[i], numVerts[i]); advance += advances[i]; } gl.glEnable(GL2GL3.GL_CULL_FACE); // Cleanup gl.glDisableVertexAttribArray(posVar); }
Example 8
Source File: DebugUtils.java From jaamsim with Apache License 2.0 | 4 votes |
/** * Initialize the GL assets needed, this should be called with the shared GL context * @param gl */ public static void init(Renderer r, GL2GL3 gl) { int[] is = new int[3]; gl.glGenBuffers(3, is, 0); _aabbVertBuffer = is[0]; _boxVertBuffer = is[1]; _lineVertBuffer = is[2]; Shader s = r.getShader(ShaderHandle.DEBUG); _debugProgHandle = s.getProgramHandle(); gl.glUseProgram(_debugProgHandle); _modelViewMatVar = gl.glGetUniformLocation(_debugProgHandle, "modelViewMat"); _projMatVar = gl.glGetUniformLocation(_debugProgHandle, "projMat"); _colorVar = gl.glGetUniformLocation(_debugProgHandle, "color"); _posVar = gl.glGetAttribLocation(_debugProgHandle, "position"); _cVar = gl.glGetAttribLocation(_debugProgHandle, "C"); _fcVar = gl.glGetAttribLocation(_debugProgHandle, "FC"); // Build up a buffer of vertices for lines in a box gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _aabbVertBuffer); FloatBuffer fb = FloatBuffer.allocate(3 * 2 * 12); // 12 line segments // Top lines app( 1, 1, 1, fb); app( 1, -1, 1, fb); app( 1, -1, 1, fb); app(-1, -1, 1, fb); app(-1, -1, 1, fb); app(-1, 1, 1, fb); app(-1, 1, 1, fb); app( 1, 1, 1, fb); // Bottom lines app( 1, 1, -1, fb); app( 1, -1, -1, fb); app( 1, -1, -1, fb); app(-1, -1, -1, fb); app(-1, -1, -1, fb); app(-1, 1, -1, fb); app(-1, 1, -1, fb); app( 1, 1, -1, fb); // Side lines app( 1, 1, 1, fb); app( 1, 1, -1, fb); app(-1, 1, 1, fb); app(-1, 1, -1, fb); app( 1, -1, 1, fb); app( 1, -1, -1, fb); app(-1, -1, 1, fb); app(-1, -1, -1, fb); fb.flip(); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 3 * 2 * 12 * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); // Create a buffer for drawing rectangles // Build up a buffer of vertices for lines in a box gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _boxVertBuffer); fb = FloatBuffer.allocate(3 * 2 * 4); // 4 line segments // lines app( 0.5f, 0.5f, 0, fb); app( 0.5f, -0.5f, 0, fb); app( 0.5f, -0.5f, 0, fb); app(-0.5f, -0.5f, 0, fb); app(-0.5f, -0.5f, 0, fb); app(-0.5f, 0.5f, 0, fb); app(-0.5f, 0.5f, 0, fb); app( 0.5f, 0.5f, 0, fb); fb.flip(); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 3 * 2 * 4 * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); }
Example 9
Source File: DebugUtils.java From jaamsim with Apache License 2.0 | 4 votes |
public static void renderArmature(int contextID, Renderer renderer, Mat4d modelViewMat, Armature arm, ArrayList<Mat4d> pose, Color4d color, Camera cam) { GL2GL3 gl = renderer.getGL(); if (!_debugVAOMap.containsKey(contextID)) { setupDebugVAO(contextID, renderer); } int vao = _debugVAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(_debugProgHandle); // Setup uniforms for this object Mat4d projMat = cam.getProjMat4d(); gl.glUniformMatrix4fv(_modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(_projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0); gl.glUniform4fv(_colorVar, 1, color.toFloats(), 0); gl.glUniform1f(_cVar, Camera.C); gl.glUniform1f(_fcVar, Camera.FC); ArrayList<Armature.Bone> bones = arm.getAllBones(); //Build up the list of bone vertices Vec4d[] vects = new Vec4d[bones.size() * 2]; for (int i = 0; i < bones.size(); ++i) { Armature.Bone b = bones.get(i); Vec4d boneStart = new Vec4d(0, 0, 0, 1); boneStart.mult4(b.getMatrix(), boneStart); Vec4d boneEnd = new Vec4d(0, b.getLength(), 0, 1); boneEnd.mult4(b.getMatrix(), boneEnd); if (pose != null) { // Adjust the bone by the current pose Mat4d poseMat = pose.get(i); boneStart.mult4(poseMat, boneStart); boneEnd.mult4(poseMat, boneEnd); } vects[2*i + 0] = boneStart; vects[2*i + 1] = boneEnd; } // Now push it to the card FloatBuffer fb = FloatBuffer.allocate(vects.length * 3); for (Vec4d v : vects) { RenderUtils.putPointXYZ(fb, v); } fb.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _lineVertBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, fb.limit() * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glDisable(GL2GL3.GL_DEPTH_TEST); gl.glDrawArrays(GL2GL3.GL_LINES, 0, fb.limit() / 3); gl.glEnable(GL2GL3.GL_DEPTH_TEST); gl.glLineWidth(1.0f); gl.glBindVertexArray(0); }
Example 10
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void setupVAOForStaticLines(int contextID, Renderer renderer) { GL2GL3 gl = renderer.getGL(); int vao = renderer.generateVAO(contextID, gl); _lineVAOs.put(contextID, vao); gl.glBindVertexArray(vao); Shader s= renderer.getShader(ShaderHandle.DEBUG_BATCH); assert(s.isGood()); int prog = s.getProgramHandle(); gl.glUseProgram(prog); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, linePosBuffer); gl.glVertexAttribPointer(posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); int colVar = gl.glGetAttribLocation(prog, "vertColor"); gl.glEnableVertexAttribArray(colVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, lineInstColorBuffer); gl.glVertexAttribPointer(colVar, 4, GL2GL3. GL_UNSIGNED_BYTE, true, 0, 0); gl.glVertexAttribDivisor(colVar, 1); int instMatVar = gl.glGetAttribLocation(prog, "instMat"); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, lineTransBuffer); for (int i = 0; i < 4; ++i) { // Enable 4 variables because this is a matrix int varInd = instMatVar + i; gl.glEnableVertexAttribArray(varInd); gl.glVertexAttribPointer(varInd, 4, GL2GL3.GL_FLOAT, false, 16*4, i*4*4); gl.glVertexAttribDivisor(varInd, 1); // Per instance } gl.glBindVertexArray(0); }
Example 11
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void setupVAOForSubLine(int contextID, SubLine sub, Renderer renderer) { GL2GL3 gl = renderer.getGL(); int vao = renderer.generateVAO(contextID, gl); sub.vaoMap.put(contextID, vao); gl.glBindVertexArray(vao); int prog = sub._progHandle; gl.glUseProgram(prog); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, sub._vertexBuffer); gl.glVertexAttribPointer(posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindVertexArray(0); }
Example 12
Source File: OverlayString.java From jaamsim with Apache License 2.0 | 4 votes |
@Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { Vec3d renderedSize = _font.getStringSize(_height, _contents); double x = _x; double y = _y; if (_alignRight) { x = windowWidth - _x - renderedSize.x; } if (!_alignBottom) { y = windowHeight - _y - renderedSize.y; } GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); // Render the string Shader s = renderer.getShader(Renderer.ShaderHandle.OVERLAY_FONT); s.useShader(gl); int prog = s.getProgramHandle(); int colorVar = gl.glGetUniformLocation(prog, "color"); gl.glUniform4fv(colorVar, 1, _color, 0); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl)); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); int offsetVar = gl.glGetUniformLocation(prog, "offset"); float scaleY = (float)(2 * _height / (windowHeight * _font.getNominalHeight())); float scaleX = scaleY * (float)(windowHeight/windowWidth); int scaleVar = gl.glGetUniformLocation(prog, "scale"); gl.glUniform2f(scaleVar, scaleX, scaleY); float offsetX = (float)(2*x/windowWidth - 1); float offsetY = (float)(2*y/windowHeight - 1); gl.glDisable(GL2GL3.GL_CULL_FACE); for (int cp : RenderUtils.stringToCodePoints(_contents)) { TessChar tc = _font.getTessChar(cp); if (tc == null) { assert(false); continue; } gl.glUniform2f(offsetVar, offsetX, offsetY); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, tc.getStartIndex(), tc.getNumVerts()); offsetX += tc.getAdvance()*scaleX; } gl.glEnable(GL2GL3.GL_CULL_FACE); }
Example 13
Source File: HullProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void setupVAO(int contextID, Renderer renderer, int progHandle, int vertexBuffer, int indexBuffer) { GL2GL3 gl = renderer.getGL(); int vao = renderer.generateVAO(contextID, gl); _vaoMap.put(contextID, vao); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); int posVar = gl.glGetAttribLocation(progHandle, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertexBuffer); gl.glVertexAttribPointer(posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); gl.glBindVertexArray(0); }
Example 14
Source File: BillboardString.java From jaamsim with Apache License 2.0 | 4 votes |
/** * Note: render() and renderForView() are mutually non-reentrant due to shared temporaries. This should be fine * because neither should ever be called by any thread other than the render thread. */ @Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); // Render the string Shader s = renderer.getShader(Renderer.ShaderHandle.OVERLAY_FONT); s.useShader(gl); int prog = s.getProgramHandle(); // Work out the billboard position cam.getViewMat4d(tempViewMat); // Build up the projection*view matrix tempViewMat.mult4(cam.getProjMat4d(), tempViewMat); tempPos.x = _pos.x; tempPos.y = _pos.y; tempPos.z = _pos.z; tempPos.w = 1.0; tempPos.mult4(tempViewMat, tempPos); tempPos.x /= tempPos.w; tempPos.y /= tempPos.w; // TempPos x and y are now in normalized coordinate space (after the projection) int colorVar = gl.glGetUniformLocation(prog, "color"); gl.glUniform4fv(colorVar, 1, _color, 0); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl)); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); int offsetVar = gl.glGetUniformLocation(prog, "offset"); float scaleY = (float)(2 * _height / (windowHeight * _font.getNominalHeight())); float scaleX = scaleY * (float)(windowHeight/windowWidth); int scaleVar = gl.glGetUniformLocation(prog, "scale"); gl.glUniform2f(scaleVar, scaleX, scaleY); float offsetX = (float)tempPos.x; float offsetY = (float)tempPos.y; offsetX += _xOffset*2.0/windowWidth; offsetY += _yOffset*2.0/windowHeight; gl.glDisable(GL2GL3.GL_CULL_FACE); for (int cp : RenderUtils.stringToCodePoints(_contents)) { TessChar tc = _font.getTessChar(cp); if (tc == null) { assert(false); continue; } gl.glUniform2f(offsetVar, offsetX, offsetY); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, tc.getStartIndex(), tc.getNumVerts()); offsetX += tc.getAdvance()*scaleX; } gl.glEnable(GL2GL3.GL_CULL_FACE); }
Example 15
Source File: DebugUtils.java From jaamsim with Apache License 2.0 | 4 votes |
public static void renderAABB(int contextID, Renderer renderer, AABB aabb, Color4d color, Camera cam) { if (aabb.isEmpty()) { return; } GL2GL3 gl = renderer.getGL(); if (!_debugVAOMap.containsKey(contextID)) { setupDebugVAO(contextID, renderer); } int vao = _debugVAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(_debugProgHandle); // Setup uniforms for this object Mat4d projMat = cam.getProjMat4d(); Mat4d modelViewMat = new Mat4d(); cam.getViewMat4d(modelViewMat); Mat4d aabbCenterMat = new Mat4d(); aabbCenterMat.setTranslate3(aabb.center); modelViewMat.mult4(aabbCenterMat); modelViewMat.scaleCols3(aabb.radius); gl.glUniformMatrix4fv(_modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(_projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0); gl.glUniform4fv(_colorVar, 1, color.toFloats(), 0); gl.glUniform1f(_cVar, Camera.C); gl.glUniform1f(_fcVar, Camera.FC); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _aabbVertBuffer); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glDrawArrays(GL2GL3.GL_LINES, 0, 12 * 2); gl.glBindVertexArray(0); }
Example 16
Source File: OverlayTexture.java From jaamsim with Apache License 2.0 | 4 votes |
private static void initStaticBuffers(Renderer r) { GL2GL3 gl = r.getGL(); int[] buffs = new int[2]; gl.glGenBuffers(2, buffs, 0); vertBuff = buffs[0]; texCoordBuff = buffs[1]; FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates verts.put(0.0f); verts.put(0.0f); verts.put(0.0f); verts.put(1.0f); verts.put(0.0f); verts.put(0.0f); verts.put(1.0f); verts.put(1.0f); verts.put(0.0f); verts.put(0.0f); verts.put(0.0f); verts.put(0.0f); verts.put(1.0f); verts.put(1.0f); verts.put(0.0f); verts.put(0.0f); verts.put(1.0f); verts.put(0.0f); verts.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW); FloatBuffer texCoords = FloatBuffer.allocate(6*2); // 2 triangles * 2 coordinates texCoords.put(0.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.put(1.0f); texCoords.put(0.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.put(1.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, texCoordBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*2*4, texCoords, GL2GL3.GL_STATIC_DRAW); // Initialize the shader variables progHandle = r.getShader(Renderer.ShaderHandle.OVERLAY_FLAT).getProgramHandle(); texVar = gl.glGetUniformLocation(progHandle, "tex"); hasTexVar = gl.glGetUniformLocation(progHandle, "useTex"); sizeVar = gl.glGetUniformLocation(progHandle, "size"); offsetVar = gl.glGetUniformLocation(progHandle, "offset"); staticInit = true; }
Example 17
Source File: TextureView.java From jaamsim with Apache License 2.0 | 4 votes |
private static void initStaticBuffers(Renderer r) { GL2GL3 gl = r.getGL(); int[] buffs = new int[3]; gl.glGenBuffers(3, buffs, 0); vertBuff = buffs[0]; texCoordBuff = buffs[1]; normalBuff = buffs[2]; FloatBuffer verts = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates verts.put(-0.5f); verts.put(-0.5f); verts.put(0.0f); verts.put( 0.5f); verts.put(-0.5f); verts.put(0.0f); verts.put( 0.5f); verts.put( 0.5f); verts.put(0.0f); verts.put(-0.5f); verts.put(-0.5f); verts.put(0.0f); verts.put( 0.5f); verts.put( 0.5f); verts.put(0.0f); verts.put(-0.5f); verts.put( 0.5f); verts.put(0.0f); verts.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, verts, GL2GL3.GL_STATIC_DRAW); FloatBuffer texCoords = FloatBuffer.allocate(6*2); // 2 triangles * 2 coordinates texCoords.put(0.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.put(1.0f); texCoords.put(0.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.put(1.0f); texCoords.put(0.0f); texCoords.put(1.0f); texCoords.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, texCoordBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*2*4, texCoords, GL2GL3.GL_STATIC_DRAW); FloatBuffer normals = FloatBuffer.allocate(6*3); // 2 triangles * 3 coordinates for (int i = 0; i < 6; ++i) { normals.put(0.0f); normals.put(0.0f); normals.put(1.0f); } normals.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, normalBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, 6*3*4, normals, GL2GL3.GL_STATIC_DRAW); // Initialize the shader variables progHandle = r.getMeshShader(Renderer.DIFF_TEX_FLAG).getProgramHandle(); modelViewMatVar = gl.glGetUniformLocation(progHandle, "modelViewMat"); projMatVar = gl.glGetUniformLocation(progHandle, "projMat"); normalMatVar = gl.glGetUniformLocation(progHandle, "normalMat"); bindSpaceMatVar = gl.glGetUniformLocation(progHandle, "bindSpaceMat"); bindSpaceNorMatVar = gl.glGetUniformLocation(progHandle, "bindSpaceNorMat"); texVar = gl.glGetUniformLocation(progHandle, "diffuseTex"); lightDirVar = gl.glGetUniformLocation(progHandle, "lightDir"); lightIntVar = gl.glGetUniformLocation(progHandle, "lightIntensity"); numLightsVar = gl.glGetUniformLocation(progHandle, "numLights"); specColorVar = gl.glGetUniformLocation(progHandle, "specColor"); ambientColorVar = gl.glGetUniformLocation(progHandle, "ambientColor"); shininessVar = gl.glGetUniformLocation(progHandle, "shininess"); cVar = gl.glGetUniformLocation(progHandle, "C"); fcVar = gl.glGetUniformLocation(progHandle, "FC"); lightDir[0] = 0; lightDir[1] = 0; lightDir[2] = -1; lightInt[0] = 1; staticInit = true; }
Example 18
Source File: Skybox.java From jaamsim with Apache License 2.0 | 4 votes |
private void setupVAO(int contextID, Renderer renderer) { GL2GL3 gl = renderer.getGL(); int vao = renderer.generateVAO(contextID, gl); VAOMap.put(contextID, vao); gl.glBindVertexArray(vao); // Position int posVar = gl.glGetAttribLocation(progHandle, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertBuff); gl.glVertexAttribPointer(posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glBindVertexArray(0); }
Example 19
Source File: DebugUtils.java From jaamsim with Apache License 2.0 | 3 votes |
public static void renderBox(int contextID, Renderer renderer, Transform modelTrans, Vec4d scale, Color4d color, Camera cam) { GL2GL3 gl = renderer.getGL(); if (!_debugVAOMap.containsKey(contextID)) { setupDebugVAO(contextID, renderer); } int vao = _debugVAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(_debugProgHandle); gl.glUniform1f(_cVar, Camera.C); gl.glUniform1f(_fcVar, Camera.FC); // Setup uniforms for this object Mat4d projMat = cam.getProjMat4d(); Mat4d modelViewMat = new Mat4d(); cam.getViewMat4d(modelViewMat); modelViewMat.mult4(modelTrans.getMat4dRef()); modelViewMat.scaleCols3(scale); gl.glUniformMatrix4fv(_modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(_projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0); gl.glUniform4fv(_colorVar, 1, color.toFloats(), 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _boxVertBuffer); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glDrawArrays(GL2GL3.GL_LINES, 0, 4 * 2); gl.glBindVertexArray(0); }
Example 20
Source File: DebugUtils.java From jaamsim with Apache License 2.0 | 2 votes |
/** * Render a number of lines segments from the points provided * @param vaoMap * @param renderer * @param lineSegments - pairs of discontinuous line start and end points * @param color * @param cam */ public static void renderLine(int contextID, Renderer renderer, FloatBuffer lineSegments, float[] color, double lineWidth, Camera cam) { GL2GL3 gl = renderer.getGL(); if (!_debugVAOMap.containsKey(contextID)) { setupDebugVAO(contextID, renderer); } int vao = _debugVAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(_debugProgHandle); // Setup uniforms for this object Mat4d projMat = cam.getProjMat4d(); Mat4d modelViewMat = new Mat4d(); cam.getViewMat4d(modelViewMat); gl.glUniformMatrix4fv(_modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(_projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0); gl.glUniform4fv(_colorVar, 1, color, 0); gl.glUniform1f(_cVar, Camera.C); gl.glUniform1f(_fcVar, Camera.FC); if (!gl.isGLcore()) gl.glLineWidth((float)lineWidth); else gl.glLineWidth(1.0f); // Build up a float buffer to pass to GL gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _lineVertBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, lineSegments.limit() * 4, lineSegments, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glDrawArrays(GL2GL3.GL_LINES, 0, lineSegments.limit() / 3); gl.glLineWidth(1.0f); gl.glBindVertexArray(0); }