Page 1 of 1

Emulation ideas ..

PostPosted: Thu Sep 17, 2020 11:39 am
by Ian
I had some thoughts about a somewhat of a refactoring of the model3 opengl code .. in my renderer.
Basically how the texturing works currently is when a model references a texture, the new3d renderer cuts out that texture from the texture sheet and well makes a standard opengl texture from it.
This works nicely, but due to the way models reference overlapping textures, quite often we'll make say 8+ textures out of the 4 textures in the sheet.
It also makes invalidation quite expensive because we have to loop through memory and check for overlapping textures.

Basically instead of this we could simply pass the entire texture sheet to the shaders unmodified, and read the textures directly out of memory. Opengl 4+ can read unsigned16 bit textures, which is what the model3 uses. In opengl 4+ you can also do unsigned integer math in shaders, which is simply not possible in glsl 1.0 or 1.2. With unsigned integer math we can do code like this

Code: Select all
            texel = src[yi * 2048 + xi] & 0xFF;
            c = ((texel >> 4) & 0xF) * 17;
            scratch[i++] = c;
            scratch[i++] = c;
            scratch[i++] = c;
            scratch[i++] = (c == 255 ? 0 : 255);


Anyway this might potentially (on decent gpus) give us a speed up. It would also simplify the code a lot.

But we would need opengl 4+, and I know there are people out there on OLD gpus.
But like with nvidia now releasing 8nm GPUs with totally insane performance, do we really want to be stuck in the past forever? :s

OpenGL 4.1 came out 10 years ago now.

Re: Emulation ideas ..

PostPosted: Thu Sep 17, 2020 1:43 pm
by Bart
This is similar to what the legacy engine does, isn't it? Except that I don't upload the raw texture data. Rather, it is pre-decoded into multiple texture sheets based on each possible format. I think since the legacy engine was designed, we've discovered that there are far more permutations of textures than initially anticipated (e.g., the 4-bit textures), so maybe this isn't practical?

Re: Emulation ideas ..

PostPosted: Thu Sep 17, 2020 1:54 pm
by Ian
Yes the legacy engine is similar. But you are uploading like X amount of texture sheets, one for each texture type.
My idea is to just upload the raw data, and extract the relevant colour information directly in the shader itself. So really only need to bind 1 texture.

The problem is we can't do the integer math required with gl2 ..

Re: Emulation ideas ..

PostPosted: Thu Sep 17, 2020 11:21 pm
by SegaLover2020
Ian wrote:But like with nvidia now releasing 8nm GPUs with totally insane performance, do we really want to be stuck in the past forever? :s
OpenGL 4.1 came out 10 years ago now.


As a side note, even intel integrated graphics support opengl 4.4 now. In fact I've noticed a fair increase in performance with recent drivers, and these "video cards" are part of many modern processors.

Re: Emulation ideas ..

PostPosted: Fri Sep 18, 2020 10:49 am
by Bart
Ian wrote:Yes the legacy engine is similar. But you are uploading like X amount of texture sheets, one for each texture type.
My idea is to just upload the raw data, and extract the relevant colour information directly in the shader itself. So really only need to bind 1 texture.


Right. Your idea sounds better. And simpler on the CPU side. I think we should go for it :) IIRC, OpenGL isn't being updated anymore anyway, right?

I wish I had time to fix up the legacy engine a bit. I don't think there's much I can do on the texture and alpha front but the lighting could probably be improved.