/** * Makes the supplied shader the current shader, flushing any previous shader. */ public boolean useShader(GLShader shader) { if (curShader == shader) return false; checkGLError("useShader"); flush(true); curShader = shader; return true; }
/** Called before each primitive to update the current color. */ public void prepare(int tex, int tint, boolean justActivated) { ctx.checkGLError("textureShader.prepare start"); boolean stateChanged = (tex != lastTex); if (!justActivated && stateChanged) { GLShader.this.flush(); ctx.checkGLError("textureShader.prepare flush"); } if (stateChanged) { lastTex = tex; ctx.checkGLError("textureShader.prepare end"); } if (justActivated) { ctx.activeTexture(GL20.GL_TEXTURE0); uTexture.bind(0); } }
@Override public void flush() { super.flush(); if (vertices.position() == 0) return; ctx.checkGLError("Shader.flush"); if (delayedBinding) { // see comments in activate() bindAttribsBufs(); ctx.checkGLError("Shader.flush bind"); } vertices.send(GL20.GL_ARRAY_BUFFER, GL20.GL_STREAM_DRAW); int elems = elements.send(GL20.GL_ELEMENT_ARRAY_BUFFER, GL20.GL_STREAM_DRAW); ctx.checkGLError("Shader.flush BufferData"); elements.drawElements(GL20.GL_TRIANGLES, elems); ctx.checkGLError("Shader.flush DrawElements"); }
public void flush(boolean deactivate) { if (curShader != null) { checkGLError("flush()"); curShader.flush(); if (deactivate) { curShader.deactivate(); curShader = null; } } }
public void bindFramebuffer(int fbuf, int width, int height) { if (fbuf != lastFramebuffer) { flush(true); // flush and deactivate any shader rendering to the old framebuffer checkGLError("bindFramebuffer"); bindFramebufferImpl(lastFramebuffer = fbuf, curFbufWidth = width, curFbufHeight = height); } }
@Override public void activate(int fbufWidth, int fbufHeight) { prog.bind(); uScreenSize.bind(fbufWidth, fbufHeight); // certain graphics cards (I'm looking at you, Intel) exhibit broken behavior if we bind our // attributes once during activation, so for those cards we bind every time in flush() if (!delayedBinding) bindAttribsBufs(); ctx.checkGLError("Shader.activate bind"); }
ctx.checkGLError("Attached vertex shader"); ctx.checkGLError("Attached fragment shader");