Next engine, MRT

Next engine

I am currently thinking on the architecture of my next game engine, and first I need to do some studies on the underlying graphical/game engine to be used:

  • Unity 5: it seems to be more affordable now, but every time I read about implementing some voxels in it on reddit it seems only some prototype that rely on “hacks” are developed, when it comes to doing on actual game it is a lot more complex. And second thing is that it is not really linux friendly (game I have tested have some bugs due to Unity, and there’s no editor yet)
  • Unreal Engine: it was already affordable, but now it’s just free :) they are more linux friendly, but I don’t really know if voxel engine could be done, needs more investigations (but I think it will be like Unity)
  • LibGdx: I love this engine, but if I want to do some more complex stuff I might be limited by OpenGL ES 2. For 2d it’s enough but when it comes to 3d it might be too limiting.
  • Lwjgl: I have enough 3d knowledge now to work directly with Lwjgl, problem is it does not support Android, so I will have to drop all android support.

What I might end up doing is a mix between the LibGdx & the Lwjgl solutions, basically I will sometimes have to call directly some Lwjgl functions on desktop, and have some workaround on Android (for example no shadows on Android, but shadows on desktop). And even maybe try to have an OpenGL 3 context in LibGdx (but again just for desktop)



In light of above “solution” I have played a bit with  Multiple Render Target today, in order to have them working you need to call a Lwjgl function directly.

So what I did is implement a custom FrameBuffer that supports MRT, basically the initialization method becomes something like:

handle = BufferUtils.newIntBuffer(numTexture);
gl.glGenFramebuffers(numTexture, handle);
gl.glBindFramebuffer(GL20.GL_FRAMEBUFFER, handle.get(0));
for (int i = 0; i < numTexture; i++)
    gl.glBindTexture(GL20.GL_TEXTURE_2D, colorTexture[i].getTextureObjectHandle());
    gl.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0 + i, GL20.GL_TEXTURE_2D, colorTexture[i].getTextureObjectHandle(), 0);
IntBuffer drawBuffers = BufferUtils.newIntBuffer(numTexture);
for (int i = 0; i < numTexture; i++)
    drawBuffers.put(i, GL20.GL_COLOR_ATTACHMENT0 + i);

Where Platform.instance is an interface that gets implemented in the Desktop project

import org.lwjgl.opengl.GL20;

public class LwjglPlatform implements IPlatform
    public void glDrawBuffers(IntBuffer buffers)

And then I can call the different render targets in the fragment shader

gl_FragData[0]     = vec4(1.0,0.0,0.0,1.0);
gl_FragData[1]     = vec4(0.0,1.0,0.0,1.0);

It seems to work fine so far, but I just began playing with that. I began working on a pull request on LibGdx to add cube map support, but sadly MRT being desktop only I think it couldn’t fit in LibGdx, so I won’t include this part. But:

  • I’ll try to come up with a clean version that could be download here
  • I’ll try to update my shadow mapping tutorial to include a part 5 using MRT

Comments are closed.