Hello Guest

[solved] Migration from immediate mode to VBO.

  • 0 Replies
  • 1842 Views
[solved] Migration from immediate mode to VBO.
« on: September 10, 2016, 20:25:44 »
Hi guys,

I started to develop a very complex CAD program with LWJGL (and SWT) for the LDraw community a few years ago.
The program has now over 100.000 lines of code and is called LDPartEditor.
I decided to use the old legacy API since the common user wont have a highend machine like I do.

Now, I want to implement a second render path with OpenGL 3.
I do not need realtime graphics and therefore I am not interested in aggressive micro optimization.


edit: Sorry! I was able to do the migration by myself.


The program is able to manipulate primitives (triangles, quads, lines, vertices) and submodels (groups of primitives).
There is also a manipulator tool similar to the tool which Blender uses.
It has build-in CSG features and it supports object picking.
Additionally, there is a text editor to edit the sourcecode of the 3D model and you will see the result immediately in the 3D editor (and vice versa).

Currently, I have objects which are able to draw themselves, e.g. a triangle class which has a draw method.

Code: [Select]

    @Override
    public void drawGL20(Composite3D c3d) {
        if (!visible)
            return;
        if (a < 1f && c3d.isDrawingSolidMaterials() || !c3d.isDrawingSolidMaterials() && a == 1f)
            return;
        if (!isTriangle) {
            // This triangle can be a protractor, too.
            drawProtractor(c3d, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3);
            return;
        }
        GL11.glBegin(GL11.GL_TRIANGLES);
        if (GData.globalNegativeDeterminant) {
            GL11.glColor4f(r, g, b, a);
            GL11.glNormal3f(xn, yn, zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x3, y3, z3);
            GL11.glVertex3f(x2, y2, z2);
            GL11.glNormal3f(-xn, -yn, -zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x2, y2, z2);
            GL11.glVertex3f(x3, y3, z3);
        } else {
            GL11.glColor4f(r, g, b, a);
            GL11.glNormal3f(xn, yn, zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x2, y2, z2);
            GL11.glVertex3f(x3, y3, z3);
            GL11.glNormal3f(-xn, -yn, -zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x3, y3, z3);
            GL11.glVertex3f(x2, y2, z2);
        }
        GL11.glEnd();
    }
To get the output, the renderer iterates all objects like a linked list and you'll see the model on the screen.
This approach is simple and very close to the LDraw File Format standard (its 100% compliant).

The current implementation of the render engine is modular.
I don't want to delete the old immediate mode render engine and I am able to write a new render class from scratch by just implementing the following methods:

Code: [Select]
    @Override
    public void init() {
        // Init goes here...
    }

    @Override
    public void drawScene() {
       
        // Render loop

        final GLCanvas canvas = c3d.getCanvas();
       
        if (!canvas.isCurrent()) {
            canvas.setCurrent();
            GL.setCapabilities(c3d.getCapabilities());
            // These capabilities are forward compatible!
        }
       
        // FIXME Render the 3D model, grid, GUI elements, etc. ...
       
       
        canvas.swapBuffers();
               
    }
   
    @Override
    public void dispose() {
        // TODO Dispose resources here...
    }


I can access the following data:
  • I have sets of vertices, lines and faces from the model.
  • I can also access positions, coulors, vertex and surface normals, UV coordinates and textures.

There are surfaces which have no textures, one texture or more than one texture.
A model can have many textures.
There are transparent and opaque surfaces, too.

At the moment, I don't know what to do... :(

How should I start the migration?
Should I design a shader first?
Should I focus on the creation of the VBOs?
How do I group the VBOs?
How can I expand my horizons to learn something about VBOs with very dynamic data?

Leg godt

Nils


A screenshot from an earlier version with texture mapping:


Impressions from the latest stable release

Thanks guys, for creating LWJGL!  ;)

« Last Edit: September 12, 2016, 15:16:29 by BlackBrick89 »