Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
188 user(s) are online (170 user(s) are browsing Forums)

Members: 1
Guests: 187

trixie, more...

Support us!

Headlines

 
  Register To Post  

(1) 2 »
3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@All
Tried to build ScummVM with enabling of GL_ARB_fragment_program (which basics surely works as can be see from that thread: https://www.amigans.net/modules/newbb/viewtopic.php?topic_id=8733), and have rendering issues with some game.

There are details with all screenshoots:

https://bugs.scummvm.org/ticket/13351

On 3rd comment you can see what we found: once we use GL_ARB_fragment_program, GL4ES also tried to use GL_EXT_frag_depth if available, and so create 2 additional internal shaders:

#version 100
#extension GL_EXT_frag_depth : enable
precision highp float;
precision highp int;
varying mediump vec4 _gl4es_TexCoord_0;
uniform sampler2D _gl4es_Sampler2D_0;

void main() {
        
vec4 gl4es_FragDepthTemp vec4(gl_FragDepthEXT);
        
vec4 d;
        
        
texture2D(_gl4es_Sampler2D_0_gl4es_TexCoord_0.xy);
        
gl4es_FragDepthTemp d.xxxx;
        
        
gl_FragDepthEXT gl4es_FragDepthTemp.z;
}


and

#version 100
precision highp float;
precision highp int;
varying mediump vec4 _gl4es_TexCoord_0;
uniform vec4 _gl4es_Fragment_ProgramLocal_0;
uniform sampler2D _gl4es_Sampler2D_0;

void main() {
        
vec4 level _gl4es_Fragment_ProgramLocal_0;
        
vec4 color;
        
vec4 d;
        
vec4 sum;
        
        
texture2D(_gl4es_Sampler2D_0_gl4es_TexCoord_0.xy);
        
sum d.xxxx;
        
sum sum d.yyyy;
        
sum sum d.zzzz;
        
sum sum vec4(0.3300000.3300000.3300000.330000);
        
sum sum level.xxxx;
        
gl_FragColor.sum.x;
        
gl_FragColor.sum.y;
        
gl_FragColor.sum.z;
        
}



Now, with those 2 shaders added, things start renders bad and wrong. When there is no those 2 shaders, then all renders fine.

I even tried simple to do "setenv LIBGL_NOARBPROGRAM 1", and everything fixes, as no more those 2 shaders created.

Now, question, what do we can do next and how to test functionality of things involved in those 2 shaders ? As GL_ARB_fragment_program somehow works at least, i think it can be something about GL_EXT_frag_depth , but have anyone any idea how to test it , etc?

I for myself think of disabling GL_EXT_frag_depth extensions usage inside of the GL4ES, so to see if it is which is guilty.

Thanks!

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

Have you tried to modify those shaders, for example hardcode some values? What happens if you change gl_FragColor.w (alpha channel) to 1.0 in the latter? It doesn't seem to be initialized.

It would be interesting to know also what is passed via _gl4es_Fragment_ProgramLocal_0 uniform. glSnoop should be able to show that.

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Quote:

Have you tried to modify those shaders, for example hardcode some values? What happens if you change gl_FragColor.w (alpha channel) to 1.0 in the latter? It doesn't seem to be initialized.


Only tried so far to remove "#extension GL_EXT_frag_depth : enable" from shader, and that make no differences for bug.

Will test other stuff you suggest


Quote:

It would be interesting to know also what is passed via _gl4es_Fragment_ProgramLocal_0 uniform. glSnoop should be able to show that.



There is a full ogles2 trace (without warp3dnova calls, to avoid unnecessary stuff for now) from glsnoop when i run scummvm, choose a game, and exit from:

https://kas1e.mikendezign.com/aos4/scummvm/ogles2_snoop.txt

(see from the line 2480, where first "new" ARB shader created).

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Quote:

It would be interesting to know also what is passed via _gl4es_Fragment_ProgramLocal_0 uniform. glSnoop should be able to show that.


Rechecked logs myself, and not sure if glsnoop show us anything interesting about ?

I also do for now that:

I tried to just comment out S("GL_EXT_frag_depth ", fragdepth, 1); in hardtex.c of GL4ES, so LIBGL didn't use now that extension, and while i still have rendering problem, shaders now looks like this:

#version 100
precision highp float;
mediump float fakeFragDepth 0.0;
precision highp int;
varying mediump vec4 _gl4es_TexCoord_0;
uniform sampler2D _gl4es_Sampler2D_0;

void main() {
    
vec4 gl4es_FragDepthTemp vec4(fakeFragDepth);
    
vec4 d;
    
    
texture2D(_gl4es_Sampler2D_0_gl4es_TexCoord_0.xy);
    
gl4es_FragDepthTemp d.xxxx;
    
    
fakeFragDepth gl4es_FragDepthTemp.z;
}


and

#version 100
precision highp float;
precision highp int;
varying mediump vec4 _gl4es_TexCoord_0;
uniform vec4 _gl4es_Fragment_ProgramLocal_0;
uniform sampler2D _gl4es_Sampler2D_0;

void main() {
    
vec4 level _gl4es_Fragment_ProgramLocal_0;
    
vec4 color;
    
vec4 d;
    
vec4 sum;
    
    
texture2D(_gl4es_Sampler2D_0_gl4es_TexCoord_0.xy);
    
sum d.xxxx;
    
sum sum d.yyyy;
    
sum sum d.zzzz;
    
sum sum vec4(0.3300000.3300000.3300000.330000);
    
sum sum level.xxxx;
    
gl_FragColor.sum.x;
    
gl_FragColor.sum.y;
    
gl_FragColor.sum.z;
    
}


See, first one changes : it not didn't use Depth Frag extension, but instead some "fakeddepth" , but bug still here.

So it probabaly safe to assume now, that issue not because of extension, and it probably a second shader.

But with second shader i have a hard time to understand from where it come. I tried to search in the whole ScummVM sources on the words "sum" , or on "vec4 d" , and in ScummVM found a shit about. But then i also found notihng about in GL4ES too! Wtf, from where that second shader come then ?

It should be from ScummVM imho, some kind of ARB shader generator, just i can't find where.


Edited by kas1e on 2022/3/15 13:57:40
Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
I think i found from where that new ARB shader code : from ScummVM, in the GRIM's code. There are 2 arb shaders, but they are in some strange-for-me-mnemonic-format, see:

https://github.com/scummvm/scummvm/blo ... s/grim/gfx_opengl.cpp#L54

I mean that how it looks like:

static char dimFragSrc[] =
    
"!!ARBfp1.0\n\
    PARAM level = program.local[0];\n\
    TEMP color;\n\
    TEMP d;\n\
    TEX d, fragment.texcoord[0], texture[0], 2D;\n\
    TEMP sum;\n\
    MOV sum, d.r;\n\
    ADD sum, sum, d.g;\n\
    ADD sum, sum, d.b;\n\
    MUL sum, sum, 0.33;\n\
    MUL sum, sum, level.x;\n\
    MOV result.color.r, sum;\n\
    MOV result.color.g, sum;\n\
    MOV result.color.b, sum;\n\
    END\n"
;


So that kind of "old syntax" shader sends to the GL4ES, and GL4ES tranlate them to proper GLSL shaders firstly, there is that parser:

https://github.com/ptitSeb/gl4es/blob/master/src/gl/arbgenerator.c


Which make for us firstly that:

#version 120

void main() {
    
vec4 level gl_ProgramLocal[0];
    
vec4 color;
    
vec4 d;
    
vec4 sum;
    
    
texture2D(gl_Sampler2D_0gl_TexCoord[0].xy);
    
sum d.xxxx;
    
sum sum d.yyyy;
    
sum sum d.zzzz;
    
sum sum vec4(0.330.330.330.33);
    
sum sum level.xxxx;
    
gl_FragColor.sum.x;
    
gl_FragColor.sum.y;
    
gl_FragColor.sum.z;
    
}


And then gl4es add a bit of changes on top for internal needs to have it works on ogles2.

Was there some different GLSL kind language back in days for ARB shaders ?


Anyway, i added to that "strange" shader "MOV result.color.a, 1.0;\n\" at end, and so consructred shader looks like this:

gl_FragColor.sum.x;
    
gl_FragColor.sum.y;
    
gl_FragColor.sum.z;
    
gl_FragColor.vec4(1.0,1.0,1.0,1.0).w;


But rendering didn't changes, but still there.

The fact, that when we disable ARB shaders via "LIBGL_NOARBPROGRAM 1" and have all works, make me think that maybe ARB shader generator in GL4ES not works as expected and have bugs (or, which is more lucky, it didn't have bugs, but we do have on ogles2/warp3dnova front)


EDIT: oh, find out, ARB shaders was pre-GLSL language which were ditch later. I just messed things a bit with our SDL2 testshaders.c case , as while it use ARB extensions, the shaders it use are of GLSL format, and not of original-oldshcool ARB one while in GRIM-ScummVM those ARB shaders are real oldschool ones.


Edited by kas1e on 2022/3/15 17:00:23
Edited by kas1e on 2022/3/15 17:01:07
Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill

It turns out that the same issue happens on GL4ES on X86/Linux, so, nothing for us to worry about for the moment as this probably will be fixed inside of GL4ES.

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Turned out that this issues (with bad rendering of person) and with main hero overwrite some parts of screen can't be fixed easyly:

The main problem is that pixel conversion function (gl4es_glDrawPixel() ) doesn't handle depth component at all. But ptitSeb says that:

Quote:

Problem is on gles hardware, we cannot do most of the things we can do on full opengl hardware with depth buffer (and stencil buffer).
I remember, back when residual was independant from scummvm, that I needed to hack the opengl code to get correct rendering of the caracters, because the operation done by on the engine on the depth buffer were just not supported on the gles2 hardware of the Pandora.


But the glDrawPixel(...) on depth or stencil, well, I don't know how to do that with gles2 hardware...


That turns out to be non fixable seems ? At least only by rewriting parts of game's code to not use depth or something..

Instead , we then better to go pure OGLES2 route which scummvm support as well, and fix issues in OGLES2 (or in shaders if Daniel/Hans will have no interest about), and just not use GL4ES for ScummVM.


But then , Pure OGLES2 build have some issues too (meaning no GL4ES usage, just pure olges2). See the video:

https://www.youtube.com/watch?v=zD5q9Q6_YnU

See, there we have rendered only half of hero. Have any idea what can cause this in shaders ? GRIM use a lot of shaders , there they all are:

https://github.com/scummvm/scummvm/tree/master/engines/grim/shaders


There isn't much shaders from all those in use when Manny is drawn. By using glSnoop (damn how good we have that), i find out that those shaders are loaded up when we run game:

Quote:

1. grim_background
2. grim_smush
3. grim_text
4. grim_emerg
5. grim_actor
6. grim_actorlight
7. grim_dim


But the shaders which is "rendering of the hero" are grim_actor and grim_actorlight pair:

https://github.com/scummvm/scummvm/blo ... aders/grim_actor.fragment
https://github.com/scummvm/scummvm/blo ... shaders/grim_actor.vertex

https://github.com/scummvm/scummvm/blo ... grim_actorlights.fragment
https://github.com/scummvm/scummvm/blo ... s/grim_actorlights.vertex

We find out there, that issue is that :

vec2 sampled texture(texZBufzCoord texcropZBuf).ra;
    
float sceneZ sampled.sampled.256.0;


the texZBuf it's a special texture because it's internalformat is GL_LUMINANCE_ALPHA. so it has two channels and we load it raw data. then when you look at the shader, you load r and a, as x and y, and then you do basically a load to make them read like a short (on a range from 0 to 1 instead of 0 to 655536).

So i just switch sampled.y and sampled.x and this helped much, then i also uncomment in shaders #define SGSPLUS_FIX, but not with offsetY 32, but with 0.0. And that fix all issue.

In end it looks like that:

1). scummvm shaders should be fixed for x/y stuff, so bug in shaders.

2). it seems ogles2 doees not do flipping as all OpenGL surfaces
should be ? I.e. there problem with top/down.

But hope tomorrow we will find more about. But at least we make it works ! And i have sometime up to 200 FPS ! See:

https://youtu.be/w3TcaBVQOIU


Edited by kas1e on 2022/3/20 22:02:58
Edited by kas1e on 2022/3/20 22:04:35
Edited by kas1e on 2022/3/20 22:05:27
Edited by kas1e on 2022/3/20 22:05:54
Edited by kas1e on 2022/3/20 22:29:35
Edited by kas1e on 2022/3/20 22:32:24
Edited by kas1e on 2022/3/20 23:09:35
Edited by kas1e on 2022/3/20 23:10:16
Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

Lots of things, I just state the obvious regarding:

Quote:

The main problem is that pixel conversion function (gl4es_glDrawPixel() ) doesn't handle depth component at all


However, our HW is not limited to OGLES2 features technically, but isn't it more like OpenGL 4.x? https://en.wikipedia.org/wiki/Radeon_HD_7000_series

Then it's another thing what can be supported via our APIs. I'm not familiar with glDrawPixel(s?) though, never used it.

Quote:

it seems ogles2 doees not do flipping as all OpenGL surfaces
should be ? I.e. there problem with top/down.


I didn't understand quite this issue. aglSwapBuffers() not working?

Quote:

And i have sometime up to 200 FPS


Great!

Ps. those vertex shader do division by dot(), and result of dot product can be zero, so it could have some glitch depending on inputs.

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Quote:

I didn't understand quite this issue. aglSwapBuffers() not working?


There some strange issue we found, which seems ogles2 related, but we didn't sure at moment (one of scummvms coders still trying to made a test case for). The issue is about vertical flips of depth with textures , which seems should happens automatically on all opengl realisations (at least, it seems so on Mesa and Odroid).

I.e. we have a person , which just overwrite by his own rendering the parts at bottom which he should. We think before that nothing works, but, we found that "depth" coordinates just AT TOP of scene, while should be at the bottom.


He still trying to create test case, because he fear he can be wrong, so can't explain normally issue. But i can say that thing is: we have that issue and on direct OGLES2, and via GL4ES, which can point that roots come from OGLES2/Nova/whatever. s

We do fix thos "top-down flipped depth" issue it in grim_actor and grim_actorlight shaders like this:

changing 1.0-(gl_FragCoord.y-0.5)/screenSize.y to (gl_FragCoord.y-0.5)/screenSize.y

There those 2 shaders i talk about:

https://github.com/scummvm/scummvm/blo ... aders/grim_actor.fragment
https://github.com/scummvm/scummvm/blo ... grim_actorlights.fragment

So because of that we make an opinion that "texture with depth" , or "depth for texture" is not flipped as texture itself while should.

But important moment :

We don't use depth textures in GL with shaders as it, we use GL_LUMINANCE_ALPHA for depth there.

So issue can be that unpopular GL_LUMINANCE_ALPHA for example as well.

I.e. all we know for now (without test case at the moment), is that :

1. The texture2D (in the code we use texture but there is a define in the code which says that texture is texture2D) is used everywhere, so this function seems to work for classic textures

2. we don't use depth textures in GL with shaders, we use GL_LUMINANCE_ALPHA.

3. So what OpenGL says is that when you create such texture and fill it, it's like all the others except that R G and B are equals (to luminance) and A is set to A. Then when you read in the shader it must work like all other textures.

But in our case it doesn't seem to work. So maybe there is a bug in OGLES2 when handling GL_LUMINANCE_ALPHA textures.

Maybe problem happens because our GLES2 implementation don't support DEPTH with 16 bits of precision.

If you have any idea about, plz feel free :) Maybe you even may have some tests cases about GL_LUMINANCE_ALPHA textures , etc showing that all works/not works as expected ?


Edited by kas1e on 2022/3/25 5:46:48
Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

There was glFragCoord origin issue earlier: http://www.amiga.org/developer/bugreports/view.php?id=410

Have you asked Hans about this yet?

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Quote:

There was glFragCoord origin issue earlier: http://www.amiga.org/developer/bugreports/view.php?id=410


I see it was fixed long ago, but do you think it's related ?

Quote:

Have you asked Hans about this yet?


Nope, not at moment, we firstly need to create test case, to be 100% sure how to reproduce it, because without simple test cases no one will fix anything :)

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

Quote:

Maybe problem happens because our GLES2 implementation don't support DEPTH with 16 bits of precision.


From OGLES2 documentation: "OGLES2_CCT_DEPTH (uint32 ZBufferDepth) Desired z-buffer bit-depth (e.g. 16) or 0 if you don't need a z-buffer."

You can check what is passed in during GL context creation.

Quote:

I see it was fixed long ago, but do you think it's related


Not necessarily but symptom sounds similar, so maybe it can be at least ruled out. Sounds like texture format shouldn't matter but how about target texture scenario (FBO)?

I had my own issue with FBOs (flipped Y) but I haven't written a portable example to check it on Linux.

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Quote:

I had my own issue with FBOs (flipped Y) but I haven't written a portable example to check it on Linux.


Ha so flipped Y are not new problem then .. At least in your tests too. And we probably use FBO there too .. Maybe i need to try to disable FBO to see how it will be without

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
OMG ! Once i disabl framebuffer in that file on line 329 on false:

https://github.com/scummvm/scummvm/blo ... platform/sdl/sdl.cpp#L329


Then no problems ! All works fine, and no flip by Y all fine !

So , it very much looks like issue you had is the same we had in scummvm now.

It's time to made a test case for sure, because it definately bug somewhere in nova/ogles then.

And in case with Scummvm we can't just disable FBO for release because it mean no resizing of the window mode when we use Grim , monkey4 , etc (as those engines do not have internal resizing, so FBO is only way to have it).

In what condition you have this issue btw ? I mean, in some game or when code shaderjoy ?

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

Shaderjoy. There was some discussion earlier https://www.amigans.net/modules/newbb/ ... id=121683#forumpost121683

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill

Rigth.. But now ScummVM shows that issue is probabaly not your code, but there seems some problem indeed in ogles2/nova. We just need test case now. ScummVM's dev says he may have time tomorrow/etc and to try to create test case..

But what cleary is : it's surely FBO related only. Without FBO we have no such problem.

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
I start to fear that scummvm's dev who helped us may have no time again, maybe we can somehow create a test case without asking him for help ?

At least we know that issue is "textures with FBO" , so maybe we can try to at least create SDL2 based example which works over ogles2 and load up texture, enable FBO and show it up ? Maybe that will be enough ?

Or shaders should have take the place in any case there ?

As basis/skeleton for SDL2/Ogles2 code we can take those ones: http://os4depot.net/?function=showfil ... mple/erik_sdl2-ogles2.lha

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

I started to modify testgles2 yesterday but didn't have time yet to add FBO. I will try to continue today.

Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Home away from home
Home away from home


See User information
@Capehill
Good news ! We were able to create test case, and bug easy reproduced with FBO enabled !

Check it plz where you can (linux/win32/amigaos4/whatever):

//
// ppc-amigaos-gcc frag_bug.c -l frag_bug -lSDL2
//
//#include <EGL/egl.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <GLES2/gl2.h>
#include <stdbool.h>

typedef struct
{
   
unsigned int width;
   
unsigned int height;

   
// Handle to a program object
   
GLuint testProg;
   
GLuint testAltProg;
   
GLuint drawProg;
   
GLuint drawAltProg;

   
GLuint fbo;
   
GLuint fboTexture;

   
GLuint testTexture;

   
bool withFBO;
   
bool useAltDrawTex;
   
unsigned int drawMode;
UserData;


///
// Create a shader object, load the shader source, and
// compile the shader.
//
GLuint LoadShader GLenum type, const char *shaderSrc )
{
   
GLuint shader;
   
GLint compiled;

   
// Create the shader object
   
shader glCreateShader type );

   if ( 
shader == )
   {
    
fprintfstderr"glCreateShader error: %d\n"glGetError() );
       return 
0;
   }

   
// Load the shader source
   
glShaderSource shader1, &shaderSrcNULL );

   
// Compile the shader
   
glCompileShader shader );

   
// Check the compile status
   
glGetShaderiv shaderGL_COMPILE_STATUS, &compiled );

   if ( !
compiled )
   {
      
GLint infoLen 0;

      
glGetShaderiv shaderGL_INFO_LOG_LENGTH, &infoLen );

      if ( 
infoLen )
      {
         
charinfoLog malloc (sizeof(char) * infoLen );

         
glGetShaderInfoLog shaderinfoLenNULLinfoLog );
         
fprintfstderr"Error compiling shader:\n%s\n"infoLog );

         
free infoLog );
      }

      
glDeleteShader shader );
      return 
0;
   }

   return 
shader;

}

GLuint LinkProgram(const char *vertexSrc, const char *fragmentSrc) {
   
GLuint vertexShader;
   
GLuint fragmentShader;
   
GLuint programObject;
   
GLint linked;

   
// Load the vertex/fragment shaders
   
vertexShader LoadShader GL_VERTEX_SHADERvertexSrc );
   
fragmentShader LoadShader GL_FRAGMENT_SHADERfragmentSrc );

   
// Create the program object
   
programObject glCreateProgram ( );

   if ( 
programObject == )
      return 
0;

   
glAttachShader programObjectvertexShader );
   
glAttachShader programObjectfragmentShader );

   
// Link the program
   
glLinkProgram programObject );

   
// Check the link status
   
glGetProgramiv programObjectGL_LINK_STATUS, &linked );

   if ( !
linked )
   {
      
GLint infoLen 0;

      
glGetProgramiv programObjectGL_INFO_LOG_LENGTH, &infoLen );

      if ( 
infoLen )
      {
         
charinfoLog malloc (sizeof(char) * infoLen );

         
glGetProgramInfoLog programObjectinfoLenNULLinfoLog );
         
fprintf stderr"Error linking program:\n%s\n"infoLog );

         
free infoLog );
      }

      
glDeleteProgram programObject );
      return 
0;
   }

   return 
programObject;
}

int CreateFBO UserData *userData )
{
   
// Create the FBO
   
glGenFramebuffers(1, &userData->fbo);
   if (
userData->fbo == 0) {
      
fprintf(stderr"Failed to create framebuffer");
      return 
GL_FALSE;
   }

   
// Create the texture for the FBO
   
glGenTextures(1, &userData->fboTexture);
   if (
userData->fboTexture == 0) {
      
fprintf(stderr"Failed to create framebuffer texture");
      return 
GL_FALSE;
   }
   
glBindTexture(GL_TEXTURE_2DuserData->fboTexture);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_SGL_CLAMP_TO_EDGE);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_TGL_CLAMP_TO_EDGE);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR);
   
glTexImage2D(GL_TEXTURE_2D0GL_RGBAuserData->widthuserData->height0GL_RGBAGL_UNSIGNED_BYTE0);
   
glBindTexture(GL_TEXTURE_2D0);

   
// Bind fboTexture to the framebuffer
   
glBindFramebuffer(GL_FRAMEBUFFERuserData->fbo);
   
glFramebufferTexture2D(GL_FRAMEBUFFERGL_COLOR_ATTACHMENT0GL_TEXTURE_2DuserData->fboTexture0);
   
GLenum status glCheckFramebufferStatus(GL_FRAMEBUFFER);
   if (
status != GL_FRAMEBUFFER_COMPLETE) {
      
fprintf(stderr"FBO is not complete");
      return 
GL_FALSE;
   }
   
glBindFramebuffer(GL_FRAMEBUFFER0);

   return 
GL_TRUE;
}

int CreateTestTexture UserData *userData )
{
   
GLubyte *data malloc(userData->width userData->height sizeof(GLubyte));
   if (
data == NULL) {
      
fprintf(stderr"Failed to failed to allocate texture data");
      return 
GL_FALSE;
   }

   
char *data;
   for(
unsigned int i userData->height 20i--) {
       
memset(p0userData->width sizeof(GLubyte));
       
+= userData->width;
   }
   for(
unsigned int i userData->height userData->height 20i--) {
       
memset(p0xffuserData->width sizeof(GLubyte));
       
+= userData->width;
   }

   
// Create the texture
   
glGenTextures(1, &userData->testTexture);
   if (
userData->testTexture == 0) {
      
fprintf(stderr"Failed to create test texture");
      return 
GL_FALSE;
   }
   
glBindTexture(GL_TEXTURE_2DuserData->testTexture);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_SGL_CLAMP_TO_EDGE);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_WRAP_TGL_CLAMP_TO_EDGE);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR);
   
glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR);
   
glTexImage2D(GL_TEXTURE_2D0GL_LUMINANCEuserData->widthuserData->height0,  GL_LUMINANCEGL_UNSIGNED_BYTEdata);
   
glBindTexture(GL_TEXTURE_2D0);

   
free(data);

   return 
GL_TRUE;
}

///
// Initialize the shader and program object
//
int Init UserData *userData )
{
   
GLbyte vShaderStr[] =
      
"#version 100\n"
      "attribute vec4 aPosition;\n"
      "attribute vec3 aColor;\n"
      "varying vec4   vColor;\n"
      "void main() {\n"
      "   gl_Position = aPosition;\n"
      "   vColor = vec4(aColor, 1.0);\n"
      "}\n"
;

   
GLbyte fShaderStr[] =
      
"#version 100\n"
      "precision mediump float;\n"
      "varying vec4 vColor;\n"
      "void main() {\n"
      "  gl_FragColor = vColor;\n"
      "}\n"
;

   
GLbyte vShaderAltStr[] =
      
"#version 100\n"
      "attribute vec4 aPosition;\n"
      "attribute vec3 aColor;\n"
      "varying vec4   vColor;\n"
      "void main() {\n"
      "   gl_Position = aPosition;\n"
      "   vColor = vec4(aColor, 1.0);\n"
      "}\n"
;

   
GLbyte fShaderAltStr[] =
      
"#version 100\n"
      "precision mediump float;\n"
      "varying vec4 vColor;\n"
      "uniform sampler2D tex;\n"
      "uniform vec2 screenSize;\n"
      "void main() {\n"
      "  vec2 pos = (gl_FragCoord.xy-0.5)/screenSize;\n"
      "  pos.y = 1.0 - pos.y;\n"
      "  if (texture2D(tex, pos).r < gl_FragCoord.z) {\n"
      "    discard;\n"
      "  }\n"
      "  gl_FragColor = vColor;\n"
      "}\n"
;

   
GLbyte vDrawTexStr[] =
      
"#version 100\n"
      "attribute vec2 aPosition;\n"
      "attribute vec2 aTexcoord;\n"
      "varying vec2 vTexcoord;\n"
      "void main() {\n"
         "gl_Position = vec4(aPosition, 0.0, 1.0);\n"
         "vTexcoord = aTexcoord;\n"
      "}\n"
;

   
GLbyte fDrawTexStr[] =
      
"#version 100\n"
      "precision mediump float;\n"
      "varying vec2 vTexcoord;\n"
      "uniform sampler2D tex;\n"
      "void main() {\n"
      "    gl_FragColor = texture2D(tex, vTexcoord);\n"
      "}\n"
;

   
GLbyte vDrawTexAltStr[] =
      
"#version 100\n"
      "attribute vec2 aPosition;\n"
      "varying vec2 vTexcoord;\n"
      "void main() {\n"
      "   gl_Position = vec4(aPosition, 0.0, 1.0);\n"
      "}\n"
;

   
GLbyte fDrawTexAltStr[] =
      
"#version 100\n"
      "precision mediump float;\n"
      "uniform sampler2D tex;\n"
      "uniform int flipY;\n"
      "uniform vec2 screenSize;\n"
      "void main() {\n"
      "    vec2 pos = (gl_FragCoord.xy-0.5)/screenSize;\n"
      "    if (flipY == 0) {\n"
      "       pos.y = 1.0 - pos.y;\n"
      "    }\n"
      "    gl_FragColor = texture2D(tex, pos);\n"
      "}\n"
;

   
// Store the test program object
   
userData->testProg LinkProgram(vShaderStrfShaderStr);
   if (
userData->testProg == 0) {
      return 
GL_FALSE;
   }

   
// Store the alternate test program object
   
userData->testAltProg LinkProgram(vShaderAltStrfShaderAltStr);
   if (
userData->testAltProg == 0) {
      return 
GL_FALSE;
   }

   
// Store the drawing program object
   
userData->drawProg LinkProgram(vDrawTexStrfDrawTexStr);
   if (
userData->drawProg == 0) {
      return 
GL_FALSE;
   }

   
// Store the alternate drawing program object
   
userData->drawAltProg LinkProgram(vDrawTexAltStrfDrawTexAltStr);
   if (
userData->drawAltProg == 0) {
      return 
GL_FALSE;
   }

   if (
CreateFBOuserData ) == GL_FALSE ) {
       return 
GL_FALSE;
   }

   if (
CreateTestTextureuserData ) == GL_FALSE ) {
       return 
GL_FALSE;
   }

   
glClearColor 0.0f0.0f0.0f0.0f );
   return 
GL_TRUE;
}

///
// Draw a triangle using the shader pair created in Init()
//
void DrawTest UserData *userData )
{
   
GLfloat vVertices[] = {
        
0.5f, -0.5f0.5f,
       -
0.5f, -0.5f0.5f,
        
0.5f, -0.0f0.5f,
       -
0.5f, -0.0f0.5f,
       -
0.5f, -0.0f0.5f,
        
0.0f,  0.5f0.5f,
        
0.5f, -0.0f0.5f,
                            };
   
GLfloat vColors[] = {
       
0.f1.f,  0.f,
       
0.f1.f,  0.f,
       
0.f1.f,  0.f,
       
0.f1.f,  0.f,
       
1.f0.f,  0.f,
       
1.f0.f,  0.f,
       
1.f0.f,  0.f,
   };

   
// Use the program object
   
glUseProgram userData->testProg );

   
// Load the vertex data
   
glVertexAttribPointer glGetAttribLocation(userData->testProg"aPosition"), 3GL_FLOATGL_FALSE0vVertices );
   
glVertexAttribPointer glGetAttribLocation(userData->testProg"aColor"), 3GL_FLOATGL_FALSE0vColors );
   
glEnableVertexAttribArray glGetAttribLocation(userData->testProg"aPosition") );
   
glEnableVertexAttribArray glGetAttribLocation(userData->testProg"aColor") );

   
glDrawArrays GL_TRIANGLE_STRIP0);
}

void DrawTestAlt UserData *userData )
{
   
GLfloat vVertices[] = {
        
0.5f, -0.5f0.5f,
       -
0.5f, -0.5f0.5f,
        
0.5f, -0.0f0.5f,
       -
0.5f, -0.0f0.5f,
       -
0.5f, -0.0f0.5f,
        
0.0f,  0.5f0.5f,
        
0.5f, -0.0f0.5f,
                            };
   
GLfloat vColors[] = {
       
0.f1.f,  0.f,
       
0.f1.f,  0.f,
       
0.f1.f,  0.f,
       
0.f1.f,  0.f,
       
1.f0.f,  0.f,
       
1.f0.f,  0.f,
       
1.f0.f,  0.f,
   };

   
// Use the program object
   
glUseProgram userData->testAltProg );

   
// Setup the texture as uniform
   
glActiveTexture(GL_TEXTURE0);
   
glBindTexture(GL_TEXTURE_2DuserData->testTexture);
   
glUniform1i(glGetUniformLocation(userData->testAltProg"tex"), 0);
   
glUniform2f(glGetUniformLocation(userData->testAltProg"screenSize"), userData->widthuserData->height);

   
// Load the vertex data
   
glVertexAttribPointer glGetAttribLocation(userData->testAltProg"aPosition"), 3GL_FLOATGL_FALSE0vVertices );
   
glVertexAttribPointer glGetAttribLocation(userData->testAltProg"aColor"), 3GL_FLOATGL_FALSE0vColors );
   
glEnableVertexAttribArray glGetAttribLocation(userData->testAltProg"aPosition") );
   
glEnableVertexAttribArray glGetAttribLocation(userData->testAltProg"aColor") );

   
glDrawArrays GL_TRIANGLE_STRIP0);
}

void DrawTexture UserData *userDataGLuint textureIDbool fromFBO ) {
   
GLfloat aPositions[] = {
     -
1.0f, -1.0f,  // bottom left
     
-1.0f,  1.0f,  // top left
      
1.0f, -1.0f,  // bottom right
      
1.0f,  1.0f,  // top right
   
};
   
// Origin bottom-left
   
GLfloat aTexcoordsOBL[] = {
      
0.0f0.0f,   // bottom left
      
0.0f1.0f,   // top left
      
1.0f0.0f,   // bottom right
      
1.0f1.0f,   // top right
   
};
   
// Origin top-left
   
GLfloat aTexcoordsOTL[] = {
      
0.0f1.0f,   // bottom left
      
0.0f0.0f,   // top left
      
1.0f1.0f,   // bottom right
      
1.0f0.0f,   // top right
   
};

   
GLfloat *aTexcoords fromFBO aTexcoordsOBL aTexcoordsOTL;

   
// Use the program object
   
glUseProgram userData->drawProg );

   
// Setup the texture as uniform
   
glActiveTexture(GL_TEXTURE0);
   
glBindTexture(GL_TEXTURE_2DtextureID);
   
glUniform1i(glGetUniformLocation(userData->drawProg"tex"), 0);

   
glVertexAttribPointer(glGetAttribLocation(userData->drawProg"aPosition"), 2GL_FLOAT00aPositions);
   
glVertexAttribPointer(glGetAttribLocation(userData->drawProg"aTexcoord"), 2GL_FLOAT00aTexcoords);
   
glEnableVertexAttribArray(glGetAttribLocation(userData->drawProg"aPosition"));
   
glEnableVertexAttribArray(glGetAttribLocation(userData->drawProg"aTexcoord"));

   
glDrawArrays(GL_TRIANGLE_STRIP04);
}

void DrawTextureAlt UserData *userDataGLuint textureIDbool fromFBO ) {
   
GLfloat aPositions[] = {
     -
1.0f, -1.0f,  // bottom left
     
-1.0f,  1.0f,  // top left
      
1.0f, -1.0f,  // bottom right
      
1.0f,  1.0f,  // top right
   
};

   
// Use the program object
   
glUseProgram userData->drawAltProg );

   
// Setup the texture as uniform
   
glActiveTexture(GL_TEXTURE0);
   
glBindTexture(GL_TEXTURE_2DtextureID);
   
glUniform1i(glGetUniformLocation(userData->drawAltProg"tex"), 0);
   
glUniform1i(glGetUniformLocation(userData->drawAltProg"flipY"), fromFBO);
   
glUniform2f(glGetUniformLocation(userData->drawAltProg"screenSize"), userData->widthuserData->height);

   
glVertexAttribPointer(glGetAttribLocation(userData->drawAltProg"aPosition"), 2GL_FLOAT00aPositions);
   
glEnableVertexAttribArray(glGetAttribLocation(userData->drawAltProg"aPosition"));

   
glDrawArrays(GL_TRIANGLE_STRIP04);
}

void Draw(UserData *userData) {
   
// Set the viewport
   
glViewport 00userData->widthuserData->height );

   
// Clear the color buffer
   
glClear GL_COLOR_BUFFER_BIT );

    if (
userData->withFBO) {
       
// Enable FBO
       
glBindFramebuffer(GL_FRAMEBUFFERuserData->fbo);

       
// Clear the color buffer
       
glClear GL_COLOR_BUFFER_BIT );
    }

    switch (
userData->drawMode) {
        case 
0:
            
DrawTest(userData);
            break;
        case 
1:
            
DrawTestAlt(userData);
            break;
        case 
2:
            (
userData->useAltDrawTex DrawTextureAlt DrawTexture)(userDatauserData->testTexturefalse);
            break;
    }
   
    if (
userData->withFBO) {
       
// Disable FBO
       
glBindFramebuffer(GL_FRAMEBUFFER0);

       
// Draw the FBO
       
DrawTexture(userDatauserData->fboTexturetrue);
    }
}

static const 
char *MODES[] = {
    
"Red triangle + green square",
    
"Discarded red triangle + Green square",
    
"Test texture (black above, white below)"
};

void changeState( const SDL_Event *eUserData *userData ) {
    switch (
e->key.keysym.sym) {
        case 
SDLK_d:
            
userData->useAltDrawTex = !userData->useAltDrawTex;
            break;
        case 
SDLK_f:
            
userData->withFBO = !userData->withFBO;
            break;
        case 
SDLK_g:
            
userData->drawMode++;
            if (
userData->drawMode 2) {
                
userData->drawMode 0;
            }
            break;
    }
    
fprintf(stderr"Current mode: <FragCoord Draw Texture>=%s%s <With FBO>=%s <Current mode>=%d - %s\n",
        
userData->useAltDrawTex "yes" "no",
        
userData->drawMode == "" " (ignored)",
        
userData->withFBO "yes" "no",
        
userData->drawMode,
        
MODES[userData->drawMode]);
}

int main()
{

    
UserData  userData;
    
memset(&userData0sizeof(userData));

    
userData.width 640;
    
userData.height 480;

    
// For EGL on X11 to use with RenderDoc
#ifdef SDL_VIDEO_DRIVER_X11
    
SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL"1");
    
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER"1");
#endif

    
SDL_InitSubSystem(SDL_INIT_VIDEO);
    
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
    
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASKSDL_GL_CONTEXT_PROFILE_ES);
    
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION2);
    
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION0);

    
SDL_Window *window SDL_CreateWindow("SDL GLES2", -1, -1userData.widthuserData.heightSDL_WINDOW_OPENGL);
    if (!
window) {
        
fprintf(stderr"SDL_CreateWindow: error=%s\n"SDL_GetError() );
        return 
1;
    }
    
SDL_GLContext context SDL_GL_CreateContext(window);
    if (!
context) {
        
fprintf(stderr"SDL_GL_CreateContext: error=%s\n"SDL_GetError() );
        return 
1;
    }
    if (
SDL_GL_MakeCurrent(windowcontext)) {
        
fprintf(stderr"SDL_GL_MakeCurrent: error=%s\n"SDL_GetError() );
        return 
1;
    }

    
fprintf(stderr"%s\n"glGetString(GL_RENDERER) );

    if ( !
Init ( &userData ) ) {
       
fprintf(stderr"Failed to init\n");
       return 
0;
    }

    
bool quit false;
    
SDL_Event e;
    
memset(&e0sizeof(e));

    
// Print default state
    
changeState(&e, &userData);

    while (!
quit) {
        while (
SDL_PollEvent(&e) != 0) {
            switch (
e.type) {
                case 
SDL_QUITquit true; break;
                case 
SDL_KEYUPchangeState( &e, &userData ); break;
            }
        }

        
Draw( &userData );

        
SDL_GL_SwapWindow(window);
    }

    
SDL_GL_DeleteContext(context);
    
SDL_DestroyWindow(window);
    
SDL_Quit();
}




- change mode with key <g>

- enable/disable FBO with key <f>

- when displaying test texture (black and white), change the display method with key <d>

As can be seen we can reproduce issue and we fail when

1. FBO is enabled, in mode 1 (red triangle will be displayed instead of green square)

2. FBO is enabled, and in mode 2 with alternate display (using gl_FragCoord, black will be below and white above).


To sum up:

When enabling FBO, gl_FragCoord begins to act up reversed with 0.0 at top and 1.0 at bottom instead of the usual 0.0 at bottom.

Now, what issue is ? Ogles2 or Nova ? At least reading your with Daniel discussion back in time about, it seems that it can be Ogles2 issue ?

At least we can create it for ogles2 for a start and if things turns out to Nova we can change the ticket ..

---------------

Anyway, while it's now clear that isues in our drivers and should be fixed there, i want to find out what issues are with the last problematic shaders in scummvm : shaders for "Escape From Monkey Island".

Issue we have there, that all "actors" renders black, see:

https://youtu.be/24DjuPTVIgw

(start from 0:20).


There are just 5 pairs of shaders for, see:

https://github.com/scummvm/scummvm/tree/master/engines/grim/shaders

Shaders with name "emi_*" at begining are for that game.


So, background, dimplane and sprite ones are out of question (because we can see on video that background, planes and sprites on image renders correctly).

Issue is 2 pairs: emi_actor and emi_actorlights. As it issues with colors, it mean fragment shaders then. So we end up with issue (or bug on our side) being there:

https://github.com/scummvm/scummvm/blo ... haders/emi_actor.fragment

https://github.com/scummvm/scummvm/blo ... /emi_actorlights.fragment

Shaders are absolutly 100% identical, which is :

in vec2 Texcoord;
in vec4 Color;

uniform sampler2D tex;
uniform bool textured;
uniform float alphaRef;
uniform float meshAlpha;

OUTPUT

void main
()
{
    
outColor Color;
    if (
textured) {
        
vec4 texColor texture(texTexcoord);
        
outColor.rgba *= texColor.rgba;
        
outColor.*= meshAlpha;
        if (
outColor.alphaRef)
            
discard;
    }
}


Can you se anything wrong there ? It can be easy something unitialized or so ...

ps. if you watch video more, you can see on 0:29, that main hero got the color at some point. Mean that things can works, just something wrong somewhere ..


Edited by kas1e on 2022/3/27 21:02:24
Edited by kas1e on 2022/3/27 21:17:15
Edited by kas1e on 2022/3/27 21:20:08
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: 3D: another round of help need it with gl4s/ogles2/nova and shaders.
Just can't stay away
Just can't stay away


See User information
@kas1e

Quote:

Now, what issue is ? Ogles2 or Nova ? At least reading your with Daniel discussion back in time about, it seems that it can be Ogles2 issue ?

At least we can create it for ogles2 for a start and if things turns out to Nova we can change the ticket ..


My guess is that problem is in Nova, but we can only compare OpenGL test apps between operating systems. It would be good to hear Daniel's opinion first because he was suspecting application issue (wrong UV coords) earlier but now it seems issue is somewhere on the library side, thanks to your tests.

Other topics I haven't had time to check yet.

Go to top

  Register To Post
(1) 2 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project