www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Achim on January 02, 2010, 10:44:08 am

Title: problems migrating to Windows 7 64 bits
Post by: Achim on January 02, 2010, 10:44:08 am
Hi, I am moving my application to my new Windows 7 64 bit system and have memory problems when using the HW renderer (sw rendering works fine). I am thinking this may have to do with 32bit libs. The error I am getting is after creating the HW FrameBuffer (which doesn't show anything except the background in the specified color):

Loading Texture...karoXY.jpg
Loading Texture...karoYZ.jpg
Loading Texture...karoXZ.jpg
Loading Texture...karobw.jpg
Loading Texture...envmap-alu.jpg
Java version is: 1.6.0_14
-> support for BufferedImage
Version helper for 1.2+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Using LWJGL's AWTGLCanvas
Adding Lightsource: 0
Driver is: RDPDD/null on NVIDIA Corporation / GeForce GT 220/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Hardware supports textures up to 8192*8192 in size!
Additional visibility list (2) created with size: 4096
Additional visibility list (3) created with size: 4096
Additional visibility list (4) created with size: 4096
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Direct buffer memory
   at java.nio.Bits.reserveMemory(Bits.java:633)
   at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
   at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
   at com.threed.jpct.GLBase.convertTexture(Unknown Source)
   at com.threed.jpct.GLBase.setRenderTarget(Unknown Source)
   at com.threed.jpct.AWTGLRenderer.executeGL(Unknown Source)
   at com.threed.jpct.AWTJPCTCanvas.paintGL(Unknown Source)
   at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:288)
   at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:317)
   at sun.awt.RepaintArea.updateComponent(RepaintArea.java:239)
   at sun.awt.RepaintArea.paint(RepaintArea.java:216)
   at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:306)
   at java.awt.Component.dispatchEventImpl(Component.java:4706)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

The code runs OK in my old Windows XP environment. Any suggestions of what I could do? (I am using  lwjgl 2.2.1 already)

Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 02, 2010, 02:05:43 pm
Looks like as if you are using shadow mapping? If yes, what is the size of the shadow map? If not, what else is the render target that you seem to use? The amount of direct memory is somehow derived from the amount of VM memory. So the first option would be to increase that by doing an -Xmx1024m or similar. If that doesn't help, you can specify the amount of direct memory at startup with the parameter -XX:MaxDirectMemorySize=<your size> in the same way you are doing it with -Xmx.

Hope this helps...
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 04, 2010, 10:09:23 pm
Just out of curiosity: Did it work?
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 06, 2010, 04:06:06 pm
no :-(
I am indeed using shadows, but did not have any problems on my old XP installation. I am also experiencing funy behaviour with SW rendering. Swing components used in a sibling panel (both are components of a frame) are flashed briefly at location 0,0 of the panel with the OpneGL buffer....

Achim
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 06, 2010, 05:40:46 pm
Is this somehow a remote desktop connection (judging from that strange Drivername "RDPDD")? That's a very strange name for a display adapter and the only thing i can find about this name is the remote desktop. I've no idea if this is related to the problem though.
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 06, 2010, 08:31:01 pm
Maybe you could try this little test program:

Code: [Select]
import java.nio.*;

public class MallocTest {

public static void main(String[] args) {
allocate(256 * 256);
allocate(512 * 512);
allocate(1024 * 1024);
allocate(2048 * 2048);
allocate(4096 * 4096);
allocate(8192 * 8192);
}

private static void allocate(int size) {
int bytes = size << 2;
System.out.println("Allocating " + bytes + " bytes of direct memory!");
try {
ByteBuffer tmp = ByteBuffer.allocateDirect(bytes);
tmp.order(ByteOrder.LITTLE_ENDIAN);
} catch (Throwable t) {
System.out.println("Failed to allocate " + bytes + " bytes!");
return;
}
System.out.println("Succeded to allocate " + bytes + " bytes!");
}
}


Edit: What's the size of your shadow map?
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 08, 2010, 05:24:27 pm
output:

C:\Oracle\Middleware\jdk160_14_R27.6.5-32\bin\javaw.exe -client -classpath "C:\dev\jpctTests\simpleTest\classes;C:\Program Files (x86)\Java\jpct\lib\jpct\jpct.jar;C:\Program Files (x86)\Java\jpct\lib\lwjgl-2.0\jar\jinput.jar;C:\Program Files (x86)\Java\jpct\lib\lwjgl-2.0\jar\lwjgl.jar;C:\Program Files (x86)\Java\jpct\lib\lwjgl-2.0\jar\lwjgl_test.jar;C:\Program Files (x86)\Java\jpct\lib\lwjgl-2.0\jar\lwjgl_util.jar;C:\Program Files (x86)\Java\jpct\lib\lwjgl-2.0\jar\lwjgl_util_applet.jar" MallocTest
Allocating 262144 bytes of direct memory!
Succeded to allocate 262144 bytes!
Allocating 1048576 bytes of direct memory!
Succeded to allocate 1048576 bytes!
Allocating 4194304 bytes of direct memory!
Succeded to allocate 4194304 bytes!
Allocating 16777216 bytes of direct memory!
Succeded to allocate 16777216 bytes!
Allocating 67108864 bytes of direct memory!
Failed to allocate 67108864 bytes!
Allocating 268435456 bytes of direct memory!
Failed to allocate 268435456 bytes!
Process exited with exit code 0.

with -Xmx1024m :

Allocating 262144 bytes of direct memory!
Succeded to allocate 262144 bytes!
Allocating 1048576 bytes of direct memory!
Succeded to allocate 1048576 bytes!
Allocating 4194304 bytes of direct memory!
Succeded to allocate 4194304 bytes!
Allocating 16777216 bytes of direct memory!
Succeded to allocate 16777216 bytes!
Allocating 67108864 bytes of direct memory!
Succeded to allocate 67108864 bytes!
Allocating 268435456 bytes of direct memory!
Succeded to allocate 268435456 bytes!
Process exited with exit code 0.

I also switched off shadow maps - still the same error ...
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 08, 2010, 05:43:04 pm
That makes no sense to me... ??? The test case works as expected and so should the application...

However, i'm wondering why you are using the 32bit version of Java!? Maybe that's the problem? Have you tried with the 64bit version instead? In addition, please try this jar instead of the official one: http://www.jpct.net/download/beta/jpct.jar (http://www.jpct.net/download/beta/jpct.jar). If you are setting Config.glVerbose to true, it will print out some more information when uploading the textures. Please give it a try and post the log.
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 08, 2010, 06:18:14 pm
thanks for your help, Egon.
I am using jdeveloper and installed what I beleived was teh 64bit version - this apparently included the 32bit JDK, however. Now I am traing to find out how one can force jdeveloper to use another, i.e. 64bit JDK (or at least configure the run options for a program to use a difference JVM from the one installed with jdeveloper)
The box demo runs in my current setup, however. I will try the jpcr beta over the weekend.

Update: now running in 64bit JVM. It works now, but very slow (much slower than the SW renderer), and also with shadows. I did System.setProperty("sun.java2d.d3d", "false"); as you suggested some time ago, but this did not have a visible effect.
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 08, 2010, 07:25:28 pm
Maybe it's using OpenGL's software fallback? Are you using the drivers that come with Windows 7? If so, please install one from NVidia directly to see if that helps. The MS drivers that come with the OS don't support HW-acceleration for OpenGL. That's of course not because MS wants you to use DirectX instead, it's just because....they want you to use DirectX instead... ;)
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 08, 2010, 08:31:47 pm
I do have the lates NVIDA driver - version 195.62.
I am not sure though whether that is used automatically for OpenGL (Windows making it more difficult than necessary ?), or whether you would have to change some settings...
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 08, 2010, 08:36:27 pm
No, you don't have to do anything else...could you post the complete log that jPCT prints out when running your application?
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 12:14:38 am
I did some research based on your first log and i think that this "rdpdd"-thing could be the problem. This seems to be the "remote desktop protocol display driver", which is not the one that i want to use. But i'm not sure how to change that nor that i even can do it from outside of LWJGL.

Could you please try to run this little test and post the output?

Code: [Select]
import java.awt.*;

public class GDTest {
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
for (GraphicsDevice gd : gds) {
System.out.println(gd.getIDstring());
GraphicsConfiguration[] gcs = gd.getConfigurations();
for (GraphicsConfiguration gc : gcs) {
System.out.println("--> " + gc.toString());
}
}
}
}
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 01:23:31 pm
In addition, you could try if the native OpenGL support shows the same effect. You could either use one of the examples for that or download the terrain demo from here: http://www.jpct.net/download/misc/terrain.zip (http://www.jpct.net/download/misc/terrain.zip) (i hope that 64bit lwjgl stuff is already included there...). It prints out the frame rate to the console. On a current system with a lowly graphics card like yours, i would expect it to produce 50-70fps at the starting position without moving the mouse.
I'm also interested if this renderer still says RDPDD as driver/card name.

Edit: A member of the lwjgl forum suggest to try to start with these parameters:

Code: [Select]
-Dsun.java2d.noddraw=true -Dsun.awt.noerasebackground=true -Dsun.java2d.d3d=false -Dsun.java2d.opengl=false -Dsun.java2d.pmoffscreen=false

I highly doubt that this will do any good, but you never know...
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 09, 2010, 03:19:33 pm
will try the things you suggested above. In the meantime, here the log of the startup with the new jpct beta:
C:\Oracle\Middleware\jdk1.6.0_17\bin\javaw.exe -server -classpath C:\dev\TensegrityDesign\ClientAppOpenGL\classes;C:\dev\TensegrityDesign\jdom\build\jdom.jar;C:\dev\TensegrityDesign\jpct\lib\lwjgl-2.2.1\jar\lwjgl_util.jar;C:\dev\TensegrityDesign\jpct\lib\lwjgl-2.2.1\jar\lwjgl.jar;C:\dev\TensegrityDesign\jpct\lib\lwjgl-2.2.1\jar\jinput.jar;C:\dev\TensegrityDesign\jpct\lib\lwjgl-2.2.1\jar\lwjgl_util_applet.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-antlr.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-apache-bcel.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-apache-bsf.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-apache-log4j.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-apache-oro.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-apache-regexp.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-apache-resolver.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-commons-logging.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-commons-net.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-jai.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-javamail.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-jdepend.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-jmf.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-jsch.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-junit.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-launcher.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-netrexx.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-nodeps.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-starteam.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-stylebook.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-swing.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-trax.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant-weblogic.jar;C:\Oracle\Middleware\jdeveloper\ant\lib\ant.jar;C:\dev\TensegrityDesign\jpct\lib\lwjgl-2.2.1\native\windows;C:\dev\TensegrityDesign\jpct\lib\jpct_beta\jpct.jar -Djava.library.path=C:\dev\TensegrityDesign\jpct\lib\lwjgl-2.2.1\native\windows\ Tensegrity3DApplet -Xmx1024m
Loading Texture...karoXY.jpg
Loading Texture...karoYZ.jpg
Loading Texture...karoXZ.jpg
Loading Texture...karobw.jpg
Loading Texture...envmap-alu.jpg
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Using LWJGL's AWTGLCanvas
Adding Lightsource: 0
Driver is: RDPDD/6.1.7600.16385 on NVIDIA Corporation / GeForce GT 220/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Hardware supports textures up to 8192*8192 in size!
Additional visibility list (2) created with size: 4096
Software renderer disposed
Additional visibility list (3) created with size: 4096
Additional visibility list (4) created with size: 4096
Allocating 268435456 bytes of direct memory!
Allocating 268435456 bytes of direct memory!
Allocating 262144 bytes of direct memory!
Caching 262144 bytes of direct memory!

then my output messages start
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 03:27:24 pm
Many thanks. Judging from the log, you are creating 2 textures with 256mb each. That means that you have two textures, each 8192*8192 in size. I assume that at least one is a shadow map. But what's the other one? Is it a normal texture map with that enormous size? Or are you rendering into two gl contexts, i.e. into two frame buffer? Anyway, 8192*8192 is very large and with a lowly card like the 220, may run out of texture memory but you run out of processing power for sure. Try to lower to size of the textures/shadow maps to 1024 or 2048 to see if that helps with performance. Maybe that RDPDD thing isn't the problem then...
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 03:37:39 pm
I've looked into jPCT's shadow code a little deeper. The two textures with 256mb each both belong to the shadow map. One is for alpha and one for depth information. I've tried to render a 8192*8192 shadow map on my ATI Radeon 5870...it didn't work at all even if the card can do up to 16384*16384 in theory. It's just too big. Try to lower the size...
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 09, 2010, 04:03:18 pm
this is the output of your test program above:
\Display0
--> D3DGraphicsConfig[dev=D3DGraphicsDevice[screen=0],pixfmt=0]
Process exited with exit code 0.

The parameters suggested by the lwgl forum had no effect.

terrain demo: inital fps approx. 130, after some flying around 270 ....

I have to look at the shadow maps. Curious thing is though that on my old system with onboard graphics (!) everything worked allright (it was a 3.6 GHz system, though).


Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 05:27:00 pm
Most likely because your old system didn't support such large maps. jPCT falls back to the maximum size the hardware supports. If it had Intel onboard graphics, it didn't even support an offscreen buffer, so the max size of the shadow map was limited to the largest power of two that fits on screen, which usually doesn't exceed 1024.
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 09, 2010, 05:40:53 pm
Perhaps I am doing somthing really stupid - therefore here the code snippet which sets up the shadow map:

    void setupShadowCaster() {
        if (!SW_RENDERING) {
            sh = null;
            if (useShadows) {
                projector = new Projector();
                projector.setPosition(sun.getPosition());
                projector.lookAt(md.getTransformedCenter());        //NOTE: this requires that structure is setup first
                projector.setFOV(0.7f); //set this value large enough so that the complete shadow is casted
                projector.setYFOV(0.7f);
    
                sh = new ShadowHelper(world, buffer, projector, 1024);
                sh.addReceiver(background);
                sh.setAmbientLight(new Color(64, 64, 64)); //sets the color of the shadow
               // sh.setFiltering(true);
            }
        }
    }

when using HW renderer and Shadow map (i.e. SW_RENDERING = false, useShadows=true)

Loading Texture...karoXY.jpg
Loading Texture...karoYZ.jpg
Loading Texture...karoXZ.jpg
Loading Texture...karobw.jpg
Loading Texture...envmap-alu.jpg
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Using LWJGL's AWTGLCanvas
Adding Lightsource: 0
Thread[AWT-EventQueue-0,6,main]
Driver is: RDPDD/6.1.7600.16385 on NVIDIA Corporation / GeForce GT 220/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Hardware supports textures up to 8192*8192 in size!
Additional visibility list (2) created with size: 4096
Additional visibility list (3) created with size: 4096
Additional visibility list (4) created with size: 4096
Allocating 4194304 bytes of direct memory!
Caching 4194304 bytes of direct memory!
Allocating 262144 bytes of direct memory!
Caching 262144 bytes of direct memory!


>>> Very slow.


Setting useShadows to false: buffer is only cleared, nothing is rendered (but my simulation worker thread is running)

Loading Texture...karoXY.jpg
Loading Texture...karoYZ.jpg
Loading Texture...karoXZ.jpg
Loading Texture...karobw.jpg
Loading Texture...envmap-alu.jpg
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.5+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Using LWJGL's AWTGLCanvas
Adding Lightsource: 0
Driver is: RDPDD/6.1.7600.16385 on NVIDIA Corporation / GeForce GT 220/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)

no rendering at all after this (buffer is only cleared)....
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 06:06:25 pm
Setup of the shadows looks fine to me. Can i have a look at the actual render code (i.e. the call to render(...) and that stuff)?

Edit: When not rendering the shadows, make sure that you a) are doing the correct world.render(...); world.draw(...); sequence yourself and b) ensure that you haven't setup the ShadowHelper even if you are not using it later. It adds an additional texture layer for the shadows, which will cause the rendering to look strange if not used later.

Here's a test program in native OpenGL mode. It renders a simple scene with shadows (can be disabled in the code by setting a flag). It prints its frame rate to the console. Please give it a try and report the results.

Code: [Select]
import java.awt.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class SimpleShadows {

private FrameBuffer fb = null;
private World world = null;
private Object3D plane = null;
private Object3D cube = null;
private Object3D sphere = null;
private Projector projector=null;
private ShadowHelper sh = null;
private Light sun=null;

private boolean shadows=true;

public SimpleShadows() {
Logger.setOnError(Logger.ON_ERROR_THROW_EXCEPTION);
Config.glColorDepth = 24;
Config.glFullscreen = false;
Config.farPlane = 1000;
Config.glShadowZBias = 0.8f;
Config.glTrilinear=true;
Config.glUseFBO=true;
}

private void initStuff() throws Exception {
fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
world = new World();
fb.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);

Config.lightMul=1;

plane = Primitives.getPlane(20, 30);
plane.rotateX((float) Math.PI / 2f);

cube=Primitives.getCube(15);
cube.setAdditionalColor(Color.RED);
cube.translate(0, -30, -10);

sphere=Primitives.getSphere(12);
sphere.translate(0, 0, -50);
sphere.setAdditionalColor(new Color(0,0,50));

world.addObject(sphere);
world.addObject(plane);
world.addObject(cube);

plane.compile(false);
cube.compile(false);
sphere.compile(false);

projector = new Projector();

if (shadows) {
sh = new ShadowHelper(world, fb, projector, 1024);
sh.setCullingMode(false);
sh.addCaster(cube);
sh.addCaster(sphere);
sh.addReceiver(plane);
sh.addReceiver(cube);
sh.addReceiver(sphere);
sh.setAmbientLight(new Color(30,30,30));
sh.setFiltering(true);
}

world.setAmbientLight(90,90,90);
world.buildAllObjects();

sun=new Light(world);
sun.setIntensity(250, 250, 250);
}

private void doIt() throws Exception {
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.lookAt(plane.getTransformedCenter());

projector.setFOV(0.5f);
projector.setYFOV(0.5f);

SimpleVector pos=cube.getTransformedCenter();

projector.setPosition(pos);
projector.moveCamera(Camera.CAMERA_MOVEUP, 200);
projector.lookAt(pos);
SimpleVector offset=new SimpleVector(1,0,-1).normalize();
projector.moveCamera(offset, 215);

int fps=0;
long time=System.currentTimeMillis();

while (!org.lwjgl.opengl.Display.isCloseRequested()) {
projector.lookAt(cube.getTransformedCenter());
offset.rotateY(0.007f);
projector.setPosition(pos);
projector.moveCamera(new SimpleVector(0,-1,0), 200);
projector.moveCamera(offset, 215);
SimpleVector sp=projector.getPosition();
sp.y+=150;
sun.setPosition(sp);
sun.setAttenuation(-1);

if (shadows) {
sh.updateShadowMap();
fb.clear();
sh.drawScene();
} else {
fb.clear();
world.renderScene(fb);
world.draw(fb);
}

fb.update();
fb.displayGLOnly();

if (System.currentTimeMillis() - time >= 1000) {
System.out.println(fps);
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}
fb.disableRenderer(IRenderer.RENDERER_OPENGL);
fb.dispose();
System.exit(0);
}

public static void main(String[] args) throws Exception {
SimpleShadows cd = new SimpleShadows();
cd.initStuff();
cd.doIt();
}
}

Edit: And here's the same thing for the AWTGLRenderer:

Code: [Select]
import java.awt.*;

import javax.swing.JFrame;

import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class SimpleShadowsAWT implements IPaintListener {

private FrameBuffer fb = null;
private World world = null;
private Object3D plane = null;
private Object3D cube = null;
private Object3D sphere = null;
private Projector projector=null;
private ShadowHelper sh = null;
private Light sun=null;
private JFrame frame;
private Canvas canvas;
private int fps=0;
private long time=System.currentTimeMillis();

private boolean shadows=true;

public SimpleShadowsAWT() {
Logger.setOnError(Logger.ON_ERROR_THROW_EXCEPTION);
Config.glColorDepth = 24;
Config.glFullscreen = false;
Config.farPlane = 1000;
Config.glShadowZBias = 0.8f;
Config.glTrilinear=true;
Config.glUseFBO=true;
}

private void initStuff() throws Exception {
fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
world = new World();
canvas=fb.enableGLCanvasRenderer();
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);

frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.add(canvas);
fb.setPaintListener(this);

Config.lightMul=1;

plane = Primitives.getPlane(20, 30);
plane.rotateX((float) Math.PI / 2f);

cube=Primitives.getCube(15);
cube.setAdditionalColor(Color.RED);
cube.translate(0, -30, -10);

sphere=Primitives.getSphere(12);
sphere.translate(0, 0, -50);
sphere.setAdditionalColor(new Color(0,0,50));

world.addObject(sphere);
world.addObject(plane);
world.addObject(cube);

plane.compile(false);
cube.compile(false);
sphere.compile(false);

projector = new Projector();

if (shadows) {
sh = new ShadowHelper(world, fb, projector, 1024);
sh.setCullingMode(false);
sh.addCaster(cube);
sh.addCaster(sphere);
sh.addReceiver(plane);
sh.addReceiver(cube);
sh.addReceiver(sphere);
sh.setAmbientLight(new Color(30,30,30));
sh.setFiltering(true);
}

world.setAmbientLight(90,90,90);
world.buildAllObjects();

sun=new Light(world);
sun.setIntensity(250, 250, 250);
}

private void doIt() throws Exception {
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 150);
cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
cam.lookAt(plane.getTransformedCenter());

projector.setFOV(0.5f);
projector.setYFOV(0.5f);

SimpleVector pos=cube.getTransformedCenter();

projector.setPosition(pos);
projector.moveCamera(Camera.CAMERA_MOVEUP, 200);
projector.lookAt(pos);
SimpleVector offset=new SimpleVector(1,0,-1).normalize();
projector.moveCamera(offset, 215);

while (frame.isShowing()) {
projector.lookAt(cube.getTransformedCenter());
offset.rotateY(0.007f);
projector.setPosition(pos);
projector.moveCamera(new SimpleVector(0,-1,0), 200);
projector.moveCamera(offset, 215);
SimpleVector sp=projector.getPosition();
sp.y+=150;
sun.setPosition(sp);
sun.setAttenuation(-1);

if (shadows) {
sh.updateShadowMap();
fb.clear();
sh.drawScene();
} else {
fb.clear();
world.renderScene(fb);
world.draw(fb);
}

fb.update();
fb.displayGLOnly();
canvas.repaint();
Thread.yield();
}
fb.dispose();
System.exit(0);
}

public static void main(String[] args) throws Exception {
SimpleShadowsAWT cd = new SimpleShadowsAWT();
cd.initStuff();
cd.doIt();
}

public void finishedPainting() {
if (System.currentTimeMillis() - time >= 1000) {
System.out.println(fps);
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}

public void startPainting() {
}
}

Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 09, 2010, 09:21:40 pm
output for the awtgl version (runs like a charm):
Code: [Select]
Java version is: 1.6.0_17
-> support for BufferedImage
Version helper for 1.2+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Using LWJGL's AWTGLCanvas
Software renderer disposed
Driver is: RDPDD/6.1.7600.16385 on NVIDIA Corporation / GeForce GT 220/PCI/SSE2
GL_ARB_texture_env_combine supported and used!
FBO supported and used!
OpenGL renderer initialized (using 4 texture stages)
Hardware supports textures up to 8192*8192 in size!
Adding Lightsource: 0
Subobject of object 2/object4 compiled using 2400 vertices in 62ms!
Object 2/object4 compiled to 1 subobjects in 101ms!
Subobject of object 0/object2 compiled using 2400 vertices in 19ms!
Object 0/object2 compiled to 1 subobjects in 29ms!
Subobject of object 1/object3 compiled using 48 vertices in 0ms!
Object 1/object3 compiled to 1 subobjects in 0ms!
Additional visibility list (2) created with size: 4096
Additional visibility list (3) created with size: 4096
Compiled 3 display lists!
8
54
60
61
60
61
60
60
61
60
61
61
60
Visibility lists disposed!

my rendering code:
Code: [Select]
    @Override   
    public void paint(Graphics g) {
        final int millisToPaint = 1000/framesPerSec;   //time interval for new paint (in thread awt)
        long millisSinceLastPaint = System.currentTimeMillis()-lastTimePainted;
        if (millisSinceLastPaint < millisToPaint) {
             try { thread.sleep(millisToPaint - millisSinceLastPaint); }
             catch (Exception e) {
                System.out.println(Thread.currentThread());
                System.out.println("$3 " + e);
             }
        }  else {
        try {
           // System.out.println("paint called at" + System.currentTimeMillis());
            buffer.clear(Color.DARK_GRAY);
            md.synchPositions();
            if (SW_RENDERING) {
//                if (millisSinceLastPaint < millisToPaint) { 
//                    thread.sleep(millisToPaint - millisSinceLastPaint);
//                }
                world.renderScene(buffer);
                world.draw(buffer);
                drawAnnotations();
                buffer.update();
                buffer.display(g);
            } else {
                if (sh != null) {
                     sh.updateShadowMap();
                    sh.drawScene();
                }
                drawAnnotations();
                buffer.update();
                buffer.displayGLOnly();
                canvas.repaint();
            }
        } catch (Exception e) {
            //the SW renderer sometimes produces concurrent access and nullpointer exceptions
            System.out.println(Thread.currentThread());
            System.out.println("$3 " + e + " " + canvas);
        }
        lastTimePainted = System.currentTimeMillis();
         }
    }
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 10:12:12 pm
60fps for the small test application isn't exactly great, but judging from the value, it seems to be limited by vertical sync (i.e. 60 HZ monitor refresh rate). jPCT doesn't use vsync by default in the native OpenGL renderer, but it's not possible to turn it off in the AWTGLRenderer because it sits on top of AWT, which uses it. Try to disable it in the driver settings to see how high the peek performance actually is.

However...back to your rendering code. The reason why everything is black when disabling shadows is obvious: You are not rendering anything at all in that case. Just change that part to

Code: [Select]
if (sh != null) {
     sh.updateShadowMap();
     sh.drawScene();
} else {
     world.renderScene(buffer);
     world.draw(buffer);
}

and make sure that you aren't creating the shadow helper at all in this case.

Personally, i suggest to not put the rendering code into paint() but in some other thread. You are putting a heavy load to the awt event dispatch thread (EDT) when doing this, which will make your GUI feel more sluggish than it has to. In addition, you are destroying the multi threaded nature of the AWTGLRenderer with this. This renderer does the actual painting in the EDT anyway (it has to, because it's bound to AWT), but the calls to renderScene() and draw() can and should be executed in another thread. That way, you are separating the calculations from the actual drawing, which will speed up things on multi core cpus. Can't you put this code into your own simulation worker thread and leave paint() alone? That should also fix the problems with...

Quote
//the SW renderer sometimes produces concurrent access and nullpointer exceptions

...because: No it doesn't. The renderer is stable. It's just that jPCT isn't thread safe (http://www.jpct.net/wiki/index.php/Multithreading#Thread_safety (http://www.jpct.net/wiki/index.php/Multithreading#Thread_safety)), so when doing the rendering in the EDT and manipulating the objects in another thread, you'll run into troubles...as you've obviously noticed judging from this comment... ;)

To summarize:


Hope this helps...

BTW: Can i download this app somewhere, so that i could run it on my own machines to see how it performs on them?





Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on January 09, 2010, 10:45:49 pm
Hi Egon,
I knew there must have been a stupid mistake - I'm still confused though, since this code ran on the old machine when shadowing is turned off. I also am skeptical whether your suggestions would increase the frame rate from the currently 1 fps (for medium complexity objects like the one you showed in the demo reel. Simpler ones are a bit faster).

I will let the problem rest for a while and take a fresh look at it in a couple of days, and also have a closer look at your examples.

Thanks a lot for your help so far.
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on January 09, 2010, 10:57:59 pm
I also am skeptical whether your suggestions would increase the frame rate from the currently 1 fps (for medium complexity objects like the one you showed in the demo reel. Simpler ones are a bit faster).
Me too...they were mostly meant as general hints to make your code work as similar as possible to mine, so that it's easier to find the real problem and to get rid of the problem that your comment in the catch block implies. 1fps is really low... ???

But at least we can conclude that your system itself seems to be fine. Maybe it's a Swing related problem!? If you are adventurous, you can also give the Jogl-renderer a try (http://www.jpct.net/wiki/index.php/The_different_renderers#JOGL_support (http://www.jpct.net/wiki/index.php/The_different_renderers#JOGL_support)), to see if that changes something.
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on April 10, 2010, 11:21:39 pm
an update: in the meantime I have rewritten my app and cleaned up the multithreading model - I now have a main loop doing the jpct rendering, each tensegrity obejct has its own relaxation thread, the user interaction in the awt thread, delegating modifications to the objects to either the main thread or the tensegrity object threads.

This solved the problem - no speed issues any more. However, I still have trouble getting the shadow to work. After setting up the shadow helper, everything looks perfect until I move the camera. After a while, the shadowhelper seems to confuse the camera with the projector - the shadow jumps as if the camera is the shadow-casting light source. This happens faster and more often for big objects - strange.
Also, I notices if you set up the shadow helper while the canvas is not visible yet, the constructor waits indefinitely for an opportunity to paint into the awtgl canvas (jpct1.9 and 2.0 beta). You then have to kill the Java VM process.
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on April 11, 2010, 09:23:28 pm
Quote
This solved the problem - no speed issues any more. However, I still have trouble getting the shadow to work. After setting up the shadow helper, everything looks perfect until I move the camera. After a while, the shadowhelper seems to confuse the camera with the projector - the shadow jumps as if the camera is the shadow-casting light source. This happens faster and more often for big objects - strange.
The shadow helper switched cameras of the world. If your code does something similar in another thread, it may get confused. Are you doing something like that in your code? If so, try to synchronize that with the calls to the ShadowHelper to see if that helps. I'll have a look at my code too to see, if i did something wrong though.

Quote
Also, I notices if you set up the shadow helper while the canvas is not visible yet, the constructor waits indefinitely for an opportunity to paint into the awtgl canvas (jpct1.9 and 2.0 beta). You then have to kill the Java VM process.
Yes...the helper needs information from the GL context to initialize but without a visible canvas, no context is there...so it'll wait forever. I'll see if i can hack around this somehow or at least replace the infinite loop with an error instead.
Title: Re: problems migrating to Windows 7 64 bits
Post by: EgonOlsen on April 11, 2010, 09:47:07 pm
You might want to give this beta of 1.21 a try: http://www.jpct.net/download/beta/jpct.jar (http://www.jpct.net/download/beta/jpct.jar)
It synchronizes some ShadowHelper internals to some camera related methods in World. Maybe that helps....and maybe not... ;)

In addition, it treats an invisible canvas as an error. Depending on the setting in Logger, this will cause jPCT to raise an exception or the application to crash but at least doesn't cause an infinite loop anymore.
Title: Re: problems migrating to Windows 7 64 bits
Post by: Achim on April 11, 2010, 11:04:57 pm
Hi Egon,
many thanks for the quick reply - I briefly tested the new jpct.jar - it doesn't solve my problem - I have to look closer and check whether some synchronisation helps.
I didn't test the improved error handling yet - I keep you updated on my progress.

btw: I will be presenting tensegrities in general and my tensegrity CAD program at RTT Excite - a conference the Munich-based visualization company holds every year - and will of cause mention jpct.
Achim