X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FOpenGL.java;h=c18d09cd15cc849ff88d9742902403cd8ce258ae;hb=00e1b4c9345b3294a39a9be2ebc5d976dd39f33d;hp=d4bbe1ef1768af397ab0f39b5f5b3f8e1c51904d;hpb=c776d5cb1a018c1731172c871c4a0a6e4ef64b1b;p=org.ibex.core.git diff --git a/src/org/xwt/plat/OpenGL.java b/src/org/xwt/plat/OpenGL.java index d4bbe1e..c18d09c 100644 --- a/src/org/xwt/plat/OpenGL.java +++ b/src/org/xwt/plat/OpenGL.java @@ -1,8 +1,9 @@ -// Copyright 2003 Adam Megacz, see the COPYING file for licensing [LGPL] +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [LGPL] // Author: Brian Alliet package org.xwt.plat; import org.xwt.*; +import org.xwt.js.*; import org.xwt.util.*; abstract class OpenGL { @@ -38,12 +39,12 @@ abstract class OpenGL { 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.diag(this,"Renderer: " + renderer); + Log.diag(this,"Version: " + version); + Log.diag(this,"Vendor: " + vendor); + Log.diag(this,"Rectangular textures: " + (rectangularTextures ? "supported" : "unsupported")); + Log.diag(this,"Max texture size: " + maxTexSize); + Log.diag(this,"Max rectangular texture size: " + maxRectTexSize); } protected abstract void activateSharedContext(); @@ -80,8 +81,8 @@ 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); @@ -90,31 +91,43 @@ abstract class OpenGL { private void drawPicture_(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int color) { activateContext(); 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(JS r, boolean alphaOnly) { return new OpenGLPicture(r, false); } + + public static class OpenGLPicture extends Picture { + public OpenGLPicture(JS r, boolean a) { super(r); alphaOnly = a; } + boolean alphaOnly; + GLPicture realPicture = null; } + + public Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new org.xwt.Platform.DefaultGlyph(f, c); } private native void natDeleteTexture(int tex); public void deleteTexture(final int tex) { @@ -123,7 +136,7 @@ abstract class OpenGL { Scheduler.add(new Scheduler.Task() { public void perform() { natDeleteTexture(tex); }}); } - private static abstract class GLPicture extends Picture { + private static abstract class GLPicture { protected int width; protected int height; @@ -216,7 +229,7 @@ abstract class OpenGL { super(w,h); psize = gl.maxTexSize; while(wastedSpace(w,h,psize) > 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;