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
711 stars 160 forks source link

Raylib clashes #437

Open afxgroup opened 1 year ago

afxgroup commented 1 year ago

In RayLib all functions starts with rl. And in lists.h there are some functions that has the same name. Would be possible to rename them to something different?

ptitSeb commented 1 year ago

I don't think renaming anything is the solution here. I think I build some stuff with RayLib before with gl4es (ManiaDrive use RayLib IIRC) on the Pandora and it worked fine.

afxgroup commented 1 year ago

That's strange. There are rlColor4f, rlNormal3f and rlEnd that are in both libraries.

ptitSeb commented 1 year ago

Ah ok, I see. You can try renaming those one if you want then. Are you building a static version of gl4es?

afxgroup commented 1 year ago

Yes. It is the static version of gl4es. What about something like rl -> gl4es

ptitSeb commented 1 year ago

there are already many gl4es_ functions,, so you might create more name colision. Try rl4es_ instead ;)

afxgroup commented 7 months ago

Another question regard Raylib5. When I try the shaders examples (version 100). I get the following error:

Compile error: ERROR: 57:1: 'gl4es_transpose' : function already has a body

What does it means? That it is included in both vertex and fragment shader?

ptitSeb commented 7 months ago

That's a bug in the shader transformation (from opengl to gles2). I need to have a look at that (but not sure when I'll do that).

afxgroup commented 7 months ago

Well, Raylib is your friend and it is really easy to compile and test. However this happens when there is already a transpose function (f.e. https://github.com/raysan5/raylib/blob/master/examples/shaders/resources/shaders/glsl100/lighting.vs) So this code:

    if(strstr(Tmp, "transpose(") || strstr(Tmp, "transpose ") || strstr(Tmp, "transpose\t")) {
      Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_transpose, Tmp, &tmpsize);
      gl4es_inplace_replace(Tmp, &tmpsize, "transpose", "gl4es_transpose");
      // don't increment headline count, as all variying and attributes should be created before
    }

Will insert the gl4es_transpose functions on top and rename the existent one

afxgroup commented 7 months ago

A possible workaround could be something like this: Change gl4es_transpose to:

static const char* gl4es_transpose2 =
"mat2 gl4es_transpose(mat2 m) {\n"
" return mat2(m[0][0], m[1][0],\n"
"             m[0][1], m[1][1]);\n"
"}\n";

static const char* gl4es_transpose3 =
"mat3 gl4es_transpose(mat3 m) {\n"
" return mat3(m[0][0], m[1][0], m[2][0],\n"
"             m[0][1], m[1][1], m[2][1],\n"
"             m[0][2], m[1][2], m[2][2]);\n"
"}\n";

static const char* gl4es_transpose4 =
"mat4 gl4es_transpose(mat4 m) {\n"
" return mat4(m[0][0], m[1][0], m[2][0], m[3][0],\n"
"             m[0][1], m[1][1], m[2][1], m[3][1],\n"
"             m[0][2], m[1][2], m[2][2], m[3][2],\n"
"             m[0][3], m[1][3], m[2][3], m[3][3]);\n"
"}\n";

And the replace function with:

    if(strstr(Tmp, "transpose(") || strstr(Tmp, "transpose ") || strstr(Tmp, "transpose\t")) {
      if (gl4es_find_string(Tmp, "mat2 transpose") == NULL)
        Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_transpose2, Tmp, &tmpsize);
      if (gl4es_find_string(Tmp, "mat3 transpose") == NULL)
        Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_transpose3, Tmp, &tmpsize);
      if (gl4es_find_string(Tmp, "mat4 transpose") == NULL)
        Tmp = gl4es_inplace_insert(gl4es_getline(Tmp, headline), gl4es_transpose4, Tmp, &tmpsize);
      gl4es_inplace_replace(Tmp, &tmpsize, "transpose", "gl4es_transpose");
      // don't increment headline count, as all variying and attributes should be created before
    }

However this will work only if the functions are defined like mat2 transpose( (and so on) otherwise ith will not work. A possible other solution could be: Create a Tmp1 string and replace all \n, \t and spaces. Check for mat2transpose( and do the previous replace code