Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  (Yet another) Java Scene Graph  (Read 4649 times)
0 Members and 1 Guest are viewing this topic.
Offline tom
« Posted 2008-10-09 18:56:12 »

I've decided to release the source for the scene graph I've been working on for while. The code can be found on google code.

Its a fast and simple scene graph with little overhead. Some of the features supported:
-multipass rendering
-render to texture using pbo
-shaders
-cube maps
-view frustum culling against bounding spheres
-state sorting
-front to back and back to front sorting using radix sort
-optimisations on shapes with either static state, model matrix or vertex data

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2008-10-09 19:30:27 »

I have a few (very shallow) comments on the code.

1. IMMIDIATE --> IMMEDIATE Tongue

In GLState.applyDiff(...) there are bugs in the logic:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
                if (polygonOffsetFillEnabled != state.polygonOffsetFillEnabled) {
                        polygonOffsetFillEnabled = state.polygonOffsetFillEnabled;
                        if (polygonOffsetFillEnabled) {
                                glEnable(GL_POLYGON_OFFSET_FILL);
                                if (polygonOffsetFactor != state.polygonOffsetFactor
                                                || polygonOffsetUnits != state.polygonOffsetUnits) {
                                        polygonOffsetFactor = state.polygonOffsetFactor;
                                        polygonOffsetUnits = state.polygonOffsetUnits;
                                        glPolygonOffset(polygonOffsetFactor, polygonOffsetUnits);
                                }
                        } else {
                                glDisable(GL_POLYGON_OFFSET_FILL);
                        }
                }


now glPolygonOffset(polygonOffsetFactor, polygonOffsetUnits); is only called when a bunch of conditions apply. So when only polygonOffsetFactor is changed, the difference won't be applied.


Now this is just one example, but the same bug is everywhere in GLState.applyDiff(...), like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
if (depthTestEnabled != state.isDepthTestEnabled()) {
                        depthTestEnabled = state.isDepthTestEnabled();
                       
                        if (depthTestEnabled) {
                                glEnable(GL_DEPTH_TEST);
                                if (depthFunc != state.getDepthFunc()) {
                                        depthFunc = state.getDepthFunc();
                                        glDepthFunc(depthFunc.get());
                                }
                        } else {
                                glDisable(GL_DEPTH_TEST);                      
                        }
                }
\

Which has the same problem with glDepthFunc(...); - The value is only applied when depthTestEnabled was toggled.





Or maybe I did just miss something?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2008-10-09 19:36:33 »

IMHO it should be like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
     boolean depthTestToggle = depthTestEnabled != state.isDepthTestEnabled();
     if (depthTestToggle) {
            depthTestEnabled = state.isDepthTestEnabled();
                       
            if (depthTestEnabled) {
                     glEnable(GL_DEPTH_TEST);
            } else {
                     glDisable(GL_DEPTH_TEST);                      
            }
       }

       boolean depthFuncChanged = depthFunc != state.getDepthFunc();
       if(depthFuncChanged && depthTestEnabled)
       {
             depthFunc = state.getDepthFunc();
             glDepthFunc(depthFunc.get());
       }

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2008-10-09 20:17:03 »

Thanks Riven! This is in fact a bug. Checked in a fix in SVN.

Nice to see someone taking the time to find some bugs Smiley

...and I know I can't spell Smiley

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2008-10-09 20:35:59 »

(!) same problem in GLState.applyLight(..)



further, about code readability, consider these two logically identical code listings:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
void stuff()
{
   if(someFlag)
   {
      // do
      // lots
      // of
      // complex
      // things
   }
   else
   {
       throw new IllegalStateException("Problem");
   }
}

vs.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
void stuff()
{
   if(!someFlag)
       throw new IllegalStateException("Problem");

   // do
   // lots
   // of
   // complex
   // things
}



Or, like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
for(.....)
{
       if(....) {
            if(....) {
                  // stuff!
                  // stuff!
                  // stuff!
                  // stuff!
                  // stuff!
                  // stuff!
            }
       }
}

vs.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
for(.....)
{
       if( ! ....)
           continue;
       if( ! ....)
           continue;

       // stuff!
       // stuff!
       // stuff!
       // stuff!
       // stuff!
       // stuff!
}




I find that reducing the indentation level in your sourcecode makes it easier to read, and easier do fix. After all it was Linus who said that if you have more than 3 indentation levels (in your method) you're screwed anyway. I tend to strongly agree with that, but he also said that Linux is so fast, it does an infinite loop in 2 seconds... so go figure.

Another nice idea might be to make your methods max 10-15 lines. Split those massive methods into nice little chunks, with self descriptive names. The JIT will also take advantage of that, btw.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline gouessej
« Reply #5 - Posted 2008-10-10 10:05:49 »

It is interesting, I'm going to watch your source code. Thank you very much for releasing it. I have some questions:
- Why is it bound to LWJGL? Sad
- Why are there only DLLs under the lib directory???
- Is your source code not cross-platform?
- Why do you use vecmath whereas it produces a lot of garbage? (it often bothers the garbage collector)

Online princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2008-10-10 10:59:08 »

If it's LWJGL, it is cross platform. And why not bind it to LWJGL? Got to bind it to something.

Cas Smiley

Offline gouessej
« Reply #7 - Posted 2008-10-10 11:40:20 »

If it's LWJGL, it is cross platform. And why not bind it to LWJGL? Got to bind it to something.

Cas Smiley
Maybe it would be better to write something that abstracts the OpenGL binding to drive it easier to use another binding.

Offline aldacron

Senior Duke


Medals: 9
Exp: 16 years


Java games rock!


« Reply #8 - Posted 2008-10-10 12:27:14 »

Maybe it would be better to write something that abstracts the OpenGL binding to drive it easier to use another binding.

Or maybe not. Not every 3D rendering library on the planet needs to be abstracted to such a degree. Some are, some aren't. Life goes on.
Offline tom
« Reply #9 - Posted 2008-10-10 13:19:33 »

- Why is it bound to LWJGL? Sad
Because I've used LWJGL for a long time, and I like it. I see no advantage in supporting both LWJGL and JOGL. It is good enough that it works on one of them.

I am interested in creating either a DirectX renderer or a new DirectX scene graph. This is something want to look into in the future.

- Why are there only DLLs under the lib directory???
Because I use windows and I had the files available when I uploaded to SVN. I might provide the other binaries later. They are only needed to run the single test that is included.

- Is your source code not cross-platform?
I don't know. Haven't tested it on anything but windows. I assume it is since all my code is Java and LWJGL is cross-platform.

- Why do you use vecmath whereas it produces a lot of garbage? (it often bothers the garbage collector)
Because it is a full featured, mature and will tested vecmath library. It do produce some garbage in some cases, like inverting a matrix. This is not big problom in most situations. I also think there is more garbage friendly implementation that one can use simply by replacing the jar (not completely sure about this). The vecmath source code is open. It can be fixed if this turns out to be a problem.

Making it cross platform is not the most important goal of this project. Although it would be nice to get it running on max. Don't care if it runs on linux  Tongue

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2008-10-10 13:39:52 »

The only vecmath.jar replacement I've seen is this one:

http://www.objectclub.jp/download/vecmath_e

but it's pretty much defunct and doesn't claim any garbage improvements. However, as you say the original vecmath is now open source so you could always fix that one.

You might also consider OpenMali (https://openmali.dev.java.net/) which apparantly contains a reworked vecmath. Never used it myself so can't say if it's any better.

Kev

Offline tom
« Reply #11 - Posted 2008-10-10 13:51:22 »

Yes, I was thinking of Kenji Hiranabe's javax.vecmath implementation. I thought Xith3D used it a long time ago because performance was better. But maybe it was used just because it was free.

Offline jezek2
« Reply #12 - Posted 2008-10-10 13:58:23 »

OpenMaLi contains both original Sun's Vecmath reimplementation (evolved version of Kenji Hiranabe's implementation with reduced memory allocation and under BSD license) and their own version (called Vecmath2, but it's not successor to Sun's Vecmath, it's just different project).

About the DLLs... I don't see any problem here, it uses LWJGL so it's crossplatform, you can compile it yourself and it will most likely work out of the box. Not everyone have access to various OSes and care about other platforms. Though I don't like when there is no technical problem to support other platforms and it's refused by author... even when the support is contributed. Which I believe is not this case.

About JOGL, you can port it yourself. I find it quite ridiculous to have abstraction for different OpenGL bindings, as in the end it's about the same calls to underlying OpenGL library... And you can even mix LWJGL and JOGL's contexts if needed.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (50 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (36 views)
2014-10-15 16:18:58

TehJavaDev (66 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!