X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FOpenGL.java;h=b403bdfe9d27c6618289fbf5883c6000c27b959f;hb=e2dedbcad71fdf6df74abe5c43516a4d88d145d3;hp=6e89350232d9c246b52bde1034cdb44d1e90d967;hpb=42da60bd167403eccc3466575772819007388cfd;p=org.ibex.core.git diff --git a/src/org/xwt/plat/OpenGL.java b/src/org/xwt/plat/OpenGL.java index 6e89350..b403bdf 100644 --- a/src/org/xwt/plat/OpenGL.java +++ b/src/org/xwt/plat/OpenGL.java @@ -11,6 +11,7 @@ abstract class OpenGL { boolean hasRectangularTextures() { return rectangularTextures; } int maxTexSize; int maxRectTexSize; + float glVersion; String version; String renderer; String vendor; @@ -26,27 +27,26 @@ abstract class OpenGL { return 1.1f; // just a guess } } - // This MUST be called after OpenGL is instansiated (and activateSharedContext is functioning) + + // This MUST be called after OpenGL is instansiated (and activateSharedInterpreter is functioning) public void init() throws NotSupportedException { natInit(); - float v = parseVersion(version); - // FIXME: enable linear filtering for OpenGL >= 1.2 - // If we disable linear filtering (and therefor GL_CLAMP_TO_EDGE) we could probably get by with less - if(v < 1.1) throw new NotSupportedException("OpenGL 1.1 or greater is required. (you have: " + version +" - " + v + ")"); + glVersion = parseVersion(version); + if(glVersion < 1.1) throw new NotSupportedException("OpenGL 1.1 or greater is required. (you have: " + version +" - " + glVersion + ")"); if(pretendToBeACrappyVideoCard) { maxTexSize = 512; maxRectTexSize = 0; rectangularTextures = false; } - Log.log(this,"Renderer: " + renderer); - Log.log(this,"Version: " + version); - Log.log(this,"Vendor: " + vendor); - Log.log(this,"Rectangular textures: " + (rectangularTextures ? "supported" : "unsupported")); - Log.log(this,"Max texture size: " + maxTexSize); - Log.log(this,"Max rectangular texture size: " + maxRectTexSize); + Log.info(this,"Renderer: " + renderer); + Log.info(this,"Version: " + version); + Log.info(this,"Vendor: " + vendor); + Log.info(this,"Rectangular textures: " + (rectangularTextures ? "supported" : "unsupported")); + Log.info(this,"Max texture size: " + maxTexSize); + Log.info(this,"Max rectangular texture size: " + maxRectTexSize); } - protected abstract void activateSharedContext(); + protected abstract void activateSharedInterpreter(); public static class NotSupportedException extends Exception { public NotSupportedException(String s) { super(s); } @@ -66,7 +66,7 @@ abstract class OpenGL { } // This should activate the drawing context and prepare the double buffer for drawing - protected abstract void activateContext(); + protected abstract void activateInterpreter(); protected static native void drawableInit(int w, int h); @@ -74,47 +74,84 @@ abstract class OpenGL { public native void setClip(int x, int y, int x2, int y2); public native void resetClip(); - public native void fillRect(int x, int y, int x2, int y2, int color); public native void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); public void drawString(String font, String text, int x, int y, int color) { //System.out.println("drawString(): " + text); } - - public void drawPicture(org.xwt.Picture source, int x, int y) { - activateContext(); - GLPicture p = (GLPicture) source; - p.draw(x,y); + + public void drawGlyph(org.xwt.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) { + drawPicture_(((org.xwt.Platform.DefaultGlyph)source).getPicture(), dx, dy, cx1, cy1, cx2, cy2, rgb); } - public void drawPicture(org.xwt.Picture source, int dx1, int dy1, int dx2, int dy2,int sx1, int sy1, int sx2, int sy2) { - activateContext(); - GLPicture p = (GLPicture) source; - p.draw(dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2); + public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) { + drawPicture_(source, dx, dy, cx1, cy1, cx2, cy2, 0xffffffff); + } + + private void drawPicture_(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int color) { + activateInterpreter(); + setColor(color); + GLPicture p = getInnerPicture(source, gl); + p.draw(dx,dy,cx1,cy1,cx2,cy2); } } + + // FIXME ugly + public static OpenGL gl = null; + public OpenGL() { gl = this; } public final static int roundToPowerOf2(int n) { if(((n-1)&n)==0) return n; for(int x=2;x!=0;x<<=1) if(n < x) return x; return 0; } - - public Picture createPicture(int[] data, int w, int h) { - if(rectangularTextures && w <= maxRectTexSize && h <= maxRectTexSize) new RectGLPicture(data,w,h,this); - if(w <= maxTexSize && h <= maxTexSize) return new SquareGLPicture(data,w,h,this); - return new MosaicGLPicture(data,w,h,this); + + private static GLPicture getInnerPicture(Picture p, OpenGL gl) { + OpenGLPicture oglp = (OpenGLPicture)p; + if (!oglp.isLoaded || oglp.realPicture != null) return oglp.realPicture; + if (gl.rectangularTextures && p.width <= gl.maxRectTexSize && p.height <= gl.maxRectTexSize) + oglp.realPicture = new RectGLPicture(p.data,p.width,p.height,oglp.alphaOnly,gl); + else if (p.width <= gl.maxTexSize && p.height <= gl.maxTexSize) + oglp.realPicture = new SquareGLPicture(p.data,p.width,p.height,oglp.alphaOnly,gl); + else + oglp.realPicture = new MosaicGLPicture(p.data,p.width,p.height,oglp.alphaOnly,gl); + p.data = null; + return oglp.realPicture; + } + + public Picture _createPicture(boolean alphaOnly) { return new OpenGLPicture(alphaOnly); } + + public static class OpenGLPicture extends Picture { + public OpenGLPicture(boolean a) { alphaOnly = a; } + boolean alphaOnly; + GLPicture realPicture = null; } + + public Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new OpenGLGlyph(f, c); } + public static class OpenGLGlyph extends Font.Glyph { + private Picture p = null; + public OpenGLGlyph(org.xwt.Font f, char c) { super(f, c); } + Picture getPicture() { + if (p == null && isLoaded) { + p = new OpenGLPicture(true); + p.data = new int[data.length]; + for(int i=0; i 0x7fffffff || h > 0x7fffffff) throw new Error("insane texture size: " + w + "x" + h); texHeight = roundToPowerOf2(h); texWidth = roundToPowerOf2(w); - natInit(data); + natInit(data,alphaOnly); } - public native void draw(int dx1, int dy1, int dx2, int dy2,int sx1, int sy1, int sx2, int sy2); + public native void draw(int dx, int dy, int cx1, int cy1, int cx2, int cy2); protected void finalize() { gl.deleteTexture(textureName); } } @@ -180,25 +216,35 @@ abstract class OpenGL { return 1.0f-(float)(w*h)/(float)(w2*h2); } + private static Object subData(Object data, int x, int y, int w, int h, int rowSize) { + if(data instanceof byte[]) return subData((byte[])data,x,y,w,h,rowSize); + if(data instanceof int[]) return subData((int[])data,x,y,w,h,rowSize); + throw new Error("not reached"); + } + private static int[] subData(int[] data, int x, int y, int w, int h, int rowSize) { int[] sub = new int[w*h]; int row = y; - try { for(int i=0;i 0.40) psize/=2; - Log.log(this,"Using psize: " + psize + " for " + w + "x" + h + " image (wasted space: " + wastedSpace(w,h,psize)); + Log.info(this,"Using psize: " + psize + " for " + w + "x" + h + " image (wasted space: " + wastedSpace(w,h,psize)); int rows = (h+psize-1)/psize; int cols = (w+psize-1)/psize; @@ -207,47 +253,29 @@ abstract class OpenGL { pics = new GLPicture[rows][cols]; for(int i=0;i b ? a : b; } private static final int min(int a, int b) { return a < b ? a : b; } - public void draw(int dx1, int dy1, int dx2, int dy2,int sx1, int sy1, int sx2, int sy2) { - double xscale = (double)(dx2-dx1)/(double)(sx2-sx1); - double yscale = (double)(dy2-dy1)/(double)(sy2-sy1); + public void draw(int dx, int dy, int cx1, int cy1, int cx2, int cy2) { int totalWidth = width; int totalHeight = height; // *{x,y}{1,2} key: d=dest s=src, p=bounds of this picture, i=intersection of s and p, pd = dest of this pic - //System.out.println("Starting draw..." + sx1 + "," + sy1 + " " + sx2 + "," + sy2 + " to " + dx1 +"," + dy1 + " " + dx2 + "," + dy2); for(int i=0;i= ix2 || iy1 >= iy2) continue; // no intersection - - int pdx1 = dx1 + (int) (xscale*(ix1-sx1)); - int pdy1 = dy1 + (int) (yscale*(iy1-sy1)); - int pdx2 = dx2 - (int) (xscale*(sx2-ix2)); - int pdy2 = dy2 - (int) (yscale*(sy2-iy2)); - - //System.out.println("" + i + "," + j + " is good... drawing from " + (ix1-px1) + "," + (iy1-py1) + " " + (ix2-px1) + "," + (iy2-py1) + " to " + pdx1 + "," + pdy1 + " to " + pdx2 + "," + pdy2); - - pics[i][j].draw(pdx1,pdy1,pdx2,pdy2,ix1-px1,iy1-py1,ix2-px1,iy2-py1); + int px1 = j*psize + dx; + int py1 = i*psize + dy; + pics[i][j].draw(px1, py1, cx1, cy1, cx2, cy2); } } }