Java Code Examples for com.jogamp.opengl.GL2GL3#glBindTexture()
The following examples show how to use
com.jogamp.opengl.GL2GL3#glBindTexture() .
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: DwGLTexture3D.java From PixelFlow with MIT License | 5 votes |
public void getData_GL2GL3(Buffer buffer){ int data_len = w * h * num_channel; if(buffer.remaining() < data_len){ System.out.println("ERROR DwGLTexture.getData_GL2GL3: buffer to small: "+buffer.capacity() +" < "+data_len); return; } GL2GL3 gl23 = gl.getGL2GL3(); gl23.glBindTexture(target, HANDLE[0]); gl23.glGetTexImage(target, 0, format, type, buffer); gl23.glBindTexture(target, 0); DwGLError.debug(gl, "DwGLTexture.getData_GL2GL3"); }
Example 2
Source File: DwGLTexture.java From PixelFlow with MIT License | 5 votes |
public void getData_GL2GL3(Buffer buffer){ int data_len = w * h * num_channel; if(buffer.remaining() < data_len){ System.out.println("ERROR DwGLTexture.getData_GL2GL3: buffer to small: "+buffer.capacity() +" < "+data_len); return; } GL2GL3 gl23 = gl.getGL2GL3(); gl23.glBindTexture(target, HANDLE[0]); gl23.glGetTexImage(target, 0, format, type, buffer); gl23.glBindTexture(target, 0); DwGLError.debug(gl, "DwGLTexture.getData_GL2GL3"); }
Example 3
Source File: Skybox.java From jaamsim with Apache License 2.0 | 4 votes |
public void render(int contextID, Renderer renderer, Camera cam) { if (textureURI == null) { return; } if (!isLoaded) { loadGPUAssets(renderer); } if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } GL2GL3 gl = renderer.getGL(); int textureID = renderer.getTexCache().getTexID(gl, textureURI, false, false, false); if (textureID == TexCache.LOADING_TEX_ID) { // Sky box is not ready yet, get it next time return; } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(cam.getProjMat4d()), 0); Mat4d invViewMat = new Mat4d(); invViewMat.setRot4(cam.getTransformRef().getRotRef()); gl.glUniformMatrix4fv(invViewMatVar, 1, false, RenderUtils.MarshalMat4d(invViewMat), 0); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, textureID); // Disable mipmaps for skyboxes as the discontinuity screws them up gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR ); gl.glUniform1i(texVar, 0); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, 6); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR_MIPMAP_LINEAR ); gl.glBindVertexArray(0); }
Example 4
Source File: TextureView.java From jaamsim with Apache License 2.0 | 4 votes |
private void renderImp(int contextID, Renderer renderer, Camera cam, Ray pickRay) { if (!staticInit) { initStaticBuffers(renderer); } GL2GL3 gl = renderer.getGL(); int textureID = _texLoader.getTexID(renderer); if (textureID == TexCache.LOADING_TEX_ID) { return; // This texture is not ready yet } if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); if ( _texCoords != null && (_texCoordHandle == null || !_texCoordHandle.isValid()) ) { updateTexCoordBuffer(renderer); } Mat4d modelViewMat = new Mat4d(); cam.getViewMat4d(modelViewMat); modelViewMat.mult4(_trans.getMat4dRef()); modelViewMat.scaleCols3(_scale); Mat4d normalMat = RenderUtils.getInverseWithScale(_trans, _scale); normalMat.transpose4(); gl.glUseProgram(progHandle); gl.glUniformMatrix4fv(modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(cam.getProjMat4d()), 0); gl.glUniformMatrix4fv(normalMatVar, 1, false, RenderUtils.MarshalMat4d(normalMat), 0); gl.glUniformMatrix4fv(bindSpaceMatVar, 1, false, identMat, 0); gl.glUniformMatrix4fv(bindSpaceNorMatVar, 1, false, identMat, 0); gl.glUniform1f(cVar, Camera.C); gl.glUniform1f(fcVar, Camera.FC); gl.glUniform1i(numLightsVar, 1); gl.glUniform3fv(lightDirVar, 1, lightDir, 0); gl.glUniform1fv(lightIntVar, 1, lightInt, 0); gl.glUniform3f(ambientColorVar, 0.0f, 0.0f, 0.0f); gl.glUniform3f(specColorVar, 0.0f, 0.0f, 0.0f); gl.glUniform1f(shininessVar, 1.0f); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, textureID); gl.glUniform1i(texVar, 0); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_CLAMP_TO_EDGE); // Draw gl.glDisable(GL2GL3.GL_CULL_FACE); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, 6); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }
Example 5
Source File: OverlayTexture.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) { if (!staticInit) { initStaticBuffers(renderer); } double x = _x; double y = _y; if (_alignRight) { x = windowWidth - _x - _width; } if (!_alignBottom) { y = windowHeight - _y - _height; } GL2GL3 gl = renderer.getGL(); int textureID = renderer.getTexCache().getTexID(gl, _imageURI, _isTransparent, _isCompressed, false); if (textureID == TexCache.LOADING_TEX_ID) { return; // This texture is not ready yet } if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); gl.glUniform1i(hasTexVar, 1); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, textureID); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_CLAMP_TO_EDGE); gl.glUniform1i(texVar, 0); if (_isTransparent) { gl.glEnable(GL2GL3.GL_BLEND); gl.glBlendEquationSeparate(GL2GL3.GL_FUNC_ADD, GL2GL3.GL_MAX); gl.glBlendFuncSeparate(GL2GL3.GL_SRC_ALPHA, GL2GL3.GL_ONE_MINUS_SRC_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ONE); } // Set the size and scale in normalized (-1, 1) coordinates double normX = x / (0.5 * windowWidth) - 1; double normY = y / (0.5 * windowHeight) - 1; double normWidth = _width / (0.5 * windowWidth); double normHeight = _height / (0.5 * windowHeight); gl.glUniform2f(offsetVar, (float)normX, (float)normY); gl.glUniform2f(sizeVar, (float)normWidth, (float)normHeight); // Draw gl.glDisable(GL2GL3.GL_CULL_FACE); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, 6); gl.glEnable(GL2GL3.GL_CULL_FACE); if (_isTransparent) { gl.glDisable(GL2GL3.GL_BLEND); } }
Example 6
Source File: TexCache.java From jaamsim with Apache License 2.0 | 4 votes |
private int loadGLTexture(GL2GL3 gl, LoadingEntry le) { if (le.failed.get()) { return badTextureID; } int[] i = new int[1]; gl.glGenTextures(1, i, 0); int glTexID = i[0]; gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, glTexID); if (le.compressed) gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR ); else gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR_MIPMAP_LINEAR ); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAG_FILTER, GL2GL3.GL_LINEAR ); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT); gl.glPixelStorei(GL2GL3.GL_UNPACK_ALIGNMENT, 1); // Attempt to load to a proxy texture first, then see what happens int internalFormat = 0; if (le.hasAlpha && le.compressed) { // We do not currently support compressed textures with alpha assert(false); return badTextureID; } else if(le.hasAlpha && !le.compressed) { internalFormat = GL2GL3.GL_RGBA; } else if(!le.hasAlpha && le.compressed) { internalFormat = GL2GL3.GL_COMPRESSED_RGB_S3TC_DXT1_EXT; } else if(!le.hasAlpha && !le.compressed) { internalFormat = GL2GL3.GL_RGB; } gl.glBindBuffer(GL2GL3.GL_PIXEL_UNPACK_BUFFER, le.bufferID); gl.glUnmapBuffer(GL2GL3.GL_PIXEL_UNPACK_BUFFER); try { if (le.compressed) { gl.glCompressedTexImage2D(GL2GL3.GL_TEXTURE_2D, 0, internalFormat, le.width, le.height, 0, le.data.capacity(), 0); _renderer.usingVRAM(le.data.capacity()); } else { gl.glTexImage2D(GL2GL3.GL_TEXTURE_2D, 0, internalFormat, le.width, le.height, 0, GL2GL3.GL_BGRA, GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV, 0); _renderer.usingVRAM(le.width*le.height*4); } // Note we do not let openGL generate compressed mipmaps because it stalls the render thread really badly // in theory it could be generated in the worker thread, but not yet if (!le.compressed) gl.glGenerateMipmap(GL2GL3.GL_TEXTURE_2D); } catch (GLException ex) { // We do not have enough texture memory LogBox.renderLog(String.format("Error loading texture: %s", le.imageURI.toString())); LogBox.renderLog(String.format(" %s", ex.toString())); return badTextureID; } gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, 0); gl.glBindBuffer(GL2GL3.GL_PIXEL_UNPACK_BUFFER, 0); i[0] = le.bufferID; gl.glDeleteBuffers(1, i, 0); // Finally queue a redraw in case an asset avoided drawing this one _renderer.queueRedraw(); return glTexID; }
Example 7
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") private void renderBatch(int contextID, Renderer renderer, MeshBatch batch) { // TODO bounds // TODO size culling Material mat = _materials.get(batch.matIndex); SubMesh subMesh = _subMeshes.get(batch.meshIndex); int shaderID = mat.shaderID | Renderer.STATIC_BATCH_FLAG; GL2GL3 gl = renderer.getGL(); GL4 gl4 = renderer.getGL4(); if (!batch.vaoMaps[shaderID].containsKey(contextID)) { setupVAOForBatch(contextID, batch, renderer); } int vao = batch.vaoMaps[shaderID].get(contextID); gl.glBindVertexArray(vao); ShaderInfo si = sInfos[shaderID]; gl.glUseProgram(si.meshProgHandle); // Setup uniforms for this object\ if (mat._textureIndex != -1) { int texHandle = _textureHandles.get(mat._textureIndex); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, texHandle); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT); gl.glUniform1i(si.texVar, 0); } else { gl.glUniform4fv(si.diffuseColorVar, 1, mat._diffuseColor.toFloats(), 0); } gl.glUniform3fv(si.ambientColorVar, 1, mat._ambientColor.toFloats(), 0); gl.glUniform3fv(si.specColorVar, 1, mat._specColor.toFloats(), 0); gl.glUniform1f(si.shininessVar, (float)mat._shininess); // Actually draw it gl.glDisable(GL2GL3.GL_CULL_FACE); //gl.glDrawElements(GL2GL3.GL_TRIANGLES, subMesh._numVerts, GL2GL3.GL_UNSIGNED_INT, 0); gl4.glDrawElementsInstanced(GL2GL3.GL_TRIANGLES, subMesh._numVerts, GL2GL3.GL_UNSIGNED_INT, 0, batch.numInstances); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }
Example 8
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void renderSubMesh(SubMesh subMesh, int materialIndex, Mat4d subInstTrans, Mat4d subInstInvTrans, int contextID, Renderer renderer) { Material mat = _materials.get(materialIndex); int shaderID = mat.shaderID; GL2GL3 gl = renderer.getGL(); if (!subMesh.vaoMaps[shaderID].containsKey(contextID)) { setupVAOForSubMesh(contextID, subMesh, renderer); } int vao = subMesh.vaoMaps[shaderID].get(contextID); gl.glBindVertexArray(vao); ShaderInfo si = sInfos[shaderID]; gl.glUseProgram(si.meshProgHandle); // Setup uniforms for this object Mat4d subInstNorm = new Mat4d(subInstInvTrans); subInstNorm.transpose4(); gl.glUniformMatrix4fv(si.bindSpaceMatVar, 1, false, RenderUtils.MarshalMat4d(subInstTrans), 0); gl.glUniformMatrix4fv(si.bindSpaceNorMatVar, 1, false, RenderUtils.MarshalMat4d(subInstNorm), 0); if (mat._textureIndex != -1) { int texHandle = _textureHandles.get(mat._textureIndex); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, texHandle); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT); gl.glUniform1i(si.texVar, 0); } else { gl.glUniform4fv(si.diffuseColorVar, 1, mat._diffuseColor.toFloats(), 0); } gl.glUniform3fv(si.ambientColorVar, 1, mat._ambientColor.toFloats(), 0); gl.glUniform3fv(si.specColorVar, 1, mat._specColor.toFloats(), 0); gl.glUniform1f(si.shininessVar, (float)mat._shininess); if (mat._transType != MeshData.NO_TRANS) { gl.glBlendEquationSeparate(GL2GL3.GL_FUNC_ADD, GL2GL3.GL_MAX); if (mat._transType != MeshData.DIFF_ALPHA_TRANS) { gl.glBlendColor((float)mat._transColour.r, (float)mat._transColour.g, (float)mat._transColour.b, (float)mat._transColour.a); } if (mat._transType == MeshData.A_ONE_TRANS) { gl.glBlendFuncSeparate(GL2GL3.GL_CONSTANT_ALPHA, GL2GL3.GL_ONE_MINUS_CONSTANT_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ZERO); } else if (mat._transType == MeshData.RGB_ZERO_TRANS) { gl.glBlendFuncSeparate(GL2GL3.GL_ONE_MINUS_CONSTANT_COLOR, GL2GL3.GL_CONSTANT_COLOR, GL2GL3.GL_ONE, GL2GL3.GL_ZERO); } else if (mat._transType == MeshData.DIFF_ALPHA_TRANS) { gl.glBlendFuncSeparate(GL2GL3.GL_SRC_ALPHA, GL2GL3.GL_ONE_MINUS_SRC_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ZERO); } else { assert(false); // Unknown transparency type } } // Actually draw it //gl.glPolygonMode(GL2GL3.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); gl.glDisable(GL2GL3.GL_CULL_FACE); if (flattenBuffers) { gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, subMesh._numVerts); } else { gl.glDrawElements(GL2GL3.GL_TRIANGLES, subMesh._numVerts, GL2GL3.GL_UNSIGNED_INT, 0); } gl.glEnable(GL2GL3.GL_CULL_FACE); // Reset the blend state if (mat._transType != MeshData.NO_TRANS) { gl.glBlendEquationSeparate(GL2GL3.GL_FUNC_ADD, GL2GL3.GL_MAX); gl.glBlendFuncSeparate(GL2GL3.GL_SRC_ALPHA, GL2GL3.GL_ONE_MINUS_SRC_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ONE); } gl.glBindVertexArray(0); }
Example 9
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void initBatchUniforms(Renderer renderer, Mat4d modelViewMat, Mat4d projMat, Mat4d viewMat, Mat4d normalMat) { GL2GL3 gl = renderer.getGL(); lightsDirScratch[0].mult4(viewMat, lightsDir[0]); lightsDirScratch[1].mult4(viewMat, lightsDir[1]); lightsDirFloats[0] = (float)lightsDirScratch[0].x; lightsDirFloats[1] = (float)lightsDirScratch[0].y; lightsDirFloats[2] = (float)lightsDirScratch[0].z; lightsDirFloats[3] = (float)lightsDirScratch[1].x; lightsDirFloats[4] = (float)lightsDirScratch[1].y; lightsDirFloats[5] = (float)lightsDirScratch[1].z; BatchShaderInfo si = bsInfo; gl.glUseProgram(si.progHandle); gl.glUniformMatrix4fv(si.modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(si.projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0); gl.glUniformMatrix4fv(si.normalMatVar, 1, false, RenderUtils.MarshalMat4d(normalMat), 0); gl.glUniform3fv(si.lightDirVar, 2, lightsDirFloats, 0); gl.glUniform1fv(si.lightIntVar, 2, lightsInt, 0); gl.glUniform1i(si.numLightsVar, numLights); gl.glUniform1f(si.cVar, Camera.C); gl.glUniform1f(si.fcVar, Camera.FC); int[] sampIDs = new int[_textureHandles.size()]; for (int i = 0; i < sampIDs.length; ++i) { sampIDs[i] = i; } if (sampIDs.length > 0) { gl.glUniform1iv(si.diffTexVar, sampIDs.length, sampIDs, 0); } for (int i = 0; i < _textureHandles.size(); ++i) { gl.glActiveTexture(GL2GL3.GL_TEXTURE0+i); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, _textureHandles.get(i)); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT); } }
Example 10
Source File: GraphicsMemManager.java From jaamsim with Apache License 2.0 | 4 votes |
public TexHandle allocateTexture(int width, int height, GL2GL3 gl) { int[] i = new int[1]; gl.glGenTextures(1, i, 0); int glTexID = i[0]; gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, glTexID); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MIN_FILTER, GL2GL3.GL_LINEAR_MIPMAP_LINEAR ); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_MAG_FILTER, GL2GL3.GL_LINEAR ); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_CLAMP_TO_EDGE); renderer.usingVRAM(width*height*4); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, 0); TexHandle h = new TexHandle(glTexID, width, height, this); allocatedTextures.add(h); return h; }