Java Code Examples for com.jogamp.opengl.GLContext#CONTEXT_NOT_CURRENT
The following examples show how to use
com.jogamp.opengl.GLContext#CONTEXT_NOT_CURRENT .
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: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * Update the glyph textures on the shared GL context. The update will occur * via the GlyphManagerOpenGLController object, which checks its * GlyphManager to see if anything has changed, and if so, copies the * appropriate data to the open GL textures. * * @param glCurrent The GL context to switch back to after updating the * shared context. */ public static void updateGlyphTextureController(final GL3 glCurrent) { if (Utilities.isMac()) { glyphTextureController.update(glCurrent); } else { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } glyphTextureController.update(gl); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } }
Example 2
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * The simple icon shader draws non-interactive icons. * * @param glCurrent the current OpenGL context. * @param colorTarget * @param colorShaderName * @param iconShaderName * @param iconTarget * @return the id of the icon shader. * @throws IOException if an error occurs while reading the shader source. */ public static int getSimpleIconShader(final GL3 glCurrent, final int colorTarget, final String colorShaderName, final int iconTarget, final String iconShaderName) throws IOException { if (simpleIconShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/SimpleIcon.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/SimpleIcon.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/SimpleIcon.fs"); simpleIconShader = GLTools.loadShaderSourceWithAttributes(gl, "SimpleIcon", vp, gp, fp, colorTarget, colorShaderName, iconTarget, iconShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return simpleIconShader; }
Example 3
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * The vertex icon shader draws icons for vertices on the graph. * * @param glCurrent the current OpenGL context. * @param colorTarget * @param colorShaderName * @param iconShaderName * @param iconTarget * @return the id of the icon shader. * @throws IOException if an error occurs while reading the shader source. */ public static int getVertexIconShader(final GL3 glCurrent, final int colorTarget, final String colorShaderName, final int iconTarget, final String iconShaderName) throws IOException { if (vertexIconShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/VertexIcon.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/VertexIcon.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/VertexIcon.fs"); vertexIconShader = GLTools.loadShaderSourceWithAttributes(gl, "VertexIcon", vp, gp, fp, colorTarget, colorShaderName, iconTarget, iconShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return vertexIconShader; }
Example 4
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * Lines close to the camera are drawn as triangles to provide perspective. * * @param glCurrent the current OpenGL context. * @param colotTarget * @param colorShaderName * @param connectionInfoTarget * @param connectionInfoShaderName * @return the id of the line shader. * @throws IOException if an error occurs while reading the shader source. */ public static int getLineShader(final GL3 glCurrent, final int colotTarget, final String colorShaderName, final int connectionInfoTarget, final String connectionInfoShaderName) throws IOException { if (lineShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Line.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Line.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Line.fs"); lineShader = GLTools.loadShaderSourceWithAttributes(gl, "Line", vp, gp, fp, colotTarget, colorShaderName, connectionInfoTarget, connectionInfoShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return lineShader; }
Example 5
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * Lines further away don't look good as triangles (too many artifacts), so * distant lines are drawn as lines (which is more efficient anyway). * * @param glCurrent the current OpenGL context. * @param colotTarget * @param colorShaderName * @param connectionInfoTarget * @param connectionInfoShaderName * @return the id of the line shader. * @throws IOException if an error occurs while reading the shader source. */ public static int getLineLineShader(final GL3 glCurrent, final int colotTarget, final String colorShaderName, final int connectionInfoTarget, final String connectionInfoShaderName) throws IOException { if (lineLineShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Line.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/LineLine.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/LineLine.fs"); lineLineShader = GLTools.loadShaderSourceWithAttributes(gl, "LineLine", vp, gp, fp, colotTarget, colorShaderName, connectionInfoTarget, connectionInfoShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return lineLineShader; }
Example 6
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * Lines close to the camera are drawn as triangles to provide perspective. * * @param glCurrent the current OpenGL context. * @param colorTarget * @param colorShaderName * @param loopInfoTarget * @param loopInfoShaderName * @return the id of the loop shader. * @throws IOException if an error occurs while reading the shader source. */ public static int getLoopShader(final GL3 glCurrent, final int colorTarget, final String colorShaderName, final int loopInfoTarget, final String loopInfoShaderName) throws IOException { if (loopShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Loop.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Loop.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Loop.fs"); loopShader = GLTools.loadShaderSourceWithAttributes(gl, "Loop", vp, gp, fp, colorTarget, colorShaderName, loopInfoTarget, loopInfoShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return loopShader; }
Example 7
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * Each character is drawn individually. * * @param glCurrent the current OpenGL context. * @param labelFloatsTarget The ID of the float buffer in the label batch * @param labelFloatsShaderName the name of the float buffer in the shader. * @param labelIntsTarget The ID of the int buffer in the label batch * @param labelIntsShaderName the name of the int buffer in the shader. * @return the id of the shader. * @throws IOException if an error occurs while reading the shader source. */ public static int getNodeLabelShader(final GL3 glCurrent, final int labelFloatsTarget, final String labelFloatsShaderName, final int labelIntsTarget, final String labelIntsShaderName) throws IOException { if (nodeLabelShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/NodeLabel.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Label.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Label.fs"); nodeLabelShader = GLTools.loadShaderSourceWithAttributes(gl, "Label", vp, gp, fp, labelFloatsTarget, labelFloatsShaderName, labelIntsTarget, labelIntsShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return nodeLabelShader; }
Example 8
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * Each character is drawn individually. * * @param glCurrent the current OpenGL context. * @param labelFloatsTarget The ID of the float buffer in the label batch * @param labelFloatsShaderName the name of the float buffer in the shader * source. * @param labelIntsTarget The ID of the int buffer in the label batch * @param labelIntsShaderName the name of the int buffer in the shader * source. * @return the name of the shader. * @throws IOException if an error occurs while reader the shader source. */ public static int getConnectionLabelShader(final GL3 glCurrent, final int labelFloatsTarget, final String labelFloatsShaderName, final int labelIntsTarget, final String labelIntsShaderName) throws IOException { if (connectionLabelShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/ConnectionLabel.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Label.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Label.fs"); connectionLabelShader = GLTools.loadShaderSourceWithAttributes(gl, "Label", vp, gp, fp, labelFloatsTarget, labelFloatsShaderName, labelIntsTarget, labelIntsShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return connectionLabelShader; }
Example 9
Source File: SharedDrawable.java From constellation with Apache License 2.0 | 6 votes |
/** * The blaze shader draws visual attachments to the nodes. * * @param glCurrent the current OpenGL context. * @param colorTarget * @param colorShaderName the name of the color buffer in the shader source. * @param blazeInfoTarget * @param blazeInfoShaderName the name of the int buffer in the shader * source. * @return the name of the shader. * @throws IOException if an error occurs while reader the shader source. */ public static int getBlazeShader(final GL3 glCurrent, final int colorTarget, final String colorShaderName, final int blazeInfoTarget, final String blazeInfoShaderName) throws IOException { if (blazeShader == 0) { glCurrent.getContext().release(); try { final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException(COULD_NOT_CONTEXT_CURRENT); } final String vp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Blaze.vs"); final String gp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Blaze.gs"); final String fp = GLTools.loadFile(GLVisualProcessor.class, "shaders/Blaze.fs"); blazeShader = GLTools.loadShaderSourceWithAttributes(gl, "Blaze", vp, gp, fp, colorTarget, colorShaderName, blazeInfoTarget, blazeInfoShaderName, ShaderManager.FRAG_BASE, FRAG_COLOR); } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } } return blazeShader; }
Example 10
Source File: OpenGLGFXCMD.java From sagetv with Apache License 2.0 | 5 votes |
private void unloadImage(GL2 gl, int handle) { int texturet[] = (int []) imageMap.get(new Integer(handle)); // This can happen when we unload an image and then notify the server about it being unloaded...this results in a callback made to // us to tell us to unload the image because of how that code path works on the server. if (texturet != null) { if(inframe==false) { if(pbuffer.getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT) { System.out.println("Couldn't make pbuffer current?"); return; } gl = pbuffer.getGL().getGL2(); } if(texturet.length==4) // fb object { gl.glDeleteFramebuffers(1, texturet, 0); gl.glDeleteTextures(1, texturet, 1); } else { imageCacheSize -= ((Integer) imageMapSizes.get(new Integer(handle))).intValue(); gl.glDeleteTextures(1, texturet, 0); } if(inframe==false) { pbuffer.getContext().release(); } } imageMap.remove(new Integer(handle)); imageMapSizes.remove(new Integer(handle)); myConn.clearImageAccess(handle); }
Example 11
Source File: GraphRenderable.java From constellation with Apache License 2.0 | 4 votes |
/** * Make our GL context current. It may not be as the glyph rendering may * have switched it. The JOGL way to do this is to switch contexts multiple * times in the one frame. Chapter 2 of 'Pro Java 6 3D Game Development' has * a section that explains: * * " * This coding approach means that the context is current for the entire * duration of the thread's execution. This causes no problems on most * platforms (e.g. it's fine on Windows), but unfortunately there's an issue * when using X11. On X11 platforms, a AWT lock is created between the * GLContext.makeCurrent() and GLContext.release() calls, stopping mouse and * keyboard input from being processed. " * * The JOGL model of the event listener's display being called in response * to input events, as opposed to a continuous render loop, means that this * lock may be responsible for the glyph context being current when the * other batchers are making their draw calls. * * This 'fix' was tested on El Capitan 10.11 and could be breaking on other * versions. Testing required. * * @param gl */ private void makeContentCurrent(GL3 gl) { GLContext context = gl.getContext(); try { while (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT) { Thread.sleep(100); } } catch (InterruptedException ex) { final String msg = "Unable to switch GL context. This code should only be run " + "on OSX and may need to be restricted to specific versions " + "where label rendering is broken. " + "Please inform CONSTELLATION support, including the text of this message.\n\n" + ex.getMessage(); Logger.getLogger(GraphRenderable.class .getName()).log(Level.SEVERE, msg, ex); final InfoTextPanel itp = new InfoTextPanel(msg); final NotifyDescriptor.Message nd = new NotifyDescriptor.Message(itp, NotifyDescriptor.ERROR_MESSAGE); nd.setTitle("Graph Render Error"); DialogDisplayer.getDefault().notify(nd); } }
Example 12
Source File: GLTools.java From constellation with Apache License 2.0 | 4 votes |
/** * Load an array of icon textures. * <p> * We assume that the textures being loaded are icons, and therefore are * roughly the same size (with a maximum of (width,height). * <p> * The array is limited to GL_MAX_ARRAY_TEXTURE_LAYERS layers. This can be * fairly low (512 on low-end systems), so icons are loaded into an 8x8 icon * matrix in each layer, thus giving a maximum of 512x8x8=32768 icons. (This * assumes that GL_MAX_3D_TEXTURE_SIZE is big enough to take that many * pixels. With the current icon size of 256x256, then * GL_MAX_3D_TEXTURE_SIZE must be at least 2048.) * <p> * Icons that are smaller than (width,height) are offset so they are * centred, so the shader can just draw the icons without worrying about * where in the texture they are. * <p> * It appears that the images must have a row length that is a multiple of * four. This is probably due to the particular format we're using, and * could probably be worked around, but the simple fix is to check your row * length. * * @param glCurrent the current OpenGL context. * @param icons a list of icons that need to added to the buffer. * @param width the width of each icon. * @param height the height of each icon. * * @return the id of the texture buffer. */ public static int loadSharedIconTextures(final GL3 glCurrent, final List<ConstellationIcon> icons, final int width, final int height) { final int[] v = new int[1]; glCurrent.glGetIntegerv(GL3.GL_MAX_ARRAY_TEXTURE_LAYERS, v, 0); final int maxIcons = v[0] * 64; if (icons.size() > maxIcons) { System.out.printf("****\n**** Warning: nIcons %d > GL_MAX_ARRAY_TEXTURE_LAYERS %d\n****\n", icons.size(), maxIcons); } final int nIcons = Math.min(icons.size(), maxIcons); glCurrent.getContext().release(); final GL3 gl = (GL3) SharedDrawable.getSharedAutoDrawable().getGL(); final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException("Could not make texture context current."); } final int[] textureName = new int[1]; try { textureName[0] = SharedDrawable.getIconTextureName(); gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, textureName[0]); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR); gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, GL.GL_RGBA, width * 8, height * 8, (nIcons + 63) / 64, 0, GL.GL_RGBA, GL3.GL_UNSIGNED_BYTE, null); final Iterator<ConstellationIcon> iconIterator = icons.iterator(); for (int i = 0; i < nIcons; i++) { final ConstellationIcon icon = iconIterator.next(); try { BufferedImage iconImage = icon.buildBufferedImage(); if (iconImage != null) { // Appears to be a bug in JOGL where texture provider for PNG files does not flip the texture. final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), iconImage, false); if (data.getWidth() > width || data.getHeight() > height) { throw new RenderException(String.format("Image %d is too large (width %d>%d, height %d>%d)", i, data.getWidth(), width, data.getHeight(), height)); } // Offset each icon into an 8x8 matrix. // There are multiple icons in each // Allow for icons that are smaller than width,height. final int xoffset = (width - data.getWidth()) / 2 + (width * (i & 7)); final int yoffset = (height - data.getHeight()) / 2 + (height * ((i >>> 3) & 7)); final int zoffset = i >>> 6; gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, xoffset, yoffset, zoffset, data.getWidth(), data.getHeight(), 1, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, data.getBuffer()); data.destroy(); } } catch (final RuntimeException ex) { System.out.printf("##%n## GLTools.loadTextures() icon %d throwable: %s%n##%n", i, ex); LOGGER.log(Level.SEVERE, null, ex); } } } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } return textureName[0]; }
Example 13
Source File: OpenGLVideoRenderer.java From sagetv with Apache License 2.0 | 4 votes |
private void createVideo() { //System.out.println("createvideo"); if(owner.isInFrame() || (owner.getPbuffer().getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT)) { if(!owner.isInFrame()) { System.out.println("Couldn't make pbuffer current?"); return; } else { System.out.println("Create video while already in frame"); } } GL2 gl = owner.getPbuffer().getGL().getGL2(); System.out.println("createvideo width: "+videowidth+" height: "+videoheight); if(videot!=null) gl.glDeleteTextures(3, videot, 0); // try { // closeVideo0(); // } catch(Throwable t) {} if(pureNativeMode) { videot = null; videoMode = 0; // release resources and force reallocation when we leave native mode try { createVideo0(videowidth, videoheight); } catch(Throwable t) {} } else { byte img[] = new byte[videowidth*videoheight*2]; videot = new int[3]; gl.glGenTextures(3, videot, 0); gl.glEnable(gl.GL_TEXTURE_RECTANGLE); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[0]); if(MiniClient.MAC_OS_X) { gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, 0x85BC/*GL_TEXTURE_STORAGE_HINT_APPLE*/, 0x85Be/*GL_STORAGE_CACHED_APPLE*/); gl.glPixelStorei(0x85B2/*GL_UNPACK_CLIENT_STORAGE_APPLE*/, gl.GL_TRUE); } gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 1, videowidth, videoheight, 0, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img)); gl.glDisable(gl.GL_TEXTURE_RECTANGLE); gl.glEnable(gl.GL_TEXTURE_RECTANGLE); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[1]); if(MiniClient.MAC_OS_X) { gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, 0x85BC/*GL_TEXTURE_STORAGE_HINT_APPLE*/, 0x85Be/*GL_STORAGE_CACHED_APPLE*/); gl.glPixelStorei(0x85B2/*GL_UNPACK_CLIENT_STORAGE_APPLE*/, gl.GL_TRUE); } gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 1, videowidth/2, videoheight/2, 0, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img)); gl.glDisable(gl.GL_TEXTURE_RECTANGLE); gl.glEnable(gl.GL_TEXTURE_RECTANGLE); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[2]); if(MiniClient.MAC_OS_X) { gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, 0x85BC/*GL_TEXTURE_STORAGE_HINT_APPLE*/, 0x85Be/*GL_STORAGE_CACHED_APPLE*/); gl.glPixelStorei(0x85B2/*GL_UNPACK_CLIENT_STORAGE_APPLE*/, gl.GL_TRUE); } gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 1, videowidth/2, videoheight/2, 0, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img)); gl.glDisable(gl.GL_TEXTURE_RECTANGLE); } if(!owner.isInFrame()) owner.getPbuffer().getContext().release(); }
Example 14
Source File: OpenGLVideoRenderer.java From sagetv with Apache License 2.0 | 4 votes |
private void updateVideo(int frametype) { if(owner.isInFrame() || (owner.getPbuffer().getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT)) { if(!owner.isInFrame()) { System.out.println("Couldn't make pbuffer current?"); return; } else { System.out.println("update video while already in frame"); } } GL2 gl = owner.getPbuffer().getGL().getGL2(); if(pureNativeMode) { try { updateVideo0(); } catch(Throwable t) {} } else { //System.out.println("20,20 pixel: "+videobuffer.get(20*720+20)); //System.out.println(" width: "+videowidth+" height: "+videoheight); gl.glEnable(gl.GL_TEXTURE_RECTANGLE); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[0]); gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, videoy); gl.glTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, videowidth, videoheight, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, videobuffer); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[1]); gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, videou); gl.glTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, videowidth/2, videoheight/2, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, videobuffer); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, videot[2]); gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, videov); gl.glTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, videowidth/2, videoheight/2, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, videobuffer); gl.glPixelStorei(gl.GL_UNPACK_SKIP_PIXELS, 0); gl.glDisable(gl.GL_TEXTURE_RECTANGLE); gl.glFlush(); } if(!owner.isInFrame()) owner.getPbuffer().getContext().release(); }
Example 15
Source File: OpenGLGFXCMD.java From sagetv with Apache License 2.0 | 4 votes |
private void initpbuffer() { GL2 gl; System.out.println("initpbuffer"); osdwidth=newosdwidth; osdheight=newosdheight; GLCapabilities caps = new GLCapabilities(null); caps.setHardwareAccelerated(true); caps.setDoubleBuffered(false); caps.setAlphaBits(8); caps.setRedBits(8); caps.setGreenBits(8); caps.setBlueBits(8); caps.setDepthBits(0); caps.setFBO(false); System.out.println("initpbuffer2"); if (!GLDrawableFactory.getFactory(caps.getGLProfile()).canCreateGLPbuffer(null, caps.getGLProfile())) { throw new GLException("pbuffers unsupported"); } if(pbuffer!=null) pbuffer.destroy(); System.out.println("initpbuffer3"); pbuffer = GLDrawableFactory.getFactory(caps.getGLProfile()).createOffscreenAutoDrawable(null, caps, null, osdwidth, osdheight ); pbuffer.setContext(pbuffer.createContext(c.getContext()), true); //pbuffer.setContext(c.getContext(), false); System.out.println("initpbuffer4: pbuffers is null? " + (pbuffer==null)); if(pbuffer.getContext().makeCurrent()==GLContext.CONTEXT_NOT_CURRENT) { System.out.println("Couldn't make pbuffer current?"); return; } System.out.println("initpbuffer5"); gl = pbuffer.getGL().getGL2(); gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.0f); gl.glClear( gl.GL_COLOR_BUFFER_BIT); gl.glViewport(0, 0, osdwidth, osdheight); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0,osdwidth,0,osdheight,-1.0,1.0); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); // TODO: look into reusing same texture like OSX version... if(osdt!=null) gl.glDeleteTextures(1, osdt, 0); osdt = new int[1]; byte img[] = new byte[osdwidth*osdheight*4]; gl.glGenTextures(1, osdt, 0); gl.glEnable(gl.GL_TEXTURE_RECTANGLE); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE,osdt[0]); gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameteri(gl.GL_TEXTURE_RECTANGLE, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR); gl.glTexImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 4, osdwidth, osdheight, 0, gl.GL_BGRA, bigendian ? gl.GL_UNSIGNED_INT_8_8_8_8_REV : gl.GL_UNSIGNED_BYTE, java.nio.ByteBuffer.wrap(img)); gl.glEnable(gl.GL_TEXTURE_RECTANGLE); gl.glBindTexture(gl.GL_TEXTURE_RECTANGLE, osdt[0]); gl.glCopyTexSubImage2D(gl.GL_TEXTURE_RECTANGLE, 0, 0, 0, 0, 0, osdwidth, osdheight); gl.glDisable(gl.GL_TEXTURE_RECTANGLE); System.out.println("initpbuffer6"); pbuffer.getContext().release(); System.out.println("initpbuffer7"); }