/* GLRenderingSurface.java * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas J. Lukka */ package gzz.client.gl; import gzz.*; import gzz.vob.*; import gzz.vob.impl.*; import gzz.vob.impl.gl.*; import gzz.gfx.gl.*; import gzz.errors.*; import gzz.client.*; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.awt.event.InputEvent; import java.util.HashMap; public class GLRenderingSurface extends GraphicsAPI.AbstractRenderingSurface { public static final String rcsid = "$Id: GLRenderingSurface.java,v 1.1 2002/12/05 10:57:34 tjl Exp $"; public static boolean dbg = false; private static void pa(String s) { System.err.println(s); } GLRenderingSurface(GraphicsAPI gfxapi, int x, int y, int w, int h) { super(gfxapi); surface = createGLObj(x,y,w,h); } GL.RenderingSurface surface; public GL.RenderingSurface getRenderingSurface() { return surface; } /** Called during initialization to create the corresponding GL object. */ protected GL.RenderingSurface createGLObj(int x, int y, int w, int h) { if(dbg) pa("Create rendersurface "+w+" "+h); return GL.createStableRenderingSurface(w, h); } public VobScene createVobScene(Dimension size) { VobScene vs = new VobScene( new GLVobMap(this), new GLVobCoorder(), new DefaultVobMatcher(), this.getGraphicsAPI(), this, size ); // the API particularly forbids this. // vs.put(getBGClear(), "NOCKEY", 10, 0, 0, 1, 1); return vs; } public Dimension getSize() { Rectangle bounds = surface.getBounds(); return new Dimension(bounds.width, bounds.height); } public void renderStill(VobScene scene, float lod) { renderAnim(scene, null, 0, lod, true); } VobScene listprev, listnext; int[] interplist; public void renderAnim(VobScene prev, VobScene next, float fract, float lod, boolean showFinal) { if(dbg) pa("glscreen renderanim "+fract+" "+lod); VobScene sc = prev; VobScene osc = next; if (fract > AbstractUpdateManager.jumpFract) { sc = next; osc = prev; fract = 1-fract; } if(osc == null) osc = sc; if(dbg) { pa("Going to render: "+sc+" "+osc+" "+fract); sc.dump(); } if(sc != listprev || osc != listnext) { listprev = sc; listnext = osc; interplist = sc.matcher.interpList(osc.matcher); interplist[0] = interplist.length; } ((GLVobCoorder)sc.coords).renderInterp(surface, (GLVobMap)sc.map, interplist, (GLVobCoorder)osc.coords, fract, true, showFinal); } public int[] readPixels(int x, int y, int w, int h) { GL.ByteVector v = GL.createByteVector(w*h*4); Dimension d = getSize(); v.readFromBuffer(surface, "FRONT", x, d.height-y-h, w, h, "BGRA", "UNSIGNED_BYTE"); int[] res = v.getInts(); // Exchange to get it right way up for(int row = 0; row < h/2; row++) { for(int col = 0; col < w; col++) { int tmp = res[row*w + col]; res[row*w + col] = res[(h-1-row)*w + col]; res[(h-1-row)*w + col] = tmp; } } return res; } public float timeRender(VobScene vs, int iters) { return ((GLVobCoorder)vs.coords).timeRender(surface, (GLVobMap)vs.map, true, iters); } }