34 |
|
|
35 |
import java.util.HashMap; |
import java.util.HashMap; |
36 |
|
|
37 |
public class GLScreen extends GraphicsAPI.AbstractWindow { |
public class GLScreen extends GLRenderingSurface implements GraphicsAPI.Window { |
38 |
public static final String rcsid = "$Id$"; |
public static final String rcsid = "$Id$"; |
39 |
public static boolean dbg = false; |
public static boolean dbg = false; |
40 |
private static void pa(String s) { System.err.println(s); } |
private static void pa(String s) { System.err.println(s); } |
160 |
} |
} |
161 |
} |
} |
162 |
|
|
|
// XXX To be removed later |
|
|
Vob clear ; |
|
|
public Vob getBGClear() { |
|
|
if(clear == null) |
|
|
clear = GLRen.createCallList( |
|
|
"ClearColor 0.5 0.3 0.6 1.0\n"+ |
|
|
"Clear COLOR_BUFFER_BIT DEPTH_BUFFER_BIT\n"+ |
|
|
"Enable TEXTURE_2D\n"+ |
|
|
"Enable ALPHA_TEST\n"+ |
|
|
"AlphaFunc GREATER 0\n"+ |
|
|
"Enable BLEND\n"+ |
|
|
"BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA\n"+ |
|
|
"Color 1 1 1 1\n"+ |
|
|
"" |
|
|
); |
|
|
return clear; |
|
|
} |
|
|
|
|
|
|
|
|
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; |
|
|
} |
|
163 |
|
|
164 |
|
|
165 |
Binder binder; |
Binder binder; |
171 |
|
|
172 |
public GL.Window getWindow() { return window; } |
public GL.Window getWindow() { return window; } |
173 |
|
|
174 |
GLEventHandler h = new GLEventHandler(); |
GLEventHandler h; |
175 |
|
|
176 |
public GLScreen(GraphicsAPI api) { |
protected GL.RenderingSurface createGLObj(int x, int y, int w, int h) { |
177 |
super(api); |
if(dbg) pa("Create glwindow "+x+" "+y+" "+w+" "+h); |
178 |
if(dbg) pa("Create glscreen"); |
this.h = new GLEventHandler(); |
179 |
window = GL.createWindow(0, 0, 1200, 900, h); |
window = GL.createWindow(x, y, w, h, this.h); |
180 |
// window = GL.createWindow(0, 0, 200, 200, h); |
return window; |
|
if(dbg) pa("Created window"); |
|
181 |
} |
} |
182 |
|
|
183 |
|
|
184 |
public Dimension getSize() { |
public GLScreen(GraphicsAPI api) { |
185 |
Rectangle bounds = window.getBounds(); |
super(api, 0, 0, 200, 200); |
186 |
return new Dimension(bounds.width, bounds.height); |
if(dbg) pa("Created glscreen"); |
187 |
} |
} |
188 |
|
|
189 |
|
|
190 |
public void setLocation(int x, int y, int w, int h) { |
public void setLocation(int x, int y, int w, int h) { |
191 |
if(dbg) pa("glscreen setloc "+x+" "+y+" "+w+" "+h); |
if(dbg) pa("glscreen setloc "+x+" "+y+" "+w+" "+h); |
192 |
window.move(x,y); |
window.move(x,y); |
193 |
window.resize(w,h); |
window.resize(w,h); |
194 |
} |
} |
|
|
|
|
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(window, |
|
|
(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(window, "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(window, (GLVobMap)vs.map, |
|
|
true, iters); |
|
|
} |
|
|
|
|
195 |
static int curT = 42; |
static int curT = 42; |
196 |
public void addTimeout(int ms, Object o) { |
public void addTimeout(int ms, Object o) { |
197 |
int id = curT++; |
int id = curT++; |