Mac TextureRenderer

Dunno if anyone is doing much with TextureRenderer on Mac, (including ImposterNode, etc.) but if you were then you probably noticed the terrible lag on Mac (see the .8 RenderToTexture webstart demos). As part of the fixes for .9, I’m happy to say this problem is now fixed. The problem was that glCopySubTexImage2D is really really slow on Mac vs. the standard glCopyTexImage2D. I originally programmed the latter because nVidia and ATI documentation suggested it was the faster approach. Anyhow, the change is in cvs and the PC and Mac both run well now with the PC version not showing any apparent speed loss.

I don

Eg I remember reading somewhere that Apple only includes OpenGL 1.2 drivers for Intel integrated graphics. (multitexture is 1.3) That doesn't mean Multitexture can't be made to work on the Mac/Intel IGP combination, but if the drivers report inaccurate capabilities, then we'd have to override that.



I don't own a Mac, let alone one with Intel graphics in it… so I can't even verify this.

How can I override that limitation, since the driver doesn't expose the call for multitexture?



I managed to use multi pass rendering, but I'd really appreciate if I could access the opengl directly from the hardware. I'm not sure this is possible, in lwjgl or any other binding… I think they rely on the driver implementation for accessing openGL functionality.



I have the mac box, as well as a PC properly equiped with a good X1800XT for testing advanced features, so I can try anything here.



My best regards…

One thing you could test is hacking LWJGLTextureState to see if you can get TestMultitexture to work properly for you.  You'd want to set supportsMultiTexture explicitly to true and numFixedTexUnits to 2 or more.

I'll try to download lwjgl source and get it to compile here to test this Rensanse. I'll let you all know if I have any success.

The class is part of jME :slight_smile:

This last post saved me a LOT of unnecessary efforts. Thanks again.



I'll keep on trying.

Ah, I see it was you in the other topic as well:



http://www.jmonkeyengine.com/jmeforum/index.php?topic=5088.0



If you dig into the code (mostly LWJGLTextureState I would guess) jME does some capability tests, for both OpenGL 1.3 or the multi texture extention, as well as the number of available texture units.



You can check what tests it does there and what it reports… from the look in the other topic it could very well be that it does report it's capable (possible through the extention), but since there's only one unit you can't use it. You can try overriding the number of units it reports in jME or in LWJGL.



Also, it looks like you could use mulitexturing if you rely on shaders instead of fixed function texture coordinates (the jME "TextureBuffer").



(ok, I see in the meanwhile Renanse types out something like this already)


Rensanse, I tried. Dunno if you're still online, but when changing suportsMultiTexture to true, it recognized the 8 fixed function texture units of the hardware. But the test for multitexture still didn't work. This is the output:


31/Mai/2007 14:50:37 com.jme.app.BaseGame start
INFO: Application started.
31/Mai/2007 14:50:37 com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
31/Mai/2007 14:50:37 com.jme.system.PropertiesIO load
INFO: Read properties
31/Mai/2007 14:50:41 com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
31/Mai/2007 14:50:41 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
31/Mai/2007 14:50:41 com.jme.system.lwjgl.LWJGLDisplaySystem getValidDisplayMode
INFO: Selected DisplayMode: 640 x 480 x 32 @0Hz
31/Mai/2007 14:50:41 com.jme.system.PropertiesIO save
INFO: Saved properties
31/Mai/2007 14:50:41 com.jme.app.BaseSimpleGame initSystem
INFO: jME version 0.11 beta
31/Mai/2007 14:50:41 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  640H: 480
31/Mai/2007 14:50:41 com.jme.app.BaseSimpleGame initSystem
INFO: Running on: null
Driver version: null
Intel Inc. - Intel GMA 950 OpenGL Engine - 1.2 APPLE-1.4.52
31/Mai/2007 14:50:41 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
31/Mai/2007 14:50:41 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
31/Mai/2007 14:50:41 com.jme.scene.Node <init>
INFO: Node created.
31/Mai/2007 14:50:41 com.jme.scene.Node <init>
INFO: Node created.
31/Mai/2007 14:50:41 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
31/Mai/2007 14:50:41 com.jme.scene.Node attachChild
INFO: Child (Box) attached to this node (rootNode)
This video card has a total of 16 texture units.
This video card has a total of 8 fixed function pipeline texture units.
This video card has a total of 16 units available for fragment shaders.
This video card has a total of 0 units available for vertex shaders.
java.lang.IllegalStateException: Function is not supported
at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:67)
at org.lwjgl.opengl.GL13.glActiveTexture(GL13.java:114)
at com.jme.scene.state.lwjgl.LWJGLTextureState.checkAndSetUnit(LWJGLTextureState.java:1136)
at com.jme.scene.state.lwjgl.LWJGLTextureState.load(LWJGLTextureState.java:232)
at com.jme.scene.state.lwjgl.LWJGLTextureState.apply(LWJGLTextureState.java:446)
at com.jme.renderer.lwjgl.LWJGLRenderer.applyStates(LWJGLRenderer.java:1568)
at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:920)
at com.jme.scene.batch.TriangleBatch.draw(TriangleBatch.java:249)
at com.jme.scene.TriMesh.draw(TriMesh.java:268)
at com.jme.scene.Spatial.onDraw(Spatial.java:231)
at com.jme.scene.Node.draw(Node.java:505)
at com.jme.scene.Spatial.onDraw(Spatial.java:231)
at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1131)
at com.jme.app.SimpleGame.render(SimpleGame.java:92)
at com.jme.app.BaseGame.start(BaseGame.java:69)
at jmetest.renderer.TestMultitexture.main(TestMultitexture.java:64)
31/Mai/2007 14:50:42 com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
31/Mai/2007 14:50:42 com.jme.app.BaseGame start
INFO: Application ending.

I'll check the lwjgl source online to see if the BufferCheck class is just doing the same test.

  at org.lwjgl.opengl.GL13.glActiveTexture(GL13.java:114)



it's using OpenGL13 while probably the Mac only supports it through the extention. Try replacing these calls with org.lwjgl.opengl.ARBMultitexture

OK, done, no errors anymore… With the ARBMultitexture, but NO multitexture yet… I forced supportsMultiTexture = true, and it recognized 8 fixed function texture units. Replaced the call to GL13 by ARBMultitexture. This time it ran, but no multitexture yet…



The output:


31/Mai/2007 15:46:48 com.jme.app.BaseGame start
INFO: Application started.
31/Mai/2007 15:46:48 com.jme.system.PropertiesIO <init>
INFO: PropertiesIO created
31/Mai/2007 15:46:48 com.jme.system.PropertiesIO load
INFO: Read properties
31/Mai/2007 15:46:50 com.jme.input.joystick.DummyJoystickInput <init>
INFO: Joystick support is disabled
31/Mai/2007 15:46:50 com.jme.system.lwjgl.LWJGLDisplaySystem <init>
INFO: LWJGL Display System created.
31/Mai/2007 15:46:50 com.jme.system.lwjgl.LWJGLDisplaySystem getValidDisplayMode
INFO: Selected DisplayMode: 640 x 480 x 32 @0Hz
31/Mai/2007 15:46:50 com.jme.system.PropertiesIO save
INFO: Saved properties
31/Mai/2007 15:46:50 com.jme.app.BaseSimpleGame initSystem
INFO: jME version 0.11 beta
31/Mai/2007 15:46:50 com.jme.renderer.lwjgl.LWJGLRenderer <init>
INFO: LWJGLRenderer created. W:  640H: 480
31/Mai/2007 15:46:50 com.jme.app.BaseSimpleGame initSystem
INFO: Running on: null
Driver version: null
Intel Inc. - Intel GMA 950 OpenGL Engine - 1.2 APPLE-1.4.52
31/Mai/2007 15:46:50 com.jme.renderer.AbstractCamera <init>
INFO: Camera created.
31/Mai/2007 15:46:50 com.jme.util.lwjgl.LWJGLTimer <init>
INFO: Timer resolution: 1000 ticks per second
31/Mai/2007 15:46:50 com.jme.scene.Node <init>
INFO: Node created.
31/Mai/2007 15:46:50 com.jme.scene.Node <init>
INFO: Node created.
31/Mai/2007 15:46:50 com.jme.scene.Node attachChild
INFO: Child (FPS label) attached to this node (FPS node)
31/Mai/2007 15:46:51 com.jme.scene.Node attachChild
INFO: Child (Box) attached to this node (rootNode)
This video card has a total of 16 texture units.
This video card has a total of 8 fixed function pipeline texture units.
This video card has a total of 16 units available for fragment shaders.
This video card has a total of 0 units available for vertex shaders.
31/Mai/2007 15:47:00 com.jme.app.BaseSimpleGame cleanup
INFO: Cleaning up resources.
31/Mai/2007 15:47:00 com.jme.app.BaseGame start
INFO: Application ending.


BTW, I'm running jmetest's TestMultitexture

I also checked that this hack generates strange results in other tests, with wrong texture coordinates or wrap modes. I'll keep on investigating.

These are the only changes I made to the LWJGLTextureState.java file:


         supportsMultiTexture = (GLContext.getCapabilities().GL_ARB_multitexture);
         //&& GLContext.getCapabilities().OpenGL13);



and...

   private void checkAndSetUnit(int i, TextureStateRecord record) {
      // If we support multtexturing, specify the unit we are affecting.
      // No need to worry about valid record, since invalidate sets record's
      // currentUnit to -1.
      if (supportsMultiTexture && record.currentUnit != i) {
         ARBMultitexture.glActiveTextureARB(GL13.GL_TEXTURE0 + i);
         //GL13.glActiveTexture(GL13.GL_TEXTURE0 + i);
         record.currentUnit = i;
      }
   }

Use org.lwjgl.opengl.ARBMultitexture.GL_TEXTURE0_ARB



Replacing all GL13 with ARB is not a solution, because other cards might only have GL13 and not ARB. Still, if this works, we might make seperate rendering paths or something.

Not yet…



Should I replace anything else? I tried replacing the contants substituition from ACS_GL_TEXTURE#… It was GL13.GL_TEXTURE#. I put ARBMultitexture.GL_TEXTURE#_ARB. But still no sign of functioning multitexture.

Well, just make sure there are no calls or constants used related to GL13.

We must not be the only middleware with this mac issue.  Is there any other information out there?  It seems pretty dumb that a modern card would have such crappy driver support, mac regardless.

Just for the records: I still didn't manage to make the multitexture feature works by using the ARBMultitexture extension. I replaced all the occurrencies of GL13 constants or method calls by those found in ARBTexture### and ARBMultitexture. I think I found all the necessary ones, with a proper substituition. Now the LWJGLTextureState class does not hava a single reference to GL13, witch is even out of the imports list.



The tests run, but still without the combined textures, just with the monkey one (#0). But I think there's something wrong with my hack, since some test are still showing strange results (TextTerrain for example, with a strange wrap). But now the tests are getting closer to showing the correct behavior, witch is, to me, being equal to the results before the hack.



I'm posting here the code I'm hacking for LWJGLTextureState, just to see if anyone dares to try it out in any box. It would be interesting if this code works in a diferent hardware, witch would show the hack is correct, maybe.



Thanks to all the support. You guys are awsome, and JME is great.



I'll post the code in another form, since it's quite big.