.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
44 | 48 | static boolean ABORTED = false; |
---|
45 | 49 | |
---|
46 | 50 | static int STEP = 1; |
---|
| 51 | + |
---|
| 52 | + private static BufferedImage CreateBim(byte[] bytes, int width, int height) |
---|
| 53 | + { |
---|
| 54 | + int[] pixels = new int[bytes.length/3]; |
---|
| 55 | + for (int i=pixels.length; --i>=0;) |
---|
| 56 | + { |
---|
| 57 | + int i3 = i*3; |
---|
| 58 | + pixels[i] = 0xFF; |
---|
| 59 | + pixels[i] <<= 8; |
---|
| 60 | + pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 61 | + pixels[i] <<= 8; |
---|
| 62 | + pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 63 | + pixels[i] <<= 8; |
---|
| 64 | + pixels[i] |= bytes[i3] & 0xFF; |
---|
| 65 | + } |
---|
| 66 | + /* |
---|
| 67 | + int r=0,g=0,b=0,a=0; |
---|
| 68 | + for (int i=0; i<width; i++) |
---|
| 69 | + for (int j=0; j<height; j++) |
---|
| 70 | + { |
---|
| 71 | + int index = j*width+i; |
---|
| 72 | + int p = pixels[index]; |
---|
| 73 | + a = ((p>>24) & 0xFF); |
---|
| 74 | + r = ((p>>16) & 0xFF); |
---|
| 75 | + g = ((p>>8) & 0xFF); |
---|
| 76 | + b = (p & 0xFF); |
---|
| 77 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 78 | + } |
---|
| 79 | + /**/ |
---|
| 80 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 81 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 82 | + return rendImage; |
---|
| 83 | + } |
---|
47 | 84 | |
---|
48 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
60 | 97 | //boolean REDUCETEXTURE = true; |
---|
61 | 98 | boolean CACHETEXTURE = true; |
---|
62 | 99 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = true; // false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
64 | 101 | boolean COMPRESSTEXTURE = false; |
---|
65 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
73 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
74 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
75 | 112 | static GLContext glcontext = null; |
---|
76 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
| 116 | + boolean transformMode; |
---|
| 117 | + |
---|
77 | 118 | boolean reverseUP = false; |
---|
78 | 119 | static boolean frozen = false; |
---|
79 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
136 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
137 | 178 | boolean anisotropy = true; |
---|
138 | 179 | boolean softshadow = true; // slower but better false; |
---|
139 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
140 | 181 | |
---|
141 | 182 | boolean macromode = false; |
---|
142 | 183 | |
---|
.. | .. |
---|
150 | 191 | } |
---|
151 | 192 | |
---|
152 | 193 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 194 | + |
---|
| 195 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 196 | + { |
---|
| 197 | + try |
---|
| 198 | + { |
---|
| 199 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 200 | + } catch (IOException e) |
---|
| 201 | + { |
---|
| 202 | + System.out.println("NAME = " + name); |
---|
| 203 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 204 | + return null; |
---|
| 205 | + } |
---|
| 206 | + } |
---|
153 | 207 | |
---|
154 | 208 | void SetAsGLRenderer(boolean b) |
---|
155 | 209 | { |
---|
.. | .. |
---|
169 | 223 | |
---|
170 | 224 | SetCamera(cam); |
---|
171 | 225 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 226 | + // Warning: not used. |
---|
| 227 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 228 | |
---|
174 | 229 | object = o; |
---|
175 | 230 | |
---|
.. | .. |
---|
1447 | 1502 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1448 | 1503 | } |
---|
1449 | 1504 | |
---|
| 1505 | + float[] colorV = new float[4]; |
---|
| 1506 | + |
---|
1450 | 1507 | void SetColor(Object3D obj, Vertex p0) |
---|
1451 | 1508 | { |
---|
1452 | 1509 | CameraPane display = this; |
---|
.. | .. |
---|
1514 | 1571 | { |
---|
1515 | 1572 | return; |
---|
1516 | 1573 | } |
---|
1517 | | - |
---|
1518 | | - float[] colorV = new float[3]; |
---|
1519 | 1574 | |
---|
1520 | 1575 | if (false) // marked) |
---|
1521 | 1576 | { |
---|
.. | .. |
---|
2405 | 2460 | return currentGL; |
---|
2406 | 2461 | } |
---|
2407 | 2462 | |
---|
2408 | | - private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2463 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
2409 | 2464 | { |
---|
2410 | | - // cache to disk |
---|
2411 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
2412 | | - //buffers[0]. |
---|
2413 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
2414 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
2415 | | - int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared |
---|
2416 | | - int height = width; |
---|
2417 | | - for (int i=pixels.length; --i>=0;) |
---|
2418 | | - { |
---|
2419 | | - int i3 = i*3; |
---|
2420 | | - pixels[i] = 0xFF; |
---|
2421 | | - pixels[i] <<= 8; |
---|
2422 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
2423 | | - pixels[i] <<= 8; |
---|
2424 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
2425 | | - pixels[i] <<= 8; |
---|
2426 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
2427 | | - } |
---|
2428 | | - /* |
---|
2429 | | - int r=0,g=0,b=0,a=0; |
---|
2430 | | - for (int i=0; i<width; i++) |
---|
2431 | | - for (int j=0; j<height; j++) |
---|
2432 | | - { |
---|
2433 | | - int index = j*width+i; |
---|
2434 | | - int p = pixels[index]; |
---|
2435 | | - a = ((p>>24) & 0xFF); |
---|
2436 | | - r = ((p>>16) & 0xFF); |
---|
2437 | | - g = ((p>>8) & 0xFF); |
---|
2438 | | - b = (p & 0xFF); |
---|
2439 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
2440 | | - } |
---|
2441 | | - /**/ |
---|
2442 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
2443 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
2444 | | - return rendImage; |
---|
| 2465 | + Grafreed.Assert(texturedata != null); |
---|
| 2466 | + |
---|
| 2467 | + int width = texturedata.getWidth(); |
---|
| 2468 | + int height = texturedata.getHeight(); |
---|
| 2469 | + |
---|
| 2470 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2471 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2472 | + |
---|
| 2473 | + byte[] bytes = bytebuf.array(); |
---|
| 2474 | + |
---|
| 2475 | + return CreateBim(bytes, width, height); |
---|
2445 | 2476 | } |
---|
2446 | 2477 | |
---|
2447 | 2478 | /**/ |
---|
.. | .. |
---|
2452 | 2483 | |
---|
2453 | 2484 | int resolution; |
---|
2454 | 2485 | |
---|
2455 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2486 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2456 | 2487 | { |
---|
2457 | | - texture = tex; |
---|
| 2488 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2489 | + texturedata = texdata; |
---|
2458 | 2490 | resolution = res; |
---|
2459 | 2491 | } |
---|
2460 | 2492 | } |
---|
2461 | 2493 | /**/ |
---|
2462 | 2494 | |
---|
2463 | 2495 | // TEXTURE static Texture texture; |
---|
2464 | | - static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); |
---|
2465 | | - static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); |
---|
2466 | | - static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); |
---|
| 2496 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2497 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2498 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2499 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
2467 | 2500 | |
---|
2468 | 2501 | int pigmentdepth = 0; |
---|
2469 | 2502 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2471 | 2504 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2472 | 2505 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2473 | 2506 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2474 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2507 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2475 | 2508 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2476 | 2509 | |
---|
2477 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2510 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2478 | 2511 | { |
---|
2479 | 2512 | TextureData texturedata = null; |
---|
2480 | 2513 | |
---|
.. | .. |
---|
2484 | 2517 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2485 | 2518 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2486 | 2519 | true, |
---|
2487 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2520 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2488 | 2521 | } catch (java.io.IOException e) |
---|
2489 | 2522 | { |
---|
2490 | 2523 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
2493 | 2526 | if (bump) |
---|
2494 | 2527 | texturedata = ConvertBump(texturedata, false); |
---|
2495 | 2528 | |
---|
2496 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2497 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2529 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2530 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2498 | 2531 | |
---|
2499 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2500 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2532 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2533 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2501 | 2534 | |
---|
2502 | | - return texture; |
---|
| 2535 | + return texturedata; |
---|
2503 | 2536 | } |
---|
2504 | 2537 | |
---|
2505 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2538 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2506 | 2539 | { |
---|
2507 | 2540 | TextureData texturedata = null; |
---|
2508 | 2541 | |
---|
.. | .. |
---|
2510 | 2543 | { |
---|
2511 | 2544 | texturedata = |
---|
2512 | 2545 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2513 | | - name, |
---|
| 2546 | + bim, |
---|
2514 | 2547 | true); |
---|
2515 | 2548 | } catch (Exception e) |
---|
2516 | 2549 | { |
---|
.. | .. |
---|
2519 | 2552 | |
---|
2520 | 2553 | if (bump) |
---|
2521 | 2554 | texturedata = ConvertBump(texturedata, false); |
---|
2522 | | - |
---|
2523 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2524 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2525 | | - |
---|
2526 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2527 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2528 | | - |
---|
2529 | | - return texture; |
---|
| 2555 | + |
---|
| 2556 | + return texturedata; |
---|
2530 | 2557 | } |
---|
2531 | 2558 | |
---|
2532 | 2559 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
8014 | 8041 | pigment = null; |
---|
8015 | 8042 | } |
---|
8016 | 8043 | |
---|
8017 | | - ReleaseTexture(bump, true); |
---|
8018 | | - ReleaseTexture(pigment, false); |
---|
| 8044 | + ReleaseTexture(tex, true); |
---|
| 8045 | + ReleaseTexture(tex, false); |
---|
8019 | 8046 | } |
---|
8020 | 8047 | |
---|
8021 | 8048 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8044 | 8071 | pigment = null; |
---|
8045 | 8072 | } |
---|
8046 | 8073 | |
---|
8047 | | - ReleaseTexture(pigment, false); |
---|
| 8074 | + ReleaseTexture(tex, false); |
---|
8048 | 8075 | } |
---|
8049 | 8076 | |
---|
8050 | 8077 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8073 | 8100 | bump = null; |
---|
8074 | 8101 | } |
---|
8075 | 8102 | |
---|
8076 | | - ReleaseTexture(bump, true); |
---|
| 8103 | + ReleaseTexture(tex, true); |
---|
8077 | 8104 | } |
---|
8078 | 8105 | |
---|
8079 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8106 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8080 | 8107 | { |
---|
8081 | 8108 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8082 | 8109 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8087 | 8114 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8088 | 8115 | |
---|
8089 | 8116 | if (tex != null) |
---|
8090 | | - texture = textures.get(tex); |
---|
| 8117 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8091 | 8118 | |
---|
8092 | 8119 | // //assert( texture != null ); |
---|
8093 | 8120 | // if (texture == null) |
---|
.. | .. |
---|
8237 | 8264 | |
---|
8238 | 8265 | if (tex == null) |
---|
8239 | 8266 | { |
---|
8240 | | - BindTexture(null, null,false,resolution); |
---|
| 8267 | + BindTexture(null,false,resolution); |
---|
8241 | 8268 | return; |
---|
8242 | 8269 | } |
---|
8243 | 8270 | |
---|
8244 | 8271 | String pigment = Object3D.GetPigment(tex); |
---|
8245 | 8272 | |
---|
8246 | | - usedtextures.add(pigment); |
---|
| 8273 | + usedtextures.add(tex); |
---|
8247 | 8274 | |
---|
8248 | 8275 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8249 | 8276 | { |
---|
.. | .. |
---|
8257 | 8284 | } |
---|
8258 | 8285 | |
---|
8259 | 8286 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8260 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8287 | + BindTexture(tex, false, resolution); |
---|
8261 | 8288 | } |
---|
8262 | 8289 | |
---|
8263 | 8290 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8270 | 8297 | |
---|
8271 | 8298 | if (tex == null) |
---|
8272 | 8299 | { |
---|
8273 | | - BindTexture(null, null,true,resolution); |
---|
| 8300 | + BindTexture(null,true,resolution); |
---|
8274 | 8301 | return; |
---|
8275 | 8302 | } |
---|
8276 | 8303 | |
---|
8277 | 8304 | String bump = Object3D.GetBump(tex); |
---|
8278 | 8305 | |
---|
8279 | | - usedtextures.add(bump); |
---|
| 8306 | + usedtextures.add(tex); |
---|
8280 | 8307 | |
---|
8281 | 8308 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8282 | 8309 | { |
---|
.. | .. |
---|
8290 | 8317 | } |
---|
8291 | 8318 | |
---|
8292 | 8319 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8293 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8320 | + BindTexture(tex, true, resolution); |
---|
8294 | 8321 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8295 | 8322 | } |
---|
8296 | 8323 | |
---|
.. | .. |
---|
8314 | 8341 | return fileExists; |
---|
8315 | 8342 | } |
---|
8316 | 8343 | |
---|
8317 | | - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
| 8344 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8318 | 8345 | { |
---|
8319 | 8346 | CacheTexture texturecache = null; |
---|
8320 | 8347 | |
---|
8321 | 8348 | if (tex != null) |
---|
8322 | 8349 | { |
---|
8323 | | - String texname = tex; |
---|
| 8350 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8351 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8352 | + |
---|
| 8353 | + if (texname.equals("") && texdata == null) |
---|
| 8354 | + { |
---|
| 8355 | + return null; |
---|
| 8356 | + } |
---|
8324 | 8357 | |
---|
8325 | 8358 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8326 | 8359 | |
---|
.. | .. |
---|
8330 | 8363 | // else |
---|
8331 | 8364 | // if (!texname.startsWith("/")) |
---|
8332 | 8365 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8333 | | - if (!FileExists(tex)) |
---|
| 8366 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8334 | 8367 | { |
---|
8335 | 8368 | texname = fallbackTextureName; |
---|
8336 | 8369 | } |
---|
8337 | 8370 | |
---|
8338 | 8371 | if (CACHETEXTURE) |
---|
8339 | 8372 | { |
---|
8340 | | - if (bim == null) |
---|
8341 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8373 | + if (texdata == null) |
---|
| 8374 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8342 | 8375 | else |
---|
8343 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8376 | + texturecache = bimtextures.get(texdata); |
---|
8344 | 8377 | } |
---|
8345 | 8378 | |
---|
8346 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8379 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8347 | 8380 | { |
---|
8348 | 8381 | TextureData texturedata = null; |
---|
8349 | 8382 | |
---|
8350 | | - if (bim != null) |
---|
| 8383 | + if (texdata != null && textureon) |
---|
8351 | 8384 | { |
---|
| 8385 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8386 | + |
---|
| 8387 | + try |
---|
| 8388 | + { |
---|
| 8389 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8390 | + } |
---|
| 8391 | + catch (Exception e) |
---|
| 8392 | + { |
---|
| 8393 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8394 | + } |
---|
| 8395 | + |
---|
8352 | 8396 | texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8397 | + bimtextures.put(texdata, texturecache); |
---|
| 8398 | + |
---|
| 8399 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8400 | + |
---|
| 8401 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8402 | + //bim2 = bim; |
---|
8353 | 8403 | } |
---|
8354 | 8404 | else |
---|
8355 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8405 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8356 | 8406 | { |
---|
8357 | 8407 | assert(!bump); |
---|
8358 | 8408 | // if (bump) |
---|
.. | .. |
---|
8363 | 8413 | // } |
---|
8364 | 8414 | // else |
---|
8365 | 8415 | // { |
---|
8366 | | - texturecache = textures.get(tex); |
---|
| 8416 | + // texturecache = textures.get(texname); // suspicious |
---|
8367 | 8417 | if (texturecache == null) |
---|
8368 | 8418 | { |
---|
8369 | 8419 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
.. | .. |
---|
8372 | 8422 | new Exception().printStackTrace(); |
---|
8373 | 8423 | // } |
---|
8374 | 8424 | } else |
---|
8375 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8425 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8376 | 8426 | { |
---|
8377 | 8427 | assert(bump); |
---|
8378 | | - texturecache = textures.get(tex); |
---|
| 8428 | + // texturecache = textures.get(texname); // suspicious |
---|
8379 | 8429 | if (texturecache == null) |
---|
8380 | 8430 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8381 | 8431 | else |
---|
.. | .. |
---|
8387 | 8437 | // texture = GetResourceTexture("default.png"); |
---|
8388 | 8438 | //} else |
---|
8389 | 8439 | //{ |
---|
8390 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8440 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8391 | 8441 | { |
---|
8392 | | - texturecache = textures.get(tex); |
---|
| 8442 | + // texturecache = textures.get(texname); // suspicious |
---|
8393 | 8443 | if (texturecache == null) |
---|
8394 | 8444 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8445 | + else |
---|
| 8446 | + new Exception().printStackTrace(); |
---|
| 8447 | + } else |
---|
| 8448 | + { |
---|
| 8449 | + if (texname.startsWith("@")) |
---|
| 8450 | + { |
---|
| 8451 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8452 | + if (texturecache == null) |
---|
| 8453 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
8395 | 8454 | else |
---|
8396 | 8455 | new Exception().printStackTrace(); |
---|
8397 | 8456 | } else |
---|
.. | .. |
---|
8452 | 8511 | if (texturedata == null) |
---|
8453 | 8512 | throw new Exception(); |
---|
8454 | 8513 | |
---|
8455 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8514 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8456 | 8515 | //texture = GetTexture(tex, bump); |
---|
8457 | 8516 | } |
---|
| 8517 | + } |
---|
8458 | 8518 | } |
---|
8459 | 8519 | //} |
---|
8460 | 8520 | } |
---|
8461 | 8521 | |
---|
8462 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8522 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8463 | 8523 | { |
---|
8464 | 8524 | //return false; |
---|
8465 | | - assert(bim == null); |
---|
8466 | 8525 | |
---|
8467 | 8526 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8468 | 8527 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8509 | 8568 | } |
---|
8510 | 8569 | } |
---|
8511 | 8570 | } |
---|
8512 | | - |
---|
| 8571 | + |
---|
| 8572 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8573 | + |
---|
8513 | 8574 | //System.out.println("Texture = " + tex); |
---|
8514 | | - if (textures.containsKey(texname)) |
---|
| 8575 | + if (textures.containsKey(tex)) |
---|
8515 | 8576 | { |
---|
8516 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8577 | + CacheTexture thetex = textures.get(tex); |
---|
8517 | 8578 | thetex.texture.disable(); |
---|
8518 | 8579 | thetex.texture.dispose(); |
---|
8519 | | - textures.remove(texname); |
---|
| 8580 | + textures.remove(tex); |
---|
8520 | 8581 | } |
---|
8521 | 8582 | |
---|
8522 | 8583 | //texture.texturedata = texturedata; |
---|
8523 | | - textures.put(texname, texturecache); |
---|
| 8584 | + textures.put(tex, texturecache); |
---|
8524 | 8585 | |
---|
8525 | 8586 | // newtex = true; |
---|
8526 | 8587 | } |
---|
.. | .. |
---|
8541 | 8602 | |
---|
8542 | 8603 | static void EmbedTextures(cTexture tex) |
---|
8543 | 8604 | { |
---|
| 8605 | + if (tex.pigmentdata == null) |
---|
| 8606 | + { |
---|
| 8607 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8608 | + |
---|
| 8609 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8610 | + |
---|
| 8611 | + if (texturecache != null) |
---|
| 8612 | + { |
---|
| 8613 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8614 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8615 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8616 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8617 | + ; |
---|
| 8618 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8619 | + } |
---|
| 8620 | + } |
---|
8544 | 8621 | |
---|
| 8622 | + if (tex.bumpdata == null) |
---|
| 8623 | + { |
---|
| 8624 | + //String texname = Object3D.GetBump(tex); |
---|
| 8625 | + |
---|
| 8626 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8627 | + |
---|
| 8628 | + if (texturecache != null) |
---|
| 8629 | + { |
---|
| 8630 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8631 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8632 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8633 | + } |
---|
| 8634 | + } |
---|
8545 | 8635 | } |
---|
8546 | 8636 | |
---|
8547 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8637 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8548 | 8638 | { |
---|
8549 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8639 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8550 | 8640 | |
---|
8551 | 8641 | if (bump) |
---|
8552 | 8642 | { |
---|
.. | .. |
---|
8562 | 8652 | return texture!=null?texture.texture:null; |
---|
8563 | 8653 | } |
---|
8564 | 8654 | |
---|
8565 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8655 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8566 | 8656 | { |
---|
8567 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8657 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8568 | 8658 | |
---|
8569 | 8659 | return texture!=null?texture.texturedata:null; |
---|
8570 | 8660 | } |
---|
8571 | 8661 | |
---|
8572 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8662 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8573 | 8663 | { |
---|
8574 | 8664 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8575 | 8665 | { |
---|
.. | .. |
---|
8578 | 8668 | |
---|
8579 | 8669 | //boolean newtex = false; |
---|
8580 | 8670 | |
---|
8581 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8671 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8582 | 8672 | |
---|
8583 | 8673 | if (texture == null) |
---|
8584 | 8674 | return false; |
---|
.. | .. |
---|
8611 | 8701 | return true; // Warning: not used. |
---|
8612 | 8702 | } |
---|
8613 | 8703 | |
---|
| 8704 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8705 | + { |
---|
| 8706 | + try |
---|
| 8707 | + { |
---|
| 8708 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8709 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8710 | + ImageWriter writer = writers.next(); |
---|
| 8711 | + |
---|
| 8712 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8713 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8714 | + param.setCompressionQuality(quality); |
---|
| 8715 | + |
---|
| 8716 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8717 | + writer.setOutput(ios); |
---|
| 8718 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8719 | + |
---|
| 8720 | + byte[] data = baos.toByteArray(); |
---|
| 8721 | + writer.dispose(); |
---|
| 8722 | + return data; |
---|
| 8723 | + } |
---|
| 8724 | + catch (Exception e) |
---|
| 8725 | + { |
---|
| 8726 | + e.printStackTrace(); |
---|
| 8727 | + return null; |
---|
| 8728 | + } |
---|
| 8729 | + } |
---|
| 8730 | + |
---|
| 8731 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8732 | + { |
---|
| 8733 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8734 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8735 | + ImageReader reader = writers.next(); |
---|
| 8736 | + |
---|
| 8737 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8738 | + |
---|
| 8739 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8740 | + param.setDestination(bim); |
---|
| 8741 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8742 | + |
---|
| 8743 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8744 | + reader.setInput(ios); |
---|
| 8745 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8746 | + reader.dispose(); |
---|
| 8747 | + |
---|
| 8748 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8749 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8750 | +// byte[] bytes = data.getData(); |
---|
| 8751 | +// |
---|
| 8752 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8753 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8754 | +// { |
---|
| 8755 | +// int i3 = i*3; |
---|
| 8756 | +// pixels[i] = 0xFF; |
---|
| 8757 | +// pixels[i] <<= 8; |
---|
| 8758 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8759 | +// pixels[i] <<= 8; |
---|
| 8760 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8761 | +// pixels[i] <<= 8; |
---|
| 8762 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8763 | +// } |
---|
| 8764 | +// |
---|
| 8765 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8766 | + |
---|
| 8767 | + return bim; |
---|
| 8768 | + } |
---|
| 8769 | + |
---|
8614 | 8770 | ShadowBuffer shadowPBuf; |
---|
8615 | 8771 | AntialiasBuffer antialiasPBuf; |
---|
8616 | 8772 | int MAXSTACK; |
---|
.. | .. |
---|
8627 | 8783 | |
---|
8628 | 8784 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8629 | 8785 | MAXSTACK = temp[0]; |
---|
8630 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8786 | + if (Globals.DEBUG) |
---|
| 8787 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8631 | 8788 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8632 | 8789 | MAXSTACK = temp[0]; |
---|
8633 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8790 | + if (Globals.DEBUG) |
---|
| 8791 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8634 | 8792 | |
---|
8635 | 8793 | // Use debug pipeline |
---|
8636 | 8794 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8638 | 8796 | gl = drawable.getGL(); // |
---|
8639 | 8797 | |
---|
8640 | 8798 | GL gl3 = getGL(); |
---|
8641 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8642 | 8801 | |
---|
8643 | 8802 | |
---|
8644 | 8803 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8803 | 8962 | |
---|
8804 | 8963 | if (cubemap == null) |
---|
8805 | 8964 | { |
---|
8806 | | - LoadEnvy(5); |
---|
| 8965 | + //LoadEnvy(1); |
---|
8807 | 8966 | } |
---|
8808 | 8967 | |
---|
8809 | 8968 | //cubemap.enable(); |
---|
.. | .. |
---|
9079 | 9238 | |
---|
9080 | 9239 | void LoadEnvy(int which) |
---|
9081 | 9240 | { |
---|
| 9241 | + assert(false); |
---|
| 9242 | + |
---|
9082 | 9243 | String name; |
---|
9083 | 9244 | String ext; |
---|
9084 | 9245 | |
---|
.. | .. |
---|
9090 | 9251 | cubemap = null; |
---|
9091 | 9252 | return; |
---|
9092 | 9253 | case 1: |
---|
9093 | | - name = "cubemaps/box_"; |
---|
9094 | | - ext = "png"; |
---|
| 9254 | + name = "cubemaps/rgb/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9095 | 9256 | reverseUP = false; |
---|
9096 | 9257 | break; |
---|
9097 | 9258 | case 2: |
---|
9098 | | - name = "cubemaps/uffizi_"; |
---|
9099 | | - ext = "png"; |
---|
9100 | | - break; // reverseUP = true; break; |
---|
| 9259 | + name = "cubemaps/uffizi/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
9101 | 9263 | case 3: |
---|
9102 | | - name = "cubemaps/CloudyHills_"; |
---|
9103 | | - ext = "tga"; |
---|
| 9264 | + name = "cubemaps/CloudyHills/"; |
---|
| 9265 | + ext = "jpg"; |
---|
9104 | 9266 | reverseUP = false; |
---|
9105 | 9267 | break; |
---|
9106 | 9268 | case 4: |
---|
9107 | | - name = "cubemaps/cornell_"; |
---|
| 9269 | + name = "cubemaps/cornell/"; |
---|
9108 | 9270 | ext = "png"; |
---|
9109 | 9271 | reverseUP = false; |
---|
9110 | 9272 | break; |
---|
| 9273 | + case 5: |
---|
| 9274 | + name = "cubemaps/skycube/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
| 9278 | + case 6: |
---|
| 9279 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9280 | + ext = "jpg"; |
---|
| 9281 | + reverseUP = false; |
---|
| 9282 | + break; |
---|
| 9283 | + case 7: |
---|
| 9284 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9285 | + ext = "jpg"; |
---|
| 9286 | + reverseUP = false; |
---|
| 9287 | + break; |
---|
| 9288 | + case 8: |
---|
| 9289 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9290 | + ext = "jpg"; |
---|
| 9291 | + reverseUP = false; |
---|
| 9292 | + break; |
---|
| 9293 | + case 9: |
---|
| 9294 | + name = "cubemaps/UnionSquare/"; |
---|
| 9295 | + ext = "jpg"; |
---|
| 9296 | + reverseUP = false; |
---|
| 9297 | + break; |
---|
9111 | 9298 | default: |
---|
9112 | | - name = "cubemaps/rgb_"; |
---|
9113 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9299 | + name = "cubemaps/box/"; |
---|
| 9300 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9301 | + reverseUP = false; |
---|
9114 | 9302 | break; |
---|
9115 | 9303 | } |
---|
9116 | | - |
---|
9117 | | - try |
---|
9118 | | - { |
---|
9119 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9120 | | - } catch (IOException e) |
---|
9121 | | - { |
---|
9122 | | - throw new RuntimeException(e); |
---|
9123 | | - } |
---|
| 9304 | + |
---|
| 9305 | + LoadSkybox(name, ext, mipmap); |
---|
9124 | 9306 | } |
---|
9125 | 9307 | |
---|
9126 | 9308 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9152 | 9334 | static double[] model = new double[16]; |
---|
9153 | 9335 | double[] camera2light = new double[16]; |
---|
9154 | 9336 | double[] light2camera = new double[16]; |
---|
9155 | | - int newenvy = -1; |
---|
9156 | | - boolean envyoff = true; // false; |
---|
| 9337 | + |
---|
| 9338 | + //int newenvy = -1; |
---|
| 9339 | + //boolean envyoff = false; |
---|
| 9340 | + |
---|
| 9341 | + String loadedskyboxname; |
---|
| 9342 | + |
---|
9157 | 9343 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9158 | 9344 | //float[] light0 = { 0,0,0 }; |
---|
9159 | 9345 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9571 | 9757 | |
---|
9572 | 9758 | if (renderCamera != lightCamera) |
---|
9573 | 9759 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9760 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9575 | 9761 | |
---|
9576 | 9762 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9577 | 9763 | |
---|
.. | .. |
---|
9587 | 9773 | |
---|
9588 | 9774 | if (renderCamera != lightCamera) |
---|
9589 | 9775 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9590 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9776 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9591 | 9777 | |
---|
9592 | 9778 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9593 | 9779 | |
---|
.. | .. |
---|
9633 | 9819 | rati = 1 / rati; |
---|
9634 | 9820 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9635 | 9821 | } |
---|
9636 | | - assert (newenvy == -1); |
---|
| 9822 | + |
---|
| 9823 | + //assert (newenvy == -1); |
---|
| 9824 | + |
---|
9637 | 9825 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9638 | 9826 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9639 | | - DrawSkyBox(gl); |
---|
| 9827 | + DrawSkyBox(gl, (float)rati); |
---|
9640 | 9828 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9641 | 9829 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9642 | 9830 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10673 | 10861 | |
---|
10674 | 10862 | if (wait) |
---|
10675 | 10863 | { |
---|
10676 | | - Sleep(500); |
---|
| 10864 | + Sleep(200); // blocks everything |
---|
10677 | 10865 | |
---|
10678 | 10866 | wait = false; |
---|
10679 | 10867 | } |
---|
.. | .. |
---|
10788 | 10976 | // if (parentcam != renderCamera) // not a light |
---|
10789 | 10977 | if (cam != lightCamera) |
---|
10790 | 10978 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10791 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10979 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10792 | 10980 | |
---|
10793 | 10981 | for (int j = 0; j < 4; j++) |
---|
10794 | 10982 | { |
---|
.. | .. |
---|
10803 | 10991 | // if (parentcam != renderCamera) // not a light |
---|
10804 | 10992 | if (cam != lightCamera) |
---|
10805 | 10993 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10806 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10994 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10807 | 10995 | |
---|
10808 | 10996 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10809 | 10997 | |
---|
.. | .. |
---|
10889 | 11077 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10890 | 11078 | } |
---|
10891 | 11079 | |
---|
10892 | | - if (newenvy > -1) |
---|
| 11080 | +// if (newenvy > -1) |
---|
| 11081 | +// { |
---|
| 11082 | +// LoadEnvy(newenvy); |
---|
| 11083 | +// } |
---|
| 11084 | +// |
---|
| 11085 | +// newenvy = -1; |
---|
| 11086 | + |
---|
| 11087 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10893 | 11088 | { |
---|
10894 | | - LoadEnvy(newenvy); |
---|
| 11089 | + if (cubemaprgb == null) |
---|
| 11090 | + { |
---|
| 11091 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); |
---|
| 11092 | + } |
---|
| 11093 | + |
---|
| 11094 | + cubemap = cubemaprgb; |
---|
10895 | 11095 | } |
---|
10896 | | - |
---|
10897 | | - newenvy = -1; |
---|
10898 | | - |
---|
| 11096 | + else |
---|
| 11097 | + { |
---|
| 11098 | + if (object.skyboxname != null) |
---|
| 11099 | + { |
---|
| 11100 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11101 | + { |
---|
| 11102 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11103 | + cubemap.dispose(); |
---|
| 11104 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11105 | + loadedskyboxname = object.skyboxname; |
---|
| 11106 | + } |
---|
| 11107 | + } |
---|
| 11108 | + else |
---|
| 11109 | + { |
---|
| 11110 | + cubemapcustom = null; |
---|
| 11111 | + loadedskyboxname = null; |
---|
| 11112 | + } |
---|
| 11113 | + |
---|
| 11114 | + cubemap = cubemapcustom; |
---|
| 11115 | + } |
---|
| 11116 | + |
---|
10899 | 11117 | ratio = ((double) getWidth()) / getHeight(); |
---|
10900 | 11118 | //System.out.println("ratio = " + ratio); |
---|
10901 | 11119 | |
---|
.. | .. |
---|
10911 | 11129 | |
---|
10912 | 11130 | if (!IsFrozen() && !ambientOcclusion) |
---|
10913 | 11131 | { |
---|
10914 | | - DrawSkyBox(gl); |
---|
| 11132 | + DrawSkyBox(gl, (float)ratio); |
---|
10915 | 11133 | } |
---|
10916 | 11134 | |
---|
10917 | 11135 | //if (selection_view == -1) |
---|
.. | .. |
---|
11065 | 11283 | |
---|
11066 | 11284 | try |
---|
11067 | 11285 | { |
---|
11068 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11286 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11069 | 11287 | } |
---|
11070 | 11288 | catch (Exception e) |
---|
11071 | 11289 | { |
---|
.. | .. |
---|
11197 | 11415 | |
---|
11198 | 11416 | // if (cam != lightCamera) |
---|
11199 | 11417 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11200 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11418 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11201 | 11419 | } |
---|
11202 | 11420 | |
---|
11203 | 11421 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11356 | 11574 | } |
---|
11357 | 11575 | } |
---|
11358 | 11576 | |
---|
11359 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11577 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11360 | 11578 | { |
---|
11361 | 11579 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11362 | 11580 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11364 | 11582 | |
---|
11365 | 11583 | boolean texon = textureon; |
---|
11366 | 11584 | |
---|
11367 | | - if (RENDERPROGRAM > 0) |
---|
11368 | | - { |
---|
11369 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11370 | | - textureon = false; |
---|
11371 | | - } |
---|
| 11585 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11586 | + textureon = false; |
---|
| 11587 | + |
---|
11372 | 11588 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11373 | 11589 | //System.out.println("ALLO"); |
---|
11374 | 11590 | gl.glColorMask(false, false, false, false); |
---|
11375 | 11591 | DrawObject(gl); |
---|
11376 | | - if (RENDERPROGRAM > 0) |
---|
11377 | | - { |
---|
11378 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11379 | | - textureon = texon; |
---|
11380 | | - } |
---|
| 11592 | + |
---|
| 11593 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11594 | + textureon = texon; |
---|
| 11595 | + |
---|
11381 | 11596 | gl.glColorMask(true, true, true, true); |
---|
11382 | 11597 | |
---|
11383 | 11598 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11384 | | - //gl.glDepthMask(false); |
---|
| 11599 | + gl.glDepthMask(false); |
---|
11385 | 11600 | } |
---|
11386 | 11601 | |
---|
11387 | 11602 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11721 | 11936 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11722 | 11937 | |
---|
11723 | 11938 | if (CLEANCACHE) |
---|
11724 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11939 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11725 | 11940 | { |
---|
11726 | | - String tex = e.nextElement(); |
---|
| 11941 | + cTexture tex = e.nextElement(); |
---|
11727 | 11942 | |
---|
11728 | 11943 | // System.out.println("Texture --------- " + tex); |
---|
11729 | 11944 | |
---|
11730 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11945 | + if (tex.equals("WHITE_NOISE:")) |
---|
11731 | 11946 | continue; |
---|
11732 | 11947 | |
---|
11733 | 11948 | if (!usedtextures.contains(tex)) |
---|
11734 | 11949 | { |
---|
| 11950 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11735 | 11951 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11736 | | - textures.get(tex).texture.dispose(); |
---|
11737 | | - textures.remove(tex); |
---|
| 11952 | + if (gettex != null) |
---|
| 11953 | + { |
---|
| 11954 | + gettex.texture.dispose(); |
---|
| 11955 | + texturepigment.remove(tex); |
---|
| 11956 | + } |
---|
| 11957 | + |
---|
| 11958 | + gettex = texturebump.get(tex); |
---|
| 11959 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11960 | + if (gettex != null) |
---|
| 11961 | + { |
---|
| 11962 | + gettex.texture.dispose(); |
---|
| 11963 | + texturebump.remove(tex); |
---|
| 11964 | + } |
---|
11738 | 11965 | } |
---|
11739 | 11966 | } |
---|
11740 | 11967 | } |
---|
.. | .. |
---|
12262 | 12489 | |
---|
12263 | 12490 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12264 | 12491 | |
---|
12265 | | - String program = |
---|
| 12492 | + String programmin = |
---|
| 12493 | + // Min shader |
---|
12266 | 12494 | "!!ARBfp1.0\n" + |
---|
| 12495 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12496 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12497 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12498 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12499 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12500 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12501 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12502 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12503 | + "TEMP temp;" + |
---|
| 12504 | + "TEMP light;" + |
---|
| 12505 | + "TEMP ndotl;" + |
---|
| 12506 | + "TEMP normal;" + |
---|
| 12507 | + "TEMP depth;" + |
---|
| 12508 | + "TEMP eye;" + |
---|
| 12509 | + "TEMP pos;" + |
---|
| 12510 | + |
---|
| 12511 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12512 | + Normalize("normal") + |
---|
| 12513 | + "MOV light, state.light[0].position;" + |
---|
| 12514 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12515 | + |
---|
| 12516 | + // shadow |
---|
| 12517 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12518 | + "MOV temp, pos;" + |
---|
| 12519 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12520 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12521 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12522 | + |
---|
| 12523 | + // No shadow when out of frustum |
---|
| 12524 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12525 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12526 | + |
---|
| 12527 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12528 | + |
---|
| 12529 | + // Backlit |
---|
| 12530 | + "MOV pos.w, zero123.y;" + |
---|
| 12531 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12532 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12533 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12534 | + Normalize("eye") + |
---|
| 12535 | + |
---|
| 12536 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12538 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12539 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12540 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12541 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12542 | + |
---|
| 12543 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12544 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12545 | + |
---|
| 12546 | + // Pigment |
---|
| 12547 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12548 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12549 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12550 | + |
---|
| 12551 | + "MUL temp, temp, zero123.z;" + |
---|
| 12552 | + |
---|
| 12553 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12554 | + |
---|
| 12555 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12556 | + "MOV result.color, temp;" + |
---|
| 12557 | + "END"; |
---|
| 12558 | + |
---|
| 12559 | + String programmax = |
---|
| 12560 | + "!!ARBfp1.0\n" + |
---|
| 12561 | + |
---|
12267 | 12562 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12268 | 12563 | "PARAM light2cam0 = program.env[10];" + |
---|
12269 | 12564 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12378 | 12673 | "TEMP shininess;" + |
---|
12379 | 12674 | "\n" + |
---|
12380 | 12675 | "MOV texSamp, one;" + |
---|
12381 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12382 | | - |
---|
| 12676 | + |
---|
12383 | 12677 | "MOV mapgrid.x, one2048th.x;" + |
---|
12384 | 12678 | "MOV temp, fragment.texcoord[1];" + |
---|
12385 | 12679 | /* |
---|
.. | .. |
---|
12400 | 12694 | "MUL temp, floor, mapgrid.x;" + |
---|
12401 | 12695 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12402 | 12696 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12403 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12697 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12404 | 12698 | "") + |
---|
12405 | 12699 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12406 | 12700 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12407 | 12701 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12408 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12409 | 12703 | "") + |
---|
12410 | 12704 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12411 | 12705 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12412 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12413 | 12707 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12414 | 12708 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12415 | 12709 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12416 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12710 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12417 | 12711 | "") + |
---|
12418 | 12712 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12419 | 12713 | //"MOV params, material;" + |
---|
.. | .. |
---|
12784 | 13078 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12785 | 13079 | "") + |
---|
12786 | 13080 | |
---|
12787 | | - // display shadow only (bump == 0) |
---|
| 13081 | + // display shadow only (fakedepth == 0) |
---|
12788 | 13082 | "SUB temp.x, half.x, shadow.x;" + |
---|
12789 | 13083 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12790 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13084 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12791 | 13085 | "SUB temp.y, one.x, temp.z;" + |
---|
12792 | 13086 | "MUL temp.x, temp.x, temp.y;" + |
---|
12793 | 13087 | "KIL temp.x;" + |
---|
.. | .. |
---|
13118 | 13412 | //once = true; |
---|
13119 | 13413 | } |
---|
13120 | 13414 | |
---|
13121 | | - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13122 | | - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13415 | + String program = programmax; |
---|
| 13416 | + |
---|
| 13417 | + if (Globals.MINSHADER) |
---|
| 13418 | + { |
---|
| 13419 | + program = programmin; |
---|
| 13420 | + } |
---|
| 13421 | + |
---|
| 13422 | + if (Globals.DEBUG) |
---|
| 13423 | + { |
---|
| 13424 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
| 13425 | + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13426 | + } |
---|
| 13427 | + |
---|
13123 | 13428 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13124 | 13429 | |
---|
13125 | 13430 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13166 | 13471 | "\n" + |
---|
13167 | 13472 | "END\n"; |
---|
13168 | 13473 | |
---|
13169 | | - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
| 13474 | + if (Globals.DEBUG) |
---|
| 13475 | + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
13170 | 13476 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13171 | 13477 | |
---|
13172 | 13478 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13211 | 13517 | return out; |
---|
13212 | 13518 | } |
---|
13213 | 13519 | |
---|
13214 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13520 | + // Also does frustum culling |
---|
| 13521 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13215 | 13522 | { |
---|
13216 | 13523 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13217 | 13524 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13218 | 13525 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13526 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13527 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13219 | 13528 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13220 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13221 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13222 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13223 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13529 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13530 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13224 | 13531 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13225 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13532 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13226 | 13533 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13227 | 13534 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13228 | 13535 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13229 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13536 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13230 | 13537 | |
---|
13231 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13232 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13538 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13539 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13233 | 13540 | } |
---|
13234 | 13541 | |
---|
13235 | 13542 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13276 | 13583 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13277 | 13584 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13278 | 13585 | |
---|
13279 | | - // No shadow when out of frustrum |
---|
| 13586 | + // No shadow when out of frustum |
---|
13280 | 13587 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13281 | 13588 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13282 | 13589 | ""; |
---|
.. | .. |
---|
14074 | 14381 | drag = false; |
---|
14075 | 14382 | //System.out.println("Mouse DOWN"); |
---|
14076 | 14383 | editObj = false; |
---|
14077 | | - ClickInfo info = new ClickInfo(); |
---|
14078 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14079 | | - info.pane = this; |
---|
14080 | | - info.camera = renderCamera; |
---|
14081 | | - info.x = x; |
---|
14082 | | - info.y = y; |
---|
14083 | | - info.modifiers = modifiersex; |
---|
14084 | | - editObj = object.doEditClick(info, 0); |
---|
| 14384 | + //ClickInfo info = new ClickInfo(); |
---|
| 14385 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14386 | + object.clickInfo.pane = this; |
---|
| 14387 | + object.clickInfo.camera = renderCamera; |
---|
| 14388 | + object.clickInfo.x = x; |
---|
| 14389 | + object.clickInfo.y = y; |
---|
| 14390 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14391 | + editObj = object.doEditClick(//info, |
---|
| 14392 | + 0); |
---|
14085 | 14393 | if (!editObj) |
---|
14086 | 14394 | { |
---|
14087 | 14395 | hasMarquee = true; |
---|
.. | .. |
---|
14363 | 14671 | void GoDown(int mod) |
---|
14364 | 14672 | { |
---|
14365 | 14673 | MODIFIERS |= COMMAND; |
---|
| 14674 | + boolean isVR = (mouseMode&VR)!=0; |
---|
14366 | 14675 | /**/ |
---|
14367 | 14676 | if((mod&SHIFT) == SHIFT) |
---|
14368 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14677 | + { |
---|
| 14678 | + if (isVR) |
---|
| 14679 | + manipCamera.RotateInterest(0, -speed); |
---|
| 14680 | + else |
---|
| 14681 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14682 | + } |
---|
14369 | 14683 | else |
---|
14370 | | - manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14684 | + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); |
---|
14371 | 14685 | /**/ |
---|
14372 | 14686 | if ((mod & SHIFT) == SHIFT) |
---|
14373 | 14687 | { |
---|
.. | .. |
---|
14377 | 14691 | mouseMode |= BACKFORTH; |
---|
14378 | 14692 | } |
---|
14379 | 14693 | |
---|
| 14694 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14695 | + |
---|
14380 | 14696 | //prevX = X = anchorX; |
---|
14381 | 14697 | prevY = Y = anchorY - (int) (renderCamera.Distance()); |
---|
14382 | 14698 | } |
---|
.. | .. |
---|
14385 | 14701 | { |
---|
14386 | 14702 | MODIFIERS |= COMMAND; |
---|
14387 | 14703 | /**/ |
---|
| 14704 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14705 | + |
---|
14388 | 14706 | if((mod&SHIFT) == SHIFT) |
---|
14389 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14707 | + { |
---|
| 14708 | + if (isVR) |
---|
| 14709 | + manipCamera.RotateInterest(0, speed); |
---|
| 14710 | + else |
---|
| 14711 | + manipCamera.RotatePosition(0, speed); |
---|
| 14712 | + } |
---|
14390 | 14713 | else |
---|
14391 | | - manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14714 | + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); |
---|
14392 | 14715 | /**/ |
---|
14393 | 14716 | if ((mod & SHIFT) == SHIFT) |
---|
14394 | 14717 | { |
---|
.. | .. |
---|
14398 | 14721 | mouseMode |= BACKFORTH; |
---|
14399 | 14722 | } |
---|
14400 | 14723 | |
---|
| 14724 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14725 | + |
---|
14401 | 14726 | //prevX = X = anchorX; |
---|
14402 | 14727 | prevY = Y = anchorY + (int) (renderCamera.Distance()); |
---|
14403 | 14728 | } |
---|
.. | .. |
---|
14407 | 14732 | MODIFIERS |= COMMAND; |
---|
14408 | 14733 | /**/ |
---|
14409 | 14734 | if((mod&SHIFT) == SHIFT) |
---|
14410 | | - manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
| 14735 | + manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14411 | 14736 | else |
---|
14412 | | - manipCamera.RotatePosition(speed, 0); |
---|
| 14737 | + { |
---|
| 14738 | + if ((mouseMode&VR)!=0) |
---|
| 14739 | + manipCamera.RotateInterest(-speed, 0); |
---|
| 14740 | + else |
---|
| 14741 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14742 | + } |
---|
14413 | 14743 | /**/ |
---|
14414 | 14744 | if ((mod & SHIFT) == SHIFT) |
---|
14415 | 14745 | { |
---|
.. | .. |
---|
14419 | 14749 | mouseMode |= ROTATE; |
---|
14420 | 14750 | } // TRANSLATE; |
---|
14421 | 14751 | |
---|
| 14752 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14753 | + |
---|
14422 | 14754 | prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); |
---|
14423 | 14755 | prevY = Y = anchorY; |
---|
14424 | 14756 | } |
---|
.. | .. |
---|
14428 | 14760 | MODIFIERS |= COMMAND; |
---|
14429 | 14761 | /**/ |
---|
14430 | 14762 | if((mod&SHIFT) == SHIFT) |
---|
14431 | | - manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
| 14763 | + manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14432 | 14764 | else |
---|
14433 | | - manipCamera.RotatePosition(-speed, 0); |
---|
| 14765 | + { |
---|
| 14766 | + if ((mouseMode&VR)!=0) |
---|
| 14767 | + manipCamera.RotateInterest(speed, 0); |
---|
| 14768 | + else |
---|
| 14769 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14770 | + } |
---|
| 14771 | + |
---|
14434 | 14772 | /**/ |
---|
14435 | 14773 | if ((mod & SHIFT) == SHIFT) |
---|
14436 | 14774 | { |
---|
.. | .. |
---|
14440 | 14778 | mouseMode |= ROTATE; |
---|
14441 | 14779 | } // TRANSLATE; |
---|
14442 | 14780 | |
---|
| 14781 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14782 | + |
---|
14443 | 14783 | prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); |
---|
14444 | 14784 | prevY = Y = anchorY; |
---|
14445 | 14785 | } |
---|
.. | .. |
---|
14481 | 14821 | if (editObj) |
---|
14482 | 14822 | { |
---|
14483 | 14823 | drag = true; |
---|
14484 | | - ClickInfo info = new ClickInfo(); |
---|
14485 | | - info.bounds.setBounds(0, 0, |
---|
| 14824 | + //ClickInfo info = new ClickInfo(); |
---|
| 14825 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14486 | 14826 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14487 | | - info.pane = this; |
---|
14488 | | - info.camera = renderCamera; |
---|
14489 | | - info.x = x; |
---|
14490 | | - info.y = y; |
---|
14491 | | - object.GetWindow().copy |
---|
14492 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14827 | + object.clickInfo.pane = this; |
---|
| 14828 | + object.clickInfo.camera = renderCamera; |
---|
| 14829 | + object.clickInfo.x = x; |
---|
| 14830 | + object.clickInfo.y = y; |
---|
| 14831 | + object //.GetWindow().copy |
---|
| 14832 | + .doEditDrag(//info, |
---|
| 14833 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14493 | 14834 | } else |
---|
14494 | 14835 | { |
---|
14495 | 14836 | if (x < startX) |
---|
.. | .. |
---|
14638 | 14979 | } |
---|
14639 | 14980 | } |
---|
14640 | 14981 | |
---|
| 14982 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14983 | + |
---|
14641 | 14984 | public void mouseMoved(MouseEvent e) |
---|
14642 | 14985 | { |
---|
14643 | 14986 | //System.out.println("mouseMoved: " + e); |
---|
14644 | 14987 | if (isRenderer) |
---|
14645 | 14988 | return; |
---|
14646 | 14989 | |
---|
14647 | | - ClickInfo ci = new ClickInfo(); |
---|
14648 | | - ci.x = e.getX(); |
---|
14649 | | - ci.y = e.getY(); |
---|
14650 | | - ci.modifiers = e.getModifiersEx(); |
---|
14651 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14652 | | - ci.pane = this; |
---|
14653 | | - ci.camera = renderCamera; |
---|
| 14990 | + // Mouse cursor feedback |
---|
| 14991 | + object.clickInfo.x = e.getX(); |
---|
| 14992 | + object.clickInfo.y = e.getY(); |
---|
| 14993 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14994 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14995 | + object.clickInfo.pane = this; |
---|
| 14996 | + object.clickInfo.camera = renderCamera; |
---|
14654 | 14997 | if (!isRenderer) |
---|
14655 | 14998 | { |
---|
14656 | 14999 | //ObjEditor editWindow = object.editWindow; |
---|
14657 | 15000 | //Object3D copy = editWindow.copy; |
---|
14658 | | - if (object.doEditClick(ci, 0)) |
---|
| 15001 | + if (object.doEditClick(//clickInfo, |
---|
| 15002 | + 0)) |
---|
14659 | 15003 | { |
---|
14660 | 15004 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14661 | 15005 | } else |
---|
.. | .. |
---|
14927 | 15271 | // break; |
---|
14928 | 15272 | case 'T': |
---|
14929 | 15273 | CACHETEXTURE ^= true; |
---|
14930 | | - textures.clear(); |
---|
| 15274 | + texturepigment.clear(); |
---|
| 15275 | + texturebump.clear(); |
---|
14931 | 15276 | // repaint(); |
---|
14932 | 15277 | break; |
---|
14933 | 15278 | case 'Y': |
---|
.. | .. |
---|
15104 | 15449 | OCCLUSION_CULLING ^= true; |
---|
15105 | 15450 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15106 | 15451 | break; |
---|
15107 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15452 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15108 | 15453 | case '1': |
---|
15109 | 15454 | case '2': |
---|
15110 | 15455 | case '3': |
---|
15111 | 15456 | case '4': |
---|
15112 | 15457 | case '5': |
---|
15113 | | - newenvy = Character.getNumericValue(key); |
---|
15114 | | - repaint(); |
---|
15115 | | - break; |
---|
15116 | 15458 | case '6': |
---|
15117 | 15459 | case '7': |
---|
15118 | 15460 | case '8': |
---|
15119 | 15461 | case '9': |
---|
15120 | | - BGcolor = (key - '6')/3.f; |
---|
| 15462 | + if (true) // envyoff) |
---|
| 15463 | + { |
---|
| 15464 | + BGcolor = (key - '1')/8.f; |
---|
| 15465 | + } |
---|
| 15466 | + else |
---|
| 15467 | + { |
---|
| 15468 | + //newenvy = Character.getNumericValue(key); |
---|
| 15469 | + } |
---|
15121 | 15470 | repaint(); |
---|
15122 | 15471 | break; |
---|
15123 | 15472 | case '!': |
---|
.. | .. |
---|
15680 | 16029 | |
---|
15681 | 16030 | int width = getBounds().width; |
---|
15682 | 16031 | int height = getBounds().height; |
---|
15683 | | - ClickInfo info = new ClickInfo(); |
---|
15684 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15685 | 16032 | //Image img = CreateImage(width, height); |
---|
15686 | 16033 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15687 | 16034 | |
---|
.. | .. |
---|
15758 | 16105 | } |
---|
15759 | 16106 | if (object != null && !hasMarquee) |
---|
15760 | 16107 | { |
---|
| 16108 | + if (object.clickInfo == null) |
---|
| 16109 | + object.clickInfo = new ClickInfo(); |
---|
| 16110 | + ClickInfo info = object.clickInfo; |
---|
| 16111 | + //ClickInfo info = new ClickInfo(); |
---|
| 16112 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16113 | + |
---|
15761 | 16114 | if (isRenderer) |
---|
15762 | 16115 | { |
---|
15763 | | - info.flags++; |
---|
| 16116 | + object.clickInfo.flags++; |
---|
15764 | 16117 | double frameAspect = (double) width / (double) height; |
---|
15765 | 16118 | if (frameAspect > renderCamera.aspect) |
---|
15766 | 16119 | { |
---|
15767 | 16120 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15768 | | - info.bounds.width -= width - desired; |
---|
15769 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16121 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16122 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15770 | 16123 | } else |
---|
15771 | 16124 | { |
---|
15772 | 16125 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15773 | | - info.bounds.height -= height - desired; |
---|
15774 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16126 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16127 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15775 | 16128 | } |
---|
15776 | 16129 | } |
---|
15777 | 16130 | |
---|
15778 | | - info.g = gr; |
---|
15779 | | - info.camera = renderCamera; |
---|
| 16131 | + object.clickInfo.g = gr; |
---|
| 16132 | + object.clickInfo.camera = renderCamera; |
---|
15780 | 16133 | /* |
---|
15781 | 16134 | // Memory intensive (brep.verticescopy) |
---|
15782 | 16135 | if (!(object instanceof Composite)) |
---|
15783 | 16136 | object.draw(info, 0, false); // SLOW : |
---|
15784 | 16137 | */ |
---|
15785 | | - if (!isRenderer) |
---|
| 16138 | + if (!isRenderer) // && drag) |
---|
15786 | 16139 | { |
---|
15787 | 16140 | Grafreed.Assert(object != null); |
---|
15788 | 16141 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15790 | 16143 | { |
---|
15791 | 16144 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15792 | 16145 | |
---|
15793 | | - info.DX = 0; |
---|
15794 | | - info.DY = 0; |
---|
15795 | | - info.W = 1; |
---|
| 16146 | + object.clickInfo.DX = 0; |
---|
| 16147 | + object.clickInfo.DY = 0; |
---|
| 16148 | + object.clickInfo.W = 1; |
---|
15796 | 16149 | if (hitSomething == Object3D.hitCenter) |
---|
15797 | 16150 | { |
---|
15798 | 16151 | info.DX = X; |
---|
.. | .. |
---|
15804 | 16157 | info.DY -= info.bounds.height/2; |
---|
15805 | 16158 | } |
---|
15806 | 16159 | |
---|
15807 | | - object.drawEditHandles(info, 0); |
---|
| 16160 | + object.drawEditHandles(//info, |
---|
| 16161 | + 0); |
---|
15808 | 16162 | |
---|
15809 | 16163 | if (drag && (X != 0 || Y != 0)) |
---|
15810 | 16164 | { |
---|
15811 | 16165 | switch (hitSomething) |
---|
15812 | 16166 | { |
---|
15813 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16167 | + case Object3D.hitCenter: gr.setColor(Color.white); |
---|
15814 | 16168 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15815 | 16169 | break; |
---|
15816 | 16170 | case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
.. | .. |
---|
15836 | 16190 | if (hasMarquee) |
---|
15837 | 16191 | { |
---|
15838 | 16192 | gr.setXORMode(Color.white); |
---|
15839 | | - gr.setColor(Color.red); |
---|
| 16193 | + gr.setColor(Color.white); |
---|
15840 | 16194 | if (!firstime) |
---|
15841 | 16195 | { |
---|
15842 | 16196 | gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); |
---|
.. | .. |
---|
16303 | 16657 | private /*static*/ boolean firstime; |
---|
16304 | 16658 | private /*static*/ cVector newView = new cVector(); |
---|
16305 | 16659 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16660 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16661 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16306 | 16662 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16307 | 16663 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16308 | 16664 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16315 | 16671 | { |
---|
16316 | 16672 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16317 | 16673 | |
---|
| 16674 | + int usedsuf = 0; |
---|
| 16675 | + |
---|
16318 | 16676 | for (int i = 0; i < suffixes.length; i++) |
---|
16319 | 16677 | { |
---|
16320 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16321 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16322 | | - mipmapped, |
---|
16323 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16324 | | - if (data == null) |
---|
| 16678 | + String[] suffixe = suffixes; |
---|
| 16679 | + String[] fallback = suffixes2; |
---|
| 16680 | + String[] fallfallback = suffixes3; |
---|
| 16681 | + |
---|
| 16682 | + for (int c=usedsuf; --c>=0;) |
---|
16325 | 16683 | { |
---|
16326 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16684 | +// String[] temp = suffixe; |
---|
| 16685 | +// suffixe = fallback; |
---|
| 16686 | +// fallback = fallfallback; |
---|
| 16687 | +// fallfallback = temp; |
---|
16327 | 16688 | } |
---|
| 16689 | + |
---|
| 16690 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16691 | + TextureData data; |
---|
| 16692 | + |
---|
| 16693 | + try |
---|
| 16694 | + { |
---|
| 16695 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16696 | + mipmapped, |
---|
| 16697 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16698 | + } |
---|
| 16699 | + catch (Exception e) |
---|
| 16700 | + { |
---|
| 16701 | + try |
---|
| 16702 | + { |
---|
| 16703 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16704 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16705 | + mipmapped, |
---|
| 16706 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16707 | + } |
---|
| 16708 | + catch (Exception e2) |
---|
| 16709 | + { |
---|
| 16710 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16711 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16712 | + mipmapped, |
---|
| 16713 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16714 | + } |
---|
| 16715 | + } |
---|
| 16716 | + |
---|
16328 | 16717 | //System.out.println("Target = " + targets[i]); |
---|
16329 | 16718 | cubemap.updateImage(data, targets[i]); |
---|
16330 | 16719 | } |
---|
16331 | 16720 | |
---|
16332 | 16721 | return cubemap; |
---|
16333 | 16722 | } |
---|
| 16723 | + |
---|
16334 | 16724 | int bigsphere = -1; |
---|
16335 | 16725 | |
---|
16336 | 16726 | float BGcolor = 0.5f; |
---|
16337 | 16727 | |
---|
16338 | | - private void DrawSkyBox(GL gl) |
---|
| 16728 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16729 | + |
---|
| 16730 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16339 | 16731 | { |
---|
16340 | | - if (envyoff || cubemap == null) |
---|
| 16732 | + if (//envyoff || |
---|
| 16733 | + WIREFRAME || |
---|
| 16734 | + cubemap == null) |
---|
16341 | 16735 | { |
---|
16342 | 16736 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16343 | 16737 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16352 | 16746 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16353 | 16747 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16354 | 16748 | gl.glLoadIdentity(); |
---|
| 16749 | + gl.glScalef(1,ratio,1); |
---|
16355 | 16750 | |
---|
| 16751 | +// colorV[0] = 2; |
---|
| 16752 | +// colorV[1] = 2; |
---|
| 16753 | +// colorV[2] = 2; |
---|
| 16754 | +// colorV[3] = 1; |
---|
| 16755 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16756 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16757 | +// |
---|
| 16758 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16759 | + |
---|
16356 | 16760 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16357 | 16761 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16358 | 16762 | |
---|
.. | .. |
---|
16384 | 16788 | { |
---|
16385 | 16789 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16386 | 16790 | } |
---|
| 16791 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16387 | 16792 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16388 | 16793 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16389 | 16794 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16424 | 16829 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16425 | 16830 | |
---|
16426 | 16831 | cubemap.disable(); |
---|
16427 | | - ////cubemap.unbind(); |
---|
| 16832 | + //cubemap.dispose(); |
---|
| 16833 | + |
---|
16428 | 16834 | if (CULLFACE) |
---|
16429 | 16835 | { |
---|
16430 | 16836 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16642 | 17048 | //new Exception().printStackTrace(); |
---|
16643 | 17049 | System.out.println("select buffer init"); |
---|
16644 | 17050 | // Use debug pipeline |
---|
16645 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17051 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16646 | 17052 | |
---|
16647 | 17053 | GL gl = drawable.getGL(); |
---|
16648 | 17054 | |
---|
.. | .. |
---|
16960 | 17366 | |
---|
16961 | 17367 | public void init(GLAutoDrawable drawable) |
---|
16962 | 17368 | { |
---|
| 17369 | + if (Globals.DEBUG) |
---|
16963 | 17370 | System.out.println("shadow buffer init"); |
---|
16964 | 17371 | |
---|
16965 | 17372 | GL gl = drawable.getGL(); |
---|
.. | .. |
---|
17188 | 17595 | gl.glFlush(); |
---|
17189 | 17596 | |
---|
17190 | 17597 | /**/ |
---|
17191 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17598 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17192 | 17599 | |
---|
17193 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17600 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17194 | 17601 | |
---|
| 17602 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17603 | + |
---|
| 17604 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17605 | + |
---|
17195 | 17606 | double r = 0, g = 0, b = 0; |
---|
17196 | 17607 | |
---|
17197 | 17608 | double count = 0; |
---|
.. | .. |
---|
17202 | 17613 | |
---|
17203 | 17614 | double FACTOR = 1; |
---|
17204 | 17615 | |
---|
17205 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17616 | + for (int i = 0; i < depths.length; i++) |
---|
17206 | 17617 | { |
---|
17207 | 17618 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17208 | 17619 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17285 | 17696 | |
---|
17286 | 17697 | double scale = ray.z; // 1; // cos |
---|
17287 | 17698 | |
---|
17288 | | - float depth = pixels[newindex]; |
---|
| 17699 | + float depth = depths[newindex]; |
---|
17289 | 17700 | |
---|
17290 | 17701 | /* |
---|
17291 | 17702 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17482 | 17893 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17483 | 17894 | static IntBuffer bigAAbuffer; |
---|
17484 | 17895 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17485 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17896 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17486 | 17897 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17487 | 17898 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17488 | 17899 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17489 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17900 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17901 | + |
---|
| 17902 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17903 | + |
---|
17490 | 17904 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17491 | 17905 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17492 | 17906 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|