Applied OPENGL2 patch from James Fry

This commit is contained in:
codeanticode
2011-05-26 11:51:21 +00:00
parent 4b13bad327
commit 6e21004481
3 changed files with 35 additions and 41 deletions
@@ -178,8 +178,7 @@ class PFontTexture implements PConstants {
return glyphTexinfos[n];
}
// It was inside PFont.Glyph
// Adds this glyph to the opengl texture in PFont.
protected void addToTexture(int idx, PFont.Glyph glyph) {
// Converting the pixels array from the PImage into a valid RGBA array for OpenGL.
@@ -200,7 +199,7 @@ class PFontTexture implements PConstants {
}
}
// Is there room for this glyph on the current line?
// Is there room for this glyph in the current line?
if (offsetX + glyph.width> textures[currentTex].glWidth) {
// No room, go to the next line:
offsetX = 0;
@@ -211,7 +210,7 @@ class PFontTexture implements PConstants {
boolean resized = false;
if (offsetY + lineHeight > textures[currentTex].glHeight) {
// We run out of space in the current texture, we add a new texture:
// We run out of space in the current texture, so we add a new texture:
resized = addTexture();
if (resized) {
// Because the current texture has been resized, we need to
@@ -238,7 +237,6 @@ class PFontTexture implements PConstants {
setTexture(lastTex);
}
//PApplet.println(glyph.width * glyph.height + " " + rgba.length);
textures[currentTex].setTexels(offsetX, offsetY, glyph.width, glyph.height, rgba);
TextureInfo tinfo = new TextureInfo(currentTex, offsetX, offsetY + glyph.height, glyph.width, -glyph.height);
@@ -666,10 +666,6 @@ public class PGraphicsOpenGL2 extends PGraphics {
if (context == null) {
initPrimary();
} else {
// The following three lines are a fix for Bug #1176
// http://dev.processing.org/bugs/show_bug.cgi?id=1176
context.destroy();
context = drawable.createContext(null);
reapplySettings();
}
} else {
@@ -3379,7 +3375,6 @@ public class PGraphicsOpenGL2 extends PGraphics {
if (textTex == null) {
textTex = new PFontTexture(parent, textFont, maxTextureSize, maxTextureSize);
textFont.setCache(this, textTex);
textTex.addAllGlyphsToTexture();
}
textTex.setFirstTexture();
@@ -6694,8 +6689,8 @@ public class PGraphicsOpenGL2 extends PGraphics {
profile = null;
profile = GLProfile.getDefault();
//profile = GLProfile.get(GLProfile.GL2ES1);
//profile = GLProfile.getDefault();
profile = GLProfile.get(GLProfile.GL2ES1);
//profile = GLProfile.get(GLProfile.GL4bc);
//profile = GLProfile.getMaxProgrammable();
pipeline = FIXED;
@@ -6754,9 +6749,6 @@ public class PGraphicsOpenGL2 extends PGraphics {
GLDrawableFactory factory = GLDrawableFactory.getFactory(profile);
drawable = factory.createGLDrawable(win);
context = drawable.createContext(null);
PApplet.println("PROFILE:\n" + profile);
PApplet.println("CONTEXT:\n" + context);
}
@@ -40,8 +40,7 @@ public class PTexture implements PConstants {
public int width, height;
protected PApplet parent;
protected PGraphicsOpenGL2 ogl;
protected GL gl;
protected PGraphicsOpenGL2 ogl;
// These are public but use at your own risk!
public int glID;
@@ -95,7 +94,6 @@ public class PTexture implements PConstants {
this.height = height;
ogl = (PGraphicsOpenGL2)parent.g;
gl = ogl.gl;
glID = 0;
@@ -123,8 +121,7 @@ public class PTexture implements PConstants {
public PTexture(PApplet parent, String filename, Object params) {
this.parent = parent;
ogl = (PGraphicsOpenGL2)parent.g;
gl = ogl.gl;
ogl = (PGraphicsOpenGL2)parent.g;
glID = 0;
@@ -255,15 +252,15 @@ public class PTexture implements PConstants {
createTexture(width, height);
}
gl.glEnable(glTarget);
gl.glBindTexture(glTarget, glID);
getGl().glEnable(glTarget);
getGl().glBindTexture(glTarget, glID);
if (usingMipmaps) {
if (PGraphicsOpenGL2.mipmapGeneration) {
// Automatic mipmap generation.
int[] rgbaPixels = new int[w * h];
convertToRGBA(pixels, rgbaPixels, format, w, h);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
getGl().glTexParameteri(GL.GL_TEXTURE_2D, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
setTexels(x, y, w, h, rgbaPixels);
} else {
// TODO: Manual mipmap generation.
@@ -276,8 +273,8 @@ public class PTexture implements PConstants {
setTexels(x, y, w, h, rgbaPixels);
}
gl.glBindTexture(glTarget, 0);
gl.glDisable(glTarget);
getGl().glBindTexture(glTarget, 0);
getGl().glDisable(glTarget);
}
@@ -418,13 +415,13 @@ public class PTexture implements PConstants {
// Bind/unbind
public void bind() {
gl.glEnable(glTarget);
gl.glBindTexture(glTarget, glID);
getGl().glEnable(glTarget);
getGl().glBindTexture(glTarget, glID);
}
public void unbind() {
gl.glEnable(glTarget);
gl.glBindTexture(glTarget, 0);
getGl().glEnable(glTarget);
getGl().glBindTexture(glTarget, 0);
}
////////////////////////////////////////////////////////////
@@ -704,22 +701,22 @@ public class PTexture implements PConstants {
usingMipmaps = glMinFilter == GL.GL_LINEAR_MIPMAP_LINEAR;
gl.glEnable(glTarget);
getGl().glEnable(glTarget);
glID = ogl.createGLResource(PGraphicsOpenGL2.GL_TEXTURE_OBJECT);
gl.glBindTexture(glTarget, glID);
gl.glTexParameteri(glTarget, GL.GL_TEXTURE_MIN_FILTER, glMinFilter);
gl.glTexParameteri(glTarget, GL.GL_TEXTURE_MAG_FILTER, glMagFilter);
gl.glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_S, glWrapS);
gl.glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_T, glWrapT);
getGl().glBindTexture(glTarget, glID);
getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MIN_FILTER, glMinFilter);
getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_MAG_FILTER, glMagFilter);
getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_S, glWrapS);
getGl().glTexParameteri(glTarget, GL.GL_TEXTURE_WRAP_T, glWrapT);
// This array is used to make sure that the texture doesn't contain any
// garbage.
int[] initArray = new int[glWidth * glHeight];
java.util.Arrays.fill(initArray, 0, glWidth * glHeight, 0x00000000);
gl.glTexImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(initArray));
gl.glBindTexture(glTarget, 0);
gl.glDisable(glTarget);
getGl().glTexImage2D(glTarget, 0, glFormat, glWidth, glHeight, 0, GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(initArray));
getGl().glBindTexture(glTarget, 0);
getGl().glDisable(glTarget);
flippedX = false;
flippedY = false;
@@ -778,7 +775,7 @@ public class PTexture implements PConstants {
}
protected void setTexels(int level, int x, int y, int w, int h, int[] pix) {
gl.glTexSubImage2D(glTarget, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pix));
getGl().glTexSubImage2D(glTarget, 0, x, y, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(pix));
}
protected void copyObject(PTexture src) {
@@ -791,7 +788,6 @@ public class PTexture implements PConstants {
parent = src.parent;
ogl = src.ogl;
gl = src.gl;
glID = src.glID;
glTarget = src.glTarget;
@@ -906,6 +902,14 @@ public class PTexture implements PConstants {
}
}
///////////////////////////////////////////////////////////////////////////
// Utilities
protected GL getGl() {
return ogl.gl;
}
///////////////////////////////////////////////////////////////////////////