ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
667 stars 151 forks source link

Add support for ARB Program (was Irrlicht Engine bring shader compiling errors) #267

Open kas1e opened 3 years ago

kas1e commented 3 years ago

Find out that while with the latest gl4es we didn't have anymore "ARGB" errors when it comes to Irrlicht, but all Irrlicht based code brings me on running that now:

LIBGL: Hardware vendor is A-EON Technology Ltd. Written by Daniel 'Daytona675x' MьЯener @ GoldenCode.eu
LIBGL: GLSL 300 es supported
LIBGL: GLSL 310 es supported and used
Using renderer: OpenGL 2.1
GL4ES wrapper: ptitSeb
OpenGL driver version is 1.2 or better.
GLSL version: 1.2
Vertex shader compilation failed at position 585:
Invalid token
Pixel shader compilation failed at position 580:
Invalid value (implicit param?)
Vertex shader compilation failed at position 605:
Invalid token
Pixel shader compilation failed at position 586:
Invalid value (implicit param?)
Loaded texture: cpsplash.png 

And then all continue to work as expected.

ptitSeb commented 3 years ago

Run with LIBGL_LOGSHADERERROR=1 et copy/paste the log please

kas1e commented 3 years ago

I may forget something, but should it just print stuff to console then?

In my case now, does not matter if I do setenv LIBGL_LOGSHADERERROR 1, or if I do setenv LIBGL_DBGSHADERCONV 8 nothing prints to the console. Should't i activate it maybe somehow, or , it just didn't work for now by some reassons ?

I tested setenv LIBGL_BATCH 300, and that one surely works. So whole setenv works, just not for those 2 shader-output errors.

ptitSeb commented 3 years ago

Are you sure this is an error from a Shader then?

kas1e commented 3 years ago

It doesn't sounds very much like usual shader error yes, but it still bring erros about shaders can't be compiled :) I need to check where those words placed are.

How can i check that LIBGL_DBGSHADERCONV surely works ? Set it to 15, then run app should 100% bring me something to the console, correct ?

ptitSeb commented 3 years ago

Yes, also LIBGL_DBGSHADERCONV=1 is the same as 15. You should see some shaders (be sure to purge any psa archive first or you may see nothing)

kas1e commented 3 years ago

You are right, it seems it come from Irrlicht itself, but then why only now and what is that .. Why not before .. Maybe because before we use some LIBGL_ARBPROGRAMM for or something if i remember right .. Will do more tests now.

kas1e commented 3 years ago

It probabaly come from source/Irrlicht/COpenGLShaderMaterialRenderer.cpp

kas1e commented 3 years ago

Nope, doing "setenv LIBGL_ARBPROGRAM 1" didn't help, still bring this error.

ptitSeb commented 3 years ago

It's LIBGL_NOARBPROGRAM=1 to disable old ARB programs

kas1e commented 3 years ago

Yeah, that it! Damn, I was sure it was already in gl4es as if I remember right you work on something of that sort? Or it was a plan ?:)

kas1e commented 3 years ago

I change the title of the topic to be more understandable, so once a time (if) will come, it will be not forgotten :) But currently ```setenv LIBGL__NOARBPROGRAM 1" did the trick.

ptitSeb commented 3 years ago

Ok.

I'll look at this later. Seems like the old ARB programs handling in gl4es still need somes fixes...

kas1e commented 3 years ago

By the way, checked file buffers.c and there is such a block:

//ARB wrapper
#ifndef AMIGAOS4
void glGenBuffersARB(GLsizei n, GLuint * buffers) AliasExport("gl4es_glGenBuffers");
void glBindBufferARB(GLenum target, GLuint buffer) AliasExport("gl4es_glBindBuffer");
void glBufferDataARB(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) AliasExport("gl4es_glBufferData");
void glBufferSubDataARB(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) AliasExport("gl4es_glBufferSubData");
void glDeleteBuffersARB(GLsizei n, const GLuint * buffers) AliasExport("gl4es_glDeleteBuffers");
GLboolean glIsBufferARB(GLuint buffer) AliasExport("gl4es_glIsBuffer");
void glGetBufferParameterivARB(GLenum target, GLenum value, GLint * data) AliasExport("gl4es_glGetBufferParameteriv");
void *glMapBufferARB(GLenum target, GLenum access) AliasExport("gl4es_glMapBuffer");
GLboolean glUnmapBufferARB(GLenum target) AliasExport("gl4es_glUnmapBuffer");
void glGetBufferSubDataARB(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid * data) AliasExport("gl4es_glGetBufferSubData");
void glGetBufferPointervARB(GLenum target, GLenum pname, GLvoid ** params) AliasExport("gl4es_glGetBufferPointerv");
#endif

See, we comment it out for amigaos4 (probably to avoid throwing lots of errors). But now if you add them already, maybe that was the reason it didn't work with the latest gl4es? Will try to uncomment it to check what happens.

kas1e commented 3 years ago

Ok tracked this one down. It turned out that not things as bad: for first, ARB Programs in Irrlicth surely works by default, without any environments like setenv LIBGL_ARBPROGARM 1 set as it was before. Just since this commit https://github.com/ptitSeb/gl4es/commit/f45cb9caadec44902a784566b91adbd2c5f18294 from lscle with gl4es.h: Fix if condition typo (just replacing = on == in error handling), we start to have on running of Irrlicht examples this:

Vertex shader compilation failed at position 585:
Invalid token
Pixel shader compilation failed at position 580:
Invalid value (implicit param?)
Vertex shader compilation failed at position 605:
Invalid token
Pixel shader compilation failed at position 586:
Invalid value (implicit param?)

The question is: Is in this commit things indeed were fixed, and just we have always those errors, just since that commit they showups, and before were just hidden? If errors always were there, then strange why, because shaders loaded in example surely works.

kas1e commented 3 years ago

I tried to run 10.shaders Irrlicht example and answer "n" for using shaders, and then output looks like this:

Vertex shader compilation failed at position 585:
Invalid token
Pixel shader compilation failed at position 580:
Invalid value (implicit param?)
Vertex shader compilation failed at position 605:
Invalid token
Pixel shader compilation failed at position 586:
Invalid value (implicit param?)
Pixel shader compilation failed at position 457:
Invalid texture instruction
Pixel shader compilation failed at position 457:
Invalid texture instruction 

See it start to bring even more errors. While I clearly point out not to use shaders. And all those error messages come from gl4es's arbparser.c. But to note, they only arise when in https://github.com/ptitSeb/gl4es/commit/f45cb9caadec44902a784566b91adbd2c5f18294 we change = on ==. Maybe there just some logic error in arbparses.c now, and FAIL shouldn't be successful? (maybe it takes for granted previous broken = in gl4es.h ?)

kas1e commented 3 years ago

Sadly in the versions of 2019 I can't find anything of if(glstate->shim_error = GL_NO_ERROR) , so to check if replacing = on == will also bring the same errors, or those errors something new. Maybe there still some wrong error check, because why arbparser.c should bring those errors if they all work?

ptitSeb commented 3 years ago

Don't bother for this one. I need to analyse on my side what is happenng and how to improve log tools around ARB program too.

kas1e commented 3 years ago

By the way, I find out that setenv LIBGL_NPOT 2, fixed for me 2D images loading done on Irrlicht so they look "clean" and good, while with default they look bad. I read that LIBGL_NPOT 2 is Expose GL_ARB_texture_non_power_of_two extension, did it mean that it works mostly for Irrlicht now (as it uses ARB programs, etc) and that it didn't work for us by default on our OGLES2, because of we don't have such an extension then?

When I set LIBGL_NPOT 2, then on running I have that Expose GL_ARGB_Texture_non_power_on_two extension so it means it "faked" by gl4es then, and to make it works by default, we need in ogles2 add such an extension, right?

ptitSeb commented 3 years ago

To automatically have LIBGL_NPOT = 2, the GLES2 driver needs to expose either GL_ARB_texture_non_power_of_two or GL_OES_texture_npot, and I suppose AmigaOS2 driver have this ability, so maybe it's something that Daniel could add?

kas1e commented 3 years ago

When I run anything compiled with GL4ES, I have on running at top "Hardware Full NPOT detected and used", but still all NPOT textures in irrlicht looks bad until I set LIBGL_NPOT 2. So probably that not it, and one of those 2 extensions strings needs to be added...

ptitSeb commented 3 years ago

Oh, mmm, strange, I'll check if I haven't some mystake somewhere...

kas1e commented 3 years ago

I ask Daniel about it, he shows me what we have already in extensions :

case GL_EXTENSIONS: s=
                "GL_ARB_arrays_of_arrays GL_ARB_provoking_vertex GL_ARB_texture_mirror_clamp_to_edge GL_ARB_texture_non_power_of_two GL_ARB_texture_rectangle"
                " GL_EXT_blend_minmax GL_EXT_frag_depth GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_EXT_texture_lod_bias GL_EXT_texture_rectangle"
                " GL_OES_draw_elements_base_vertex GL_OES_element_index_uint GL_OES_get_program_binary GL_OES_mapbuffer GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_npot GL_OES_packed_depth_stencil"
                " GL_SGIS_texture_lod"
                " GL_AOS4_texture_format_RGB332 GL_AOS4_texture_format_RGB332REV GL_AOS4_texture_format_RGBA1555REV GL_AOS4_texture_format_RGBA8888 GL_AOS4_texture_format_RGBA8888REV"
                " GL_OES_vertex_type_10_10_10_2 GL_EXT_texture_type_2_10_10_10_REV"
                ; break;

See we have both GL_OES_texture_npot and GL_ARB_texture_non_power_of_two. But that what we have in output when I run any app compiled with gl4es by default:

2/0.Work:worlds> worlds 
LIBGL: Initialising gl4es
LIBGL: v1.1.5 built on Jan 28 2021 11:27:13
LIBGL: Using GLES 2.0 backend
LIBGL: Using Warp3DNova.library v1 revision 83
LIBGL: Using OGLES2.library v3 revision 1
LIBGL: OGLES2 Library and Interface open successfuly
LIBGL: Targeting OpenGL 2.1
LIBGL: Forcing NPOT support by disabling MIPMAP support for NPOT textures 
LIBGL: Not trying to batch small subsequent glDrawXXXX
LIBGL: try to use VBO
LIBGL: Force texture for Attachment color0 on FBO
LIBGL: Hack to trigger a SwapBuffers when a Full Framebuffer Blit on default FBO is done
LIBGL: Current folder is:/Work/worlds
LIBGL: Hardware test on current Context...
LIBGL: Hardware Full NPOT detected and used
LIBGL: Extension GL_EXT_blend_minmax  detected and used
LIBGL: FBO are in core, and so used
LIBGL: PointSprite are in core, and so used
LIBGL: CubeMap are in core, and so used
LIBGL: BlendColor is in core, and so used
LIBGL: Blend Substract is in core, and so used
LIBGL: Blend Function and Equation Separation is in core, and so used
LIBGL: Texture Mirrored Repeat is in core, and so used
LIBGL: Extension GL_OES_mapbuffer  detected
LIBGL: Extension GL_OES_element_index_uint  detected and used
LIBGL: Extension GL_OES_packed_depth_stencil  detected and used
LIBGL: Extension GL_EXT_texture_format_BGRA8888  detected and used
LIBGL: Extension GL_OES_texture_float  detected and used
LIBGL: Extension GL_AOS4_texture_format_RGB332 detected
LIBGL: Extension GL_AOS4_texture_format_RGB332REV detected
LIBGL: Extension GL_AOS4_texture_format_RGBA1555REV detected and used
LIBGL: Extension GL_AOS4_texture_format_RGBA8888 detected and used
LIBGL: Extension GL_AOS4_texture_format_RGBA8888REV detected and used
LIBGL: high precision float in fragment shader available and used
LIBGL: Extension GL_EXT_frag_depth  detected and used
LIBGL: Max vertex attrib: 16
LIBGL: Max texture size: 16384
LIBGL: Max Varying Vector: 32
LIBGL: Texture Units: 8/8 (hardware: 32), Max lights: 8, Max planes: 6
LIBGL: Extension GL_EXT_texture_filter_anisotropic  detected and used
LIBGL: Max Anisotropic filtering: 16
LIBGL: Max Color Attachments: 1 / Draw buffers: 1
LIBGL: Hardware vendor is A-EON Technology Ltd. Written by Daniel 'Daytona675x' MьЯener @ GoldenCode.eu
LIBGL: GLSL 300 es supported
LIBGL: GLSL 310 es supported and used
Using renderer: OpenGL 2.1
GL4ES wrapper: ptitSeb
OpenGL driver version is 1.2 or better.
GLSL version: 1.2

See, firstly it says LIBGL: Forcing NPOT support by disabling MIPMAP support for NPOT textures, then after a while Hardware Full NPOT detected and used, but then nothing about extensions like GL_OES_texture_npot and/or GL_ARB_texture_non_power_of_two, while they there, like gl4es just skip that check, or go wrong logical route, etc ...

kas1e commented 3 years ago

Interesting that once i do setenv LIBGL_NPOT 2, then output looks like this:

...
LIBGL: Targeting OpenGL 2.1
LIBGL: Expose GL_ARB_texture_non_power_of_two_extension
LIBGL: Forcing NPOT support by disabling MIPMAP support for NPOT textures
.....
LIBGL: Hardware Full NPOT detected and used
....

See it firstly do expose of GL_ARB_texture_non_power_of_two_extension and only then checking NPOT and stuff. It's like a logical flaw, and when we didn't have that environment set, things checked in the wrong order and that probably causing issue of not-detecting extensions which we had for NPOT.

ptitSeb commented 3 years ago

I guess this is an AmigaOS4 specific one than! The Hardware test is supposed to come before the handling of LIBGL_NPOT env. var., but I suppose on the Amiga it's not the case. All this is in init.c source, and there are many #ifdef and ifs.

Also, What I have just noticed is in glx/hardext.c line 107, the hardext.npot=1 is probably not right for AmigaOS4, and maybe I should set it to 3 with an #ifdef here, as the OGLES2 driver has always supported NPOT texture I think.

kas1e commented 3 years ago

Yeah, our ogles2 driver always supports NPOT. I may try now to set it to 3, to see what will happens.

kas1e commented 3 years ago

So set it to 3, and output now changes, and instead of Forcing NPOT support by disabling MIPMAP support for NPOT textures, i have now LIBGL: NPOT texture handled in hardware and then after a while same ```LIBGL: Hardware Full NPOT detected and used", but still nothing about our extensions about NPOT.

But I checked to compile a game with that change, and now "NPOT" textures look good. So probably "3" for AmigaOS is right, but still, we also should see information about extensions as well, right?

kas1e commented 3 years ago

Ah i see, you have code if(strstr(Exts, "GL_ARB_texture_non_power_of_two ") || strstr(Exts, "GL_OES_texture_npot ")) hardext.npot = 3;, so it should firstly check on extensions, and if found it will set it to 3. But in our case seems that check didn't happens, so we have "1" left. And we have 2 ways to solve issue : or set it to 3 right now (which a bit hacky) or find out why extensions didn't check when should.

ptitSeb commented 3 years ago

I have pushed the change, it should be fine now. The "Exposing NPOT" bla bla message wont appear, it only does when using LIBGL_NPOT to force things. Maybe I'll change that later to always print the message.

kas1e commented 2 years ago

@ptitSeb Is the ARB function works for now in GL4ES? Why i ask, it's because i want to build simple test case which will load and compile original OpenGL shaders over GL4ES, so i can test what shaders look like after shaderconv, without needing to run bloated stuff. And as i understand, the only way to compile original OpenGL shaders over gl4es , is to use ARB functions, right? I mean without involving any other code, just simple "load/compile", to see the shader after shaderconv.

So far i created such test case:

#include <SDL2/SDL.h>
#include <GL/gl.h>
#include <GL/glext.h>

#include <stdio.h>
#include <stdbool.h>

static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
static PFNGLUNIFORM1IARBPROC glUniform1iARB;
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;

SDL_Window    *glWindow = NULL;
SDL_GLContext glContext = NULL;

bool InitSDL(int width, int height, int bpp, bool fscreen)
{
        printf("\n[Initializing Video Settings]\n");

        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0)
        {
            printf("\n[Failed to initialize Video Settings]\n");
            return false;
        }

        int flags = SDL_WINDOW_OPENGL | (fscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0);

        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
        SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 0);

        glWindow = SDL_CreateWindow("Prototype", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
        if(!glWindow)
        {
            SDL_Quit();
            return false;
        }
        glContext = SDL_GL_CreateContext(glWindow);
        if(!glContext)
        {
            SDL_Quit();
            return false;
        }
        return true;
} 

bool QuitSDL()
{
        if(glContext)
            SDL_GL_DeleteContext(glContext);
        glContext = NULL;
        if(glWindow)
            SDL_DestroyWindow(glWindow);
        glWindow = NULL;
        SDL_Quit();
        return true;
} 

int main()

{
const char * my_fragment_shader_source =

"uniform sampler2D texture;\n"
"\n"
"void main()\n"
"\n"
"{\n"
"\n"
"  gl_FragColor = texture2D(texture, gl_TexCoord[0].st);\n"
"\n"
"}\n"
;

GLenum my_program;
GLenum my_fragment_shader;

InitSDL(640,480,32,0);

// Create Shader And Program Objects
my_program = glCreateProgramObjectARB();
my_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

// Load Shader Sources
glShaderSourceARB(my_fragment_shader, 1, &my_fragment_shader_source, NULL);

// Compile The Shaders
glCompileShaderARB(my_fragment_shader);

// Attach The Shader Objects To The Program Object
glAttachObjectARB(my_program, my_fragment_shader);

// Link The Program Object
glLinkProgramARB(my_program);

// Use The Program Object Instead Of Fixed Function OpenGL
glUseProgramObjectARB(my_program);

glDeleteObjectARB(my_fragment_shader);

QuitSDL();

}

All compiles fine, no errors, but example just freezes once we meet with first ARB call. Probably i doing something wrong and stupid, but how else i can test OpenGL shader via GL4ES more easily ? (but question about ARB support still remain, as will be nice to be able to finish that test case too)

ptitSeb commented 2 years ago

Yes, ARB function are implemented (if you mean the old-style Assembly like shader language). It's not 100% tested, so you can expact some bugs here and there.... Also, on your sample, your shader only contains a fragment shader and no vertex shader. This is "half supported" on gl4es for now. It should be supported, but it's always works fine.

kas1e commented 2 years ago

@ptitSeb

Yes, ARB function are implemented (if you mean the old-style Assembly like shader language)

Yeah, i mean those ones like glCompileShaderARB, etc. As i understand it was the only way on OpenGL2.x to use shaders, right?

But my example even without vertex shader should at least not freezes on the first ARB function? I.e. after my_program = glCreateProgramObjectARB(); everything stops. Maybe there are some amigaos4 ifdefs left in gl4es about ARB ? will check now

ptitSeb commented 2 years ago

Ah yes, calling glCreateProgramObjectARB should just work.

kas1e commented 2 years ago

Oh, check this out what i found in buffer.c : we have there #ifndef __amigaos4__ for all ARB functions. Can that be a cause? Will check now.

kas1e commented 2 years ago

Ok, for first i made it works , i had to remove from my source code that part:

static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
static PFNGLUNIFORM1IARBPROC glUniform1iARB;
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;

And then all works fine.

Through, why do we have that "ifdef" there in buffers.c ? I tried with and without, and it will works if i remove those "statics", and didn't work if i keep them there.

Btw, the reasson why i put those statics here, is that for first it offten used everywhere, i was sure it will be ok, and for second, i have on compiling without them that:

est4.c:92:14: warning: implicit declaration of function ‘glCreateProgramObjectARB’ [-Wimplicit-function-declaration]
my_program = glCreateProgramObjectARB();
             ^~~~~~~~~~~~~~~~~~~~~~~~
est4.c:93:22: warning: implicit declaration of function ‘glCreateShaderObjectARB’ [-Wimplicit-function-declaration]
my_fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
                     ^~~~~~~~~~~~~~~~~~~~~~~
est4.c:96:1: warning: implicit declaration of function ‘glShaderSourceARB’; did you mean ‘glShadeModel’? [-Wimplicit-function-declaration]
glShaderSourceARB(my_fragment_shader, 1, &my_fragment_shader_source, NULL);
^~~~~~~~~~~~~~~~~
glShadeModel
est4.c:100:1: warning: implicit declaration of function ‘glCompileShaderARB’ [-Wimplicit-function-declaration]
glCompileShaderARB(my_fragment_shader);
^~~~~~~~~~~~~~~~~~
est4.c:103:1: warning: implicit declaration of function ‘glAttachObjectARB’ [-Wimplicit-function-declaration]
glAttachObjectARB(my_program, my_fragment_shader);
^~~~~~~~~~~~~~~~~
est4.c:106:1: warning: implicit declaration of function ‘glLinkProgramARB’; did you mean ‘glHistogram’? [-Wimplicit-function-declaration]
glLinkProgramARB(my_program);
^~~~~~~~~~~~~~~~
glHistogram
est4.c:109:1: warning: implicit declaration of function ‘glUseProgramObjectARB’ [-Wimplicit-function-declaration]
glUseProgramObjectARB(my_program);
^~~~~~~~~~~~~~~~~~~~~
est4.c:112:1: warning: implicit declaration of function ‘glDeleteObjectARB’; did you mean ‘glDeleteTextures’? [-Wimplicit-function-declaration]
glDeleteObjectARB(my_fragment_shader);
^~~~~~~~~~~~~~~~~
ptitSeb commented 2 years ago

OOOOh, ok, I see now.

So, yes, all those ARB function are not supposed to be used directly, but using function pointer (like with your static). But you need to initialize them! use something like glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)aglGetProcAddress("glAttachObjectARB"); for each function, and it will work, and without warning

kas1e commented 2 years ago

Tested with this line, and have lot of warnings:

test4.c:18:1: warning: data definition has no type or storage class
 glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)aglGetProcAddress("glAttachObjectARB");
 ^~~~~~~~~~~~~~~~~
test4.c:18:1: warning: type defaults to ‘int’ in declaration of ‘glAttachObjectARB’ [-Wimplicit-int]
test4.c:18:21: warning: initialization of ‘int’ from ‘void (*)(GLhandleARB,  GLhandleARB)’ {aka ‘void (*)(unsigned int,  unsigned int)’} makes integer from pointer without a cast [-Wint-conversion]
 glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)aglGetProcAddress("glAttachObjectARB");

Will dig in , seems something need to be casted, etc..

Btw, what to do with that "ifndef" for ARB functions in buffer.c in gl4es ? Keep it ?

ptitSeb commented 2 years ago

You have to keep the lines static PFNGLATTACHOBJECTARBPROC glAttachObjectARB; for the other line to work.

Keep the ifndef for now.

ptitSeb commented 2 years ago

Something like this:

#include <SDL2/SDL.h>
#include <GL/gl.h>
#include <GL/glext.h>

#include <stdio.h>
#include <stdbool.h>

static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
static PFNGLUNIFORM1IARBPROC glUniform1iARB;
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;

SDL_Window    *glWindow = NULL;
SDL_GLContext glContext = NULL;

bool InitSDL(int width, int height, int bpp, bool fscreen)
{
        printf("\n[Initializing Video Settings]\n");

        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0)
        {
            printf("\n[Failed to initialize Video Settings]\n");
            return false;
        }

        int flags = SDL_WINDOW_OPENGL | (fscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0);

        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
        SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 0);

        glWindow = SDL_CreateWindow("Prototype", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
        if(!glWindow)
        {
            SDL_Quit();
            return false;
        }
        glContext = SDL_GL_CreateContext(glWindow);
        if(!glContext)
        {
            SDL_Quit();
            return false;
        }
               glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)aglGetProcAddress("glAttachObjectARB");
              // and all the other...
        return true;
kas1e commented 2 years ago

Ah, got it now, thanks.

Btw, to avoid creating another topic for simple question, want to ask one thing about original ogl supported shaders. For example, i have that original:

layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 tex;

out vec2 TexCoord;

void main()
{
gl_Position = vec4(pos,1.0);
TexCoord = tex;
}

And gl4es rebuild it like:

#version 100
precission highp float;
precission highp int;
layout (location = 0) in vec3 pos;
layout (location = 1) in vec2 tex;

out vec2 TexCoord;

void main()
{
gl_Position = vec4(pos,1.0);
TexCoord = tex;
}

So just add version 100 + precisions. And that shader can't be compiled by glslangvalidator. If i understand that correctly, all that layout (location = 0) in vec xxxx stuff is from GLSL of bigger versions, so there should be 300 or 330 for version. I at least checked with version 300 es, and all compiles fine then.

The question is : how to deal with it?:)

kas1e commented 2 years ago

Ah i see now, gl4es in any case put version 100, so even if original shader with 310 es work for us, it still replaced on version 100. Isn't gl4es has some option for disabling conversion of original shaders, and keep only internal gl4es ones ?

ptitSeb commented 2 years ago

Not for now. Adding the handling of GL 3.x is something I want to do on gl4es, but I haven't started worked on this yet.

kas1e commented 2 years ago

And no luck to disable gl4es conversion of original shaders? (i mean, some environment so just shaders will go "as it") ?

ptitSeb commented 2 years ago

No there isn't anything like this, because gl4es track many things from shader, skipping the analysis (and so transformation) may lead to more issues for now.

kas1e commented 2 years ago

@ptitSeb I thinking about "portability" moments of those ARB shaders in amigaos4 programs, do you think is there any kind of way that may help to work ARB shaders as it from the point of the application code, i.e. without calling glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)aglGetProcAddress("glAttachObjectARB"); etc kind of strings?

Maybe that can be put somewhere inside of includes, or maybe, to gl4es itself somewhere via amigaos4 ifdefs, or, maybe to SDL initialization code part?

ptitSeb commented 2 years ago

But this is the universal way to get opengl extension! You have a per/platform function: glXGetProcAddress(...) on linux, wglGetProcAddress(...) on Windows, and you do the exact same call when you want extension. If you use SDL2, you use SDL_GL_GetProcAddress(...) on all platform. This is the way to be portable.

kas1e commented 2 years ago

@ptitSeb Aha, thanks.

Also, another question, is this example works for you? : https://fossies.org/linux/SDL2/test/testshader.c

I just tried on my setup, and while all builds fine, i have "failed to compile shader!" , but i set LIBGL_DBGSHADERCONV 1, grab all the shaders, and manually compile them: all fine. So it seems, that "return" values or something are wrong in the ARB part? Maybe glGetInfoLogARB or something?

ptitSeb commented 2 years ago

I just tested on the Pandora and yes, it works fine for me, no error.

kas1e commented 2 years ago

Woah, how strange, found interesting moment, see :

static SDL_bool InitShaders()
{
    int i;

    /* Check for shader support */
    shaders_supported = SDL_FALSE;
    if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&
        SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
        SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
        SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {

        printf("aaaaa\n");

        glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
        glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
        glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
        glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
        glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
...blablablab..

So, if i have there that "printf" , then shaders compiles and works ! If i comment out that prinfs, then shaders didn't compiles ! Wtf .. Point out on some fighting for resources thing or something ...

ptitSeb commented 2 years ago

Seems to be some amiga specific issue. Maybe the way the function pointer are gathered? can't help much here, sorry.

kas1e commented 2 years ago

@ptitSeb Yeah that's 100% amiga specific issue, I remember to meet with something like this a few times, through can't remember if SDL/GL4ES/OGLES2 were involved at all or not.

What i found, that even simple put Delay(1), and even in different place, make that works. For example see:

static SDL_bool InitShaders()
{
    int i;

    /* Check for shader support */
    shaders_supported = SDL_FALSE;
    if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&
        SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
        SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
        SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {

        glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
        glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
        glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
        glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
        glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
        glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB");
        glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
        glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB");
        glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB");
        glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB");
        glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB");
        glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB");

        if (glAttachObjectARB &&
            glCompileShaderARB &&
            glCreateProgramObjectARB &&
            glCreateShaderObjectARB &&
            glDeleteObjectARB &&
            glGetInfoLogARB &&
            glGetObjectParameterivARB &&
            glGetUniformLocationARB &&
            glLinkProgramARB &&
            glShaderSourceARB &&
            glUniform1iARB &&
            glUseProgramObjectARB) {
            shaders_supported = SDL_TRUE;
        }
    }

    if (!shaders_supported) {
        //printf("shaders support false!n");
        return SDL_FALSE;
    }

        IDOS->Delay(1);

    /* Compile all the shaders */
    for (i = 0; i < NUM_SHADERS; ++i) {
        if (!CompileShaderProgram(&shaders[i])) {
            //printf("but compile shaders fail!n");
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to compile shader!n");
            return SDL_FALSE;
        }
    }

    /* We're done! */
    return SDL_TRUE;
}

See Delay(1) before compiling shaders, and when I have that Delay, all works, when remove then don't. It's really like some race condition or something.

Will through that all on our devs