X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FOpenGL.java;h=6268ad5afd62646a8b65e131e4d71e8f80fb3d52;hb=e1bf2123524ba1cc258188314733f62c2bf45c00;hp=68ed8c14c486bb8cf1e80a346b0b53e87ff3c674;hpb=368ee160342aa0e96e2a678129f9e309284c6107;p=org.ibex.core.git diff --git a/src/org/xwt/plat/OpenGL.java b/src/org/xwt/plat/OpenGL.java index 68ed8c1..6268ad5 100644 --- a/src/org/xwt/plat/OpenGL.java +++ b/src/org/xwt/plat/OpenGL.java @@ -28,7 +28,7 @@ abstract class OpenGL { } } - // 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(); glVersion = parseVersion(version); @@ -46,7 +46,7 @@ abstract class OpenGL { Log.log(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); @@ -80,52 +80,78 @@ abstract class OpenGL { //System.out.println("drawString(): " + text); } - public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) { - drawPicture_(source, dx, dy, cx1, cy1, cx2, cy2, rgb); + 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(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) { - activateContext(); + activateInterpreter(); setColor(color); - GLPicture p = (GLPicture) source; + 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; } - - private Picture _createPicture(Object data, int w, int h, boolean alphaOnly) { - if(rectangularTextures && w <= maxRectTexSize && h <= maxRectTexSize) new RectGLPicture(data,w,h,alphaOnly,this); - if(w <= maxTexSize && h <= maxTexSize) return new SquareGLPicture(data,w,h,alphaOnly,this); - return new MosaicGLPicture(data,w,h,alphaOnly,this); - } - public Picture createPicture(int[] data, int w, int h) { - if(w*h > data.length) throw new Error("should never happen"); - return _createPicture(data,w,h,false); + 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 createAlphaOnlyPicture(byte[] data, int w, int h) { - if(w*h > data.length) throw new Error("should never happen"); - return _createPicture(data,w,h,true); + + 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= ix2 || iy1 >= iy2) continue; // no intersection - pics[i][j].draw(px1, py1, ix1, iy1, ix2, iy2); + int px1 = j*psize + dx; + int py1 = i*psize + dy; + pics[i][j].draw(px1, py1, cx1, cy1, cx2, cy2); } } }