glad icon indicating copy to clipboard operation
glad copied to clipboard

glad2 Documentation

Open Dav1dde opened this issue 8 years ago • 43 comments

C

  • [x] Examples
  • [ ] Quick Start
  • [x] Options

Rust

  • [ ] Examples
  • [ ] Quick Start
  • [ ] Options

Related issues:

  • #161

Dav1dde avatar Aug 11 '17 14:08 Dav1dde

One question to glad2, am I doing this right? gladLoadGLSimple(GLADsimpleloadproc())

Edit: In case yes, what speaks against:

GLAPI int gladLoadGL();
GLAPI int gladLoadGLProc(GLADsimpleloadproc load);
GLAPI int gladLoadGLProcUsr(GLADloadproc load, void* userptr);

BlGene avatar Mar 02 '18 17:03 BlGene

Still deciding on the API, currently it's:

typedef void* (* GLADloadproc)(const char *name, void* userptr);
typedef void* (* GLADsimpleloadproc)(const char *name);

GLAPI int gladLoadGL(GLADloadproc load, void* userptr);
GLAPI int gladLoadGLSimple(GLADsimpleloadproc load);
GLAPI int gladLoadGLInternalLoader();

Maybe naming the functions according to what arguments they take is the better solution. My only set goal is to get rid of the gladLoadGL() which uses the internal loader, I want the default usage to be without loader (basically every windowing framework has a GetProcAddress implementation).

Dav1dde avatar Mar 02 '18 17:03 Dav1dde

...So if I call gladLoadGLInternalLoader I don’t have to call gladLoadGLSimple?

BlGene avatar Mar 02 '18 18:03 BlGene

Correct, you only need to call one of those three (calling these functions in total more than once may result in weird results).

Dav1dde avatar Mar 02 '18 18:03 Dav1dde

ProTip: When calling the glad executable add --loader

The loader function names have also changed: gladLoadEGLInternalLoader -> gladLoaderLoadEGL gladLoadGLInternalLoader -> gladLoaderLoadGL

BlGene avatar Jun 13 '18 06:06 BlGene

@Dav1dde ~~I just spent a while figuring out that gladLoaderLoadGL() was failing on certain machines because it didn't find the libGL.so.1 file. It would be nice to have more informative error information from this function.~~

BlGene avatar Jun 13 '18 11:06 BlGene

Thanks, I am still working on the documentation, the wiki should be accurate: https://github.com/Dav1dde/glad/wiki/C

Interesting that libGL.so isn't available, what else is available?

I am not sure how I would do a better error handling. Return code 0 (false) is failure, return code > 0 is the loaded version, negative return codes would break the if (!load()) "idiom".

Dav1dde avatar Jun 13 '18 14:06 Dav1dde

@Dav1dde: It looks like the problem wasn't with dlopen.

So when a colleague in another department tries to run the following code(link below) he gets errors when calling gladLoaderLoadGL. This occurs on all his Ubuntu 16 machines, not his Ubuntu 14 machines, for me it works fine on several Ubunut 16 machines.

https://gist.github.com/BlGene/b78e237efb65086de3ef9e8aafdbef02#file-egl_gl2-cpp-L167

Is there anything we could do to give more meaningful debug information?

BlGene avatar Jun 13 '18 15:06 BlGene

What error does he get, return value of 0? Glad would usually only fail if it cannot load an essential function (a function required to get very basic information, like glGetString), on a failed allocation (malloc, calloc etc.) or glGetString returning NULL where it shouldn't. For now the easiest way to figure that out why glad is failing, is to add a printf() (or breakpoint) where glad returns 0 (just ctrl-f for return 0).

I'll try to reproduce this in the next few days and add a pre-processor flag that provides additional information why the loader is failing.

Dav1dde avatar Jun 13 '18 19:06 Dav1dde

It looks like the error occurs in the function gladLoadGLUserPtr on the line glGetString(GL_VERSION) == NULL.

We tried get an error message by calling glGetError but this did not produce any results. Doing cout << load("glGetString", userptr) << endl; returns 1.

BlGene avatar Jun 14 '18 11:06 BlGene

This usually happens if there is no active/current context.

I'll have to look into that later.

Dav1dde avatar Jun 14 '18 12:06 Dav1dde

But I'm creating a context and making it current https://gist.github.com/BlGene/b78e237efb65086de3ef9e8aafdbef02#file-egl_gl2-cpp-L156

Edit: I did a check and I'm not getting error messages during context creation or making it current.

Could there be a mismatch between libs: e.g. loading a nvidia EGL library and a mesa GL library?

BlGene avatar Jun 14 '18 13:06 BlGene

Mh that actually makes sense that it doesn't work, glad uses a glx function to retrieve gl pointers and you're using egl not glx. Try passing eglGetProcAddress to gladLoadGL.

Dav1dde avatar Jun 15 '18 05:06 Dav1dde

@Dav1dde: Looks like this solved it. Thanks!

My test file is located here in case you want to include it. (no build script) https://github.com/BlGene/glad/tree/glad2-egl-example

By the way, I'm still for adding the option to load X11 functions dynamically. It would only change ~50 lines of code, see glx_dyn.c in https://gist.github.com/BlGene/add866798e551424a75315099196b53d

BlGene avatar Jun 15 '18 09:06 BlGene

I just saw you're still using version % 10 and version / 10, this does not work with the latest glad version anymore, you should use the macros GLAD_VERSION_MAJOR(version) and GLAD_VERSION_MINOR(version) instead.

I don't think I am going to dynamically load X11 functions, it's just something I don't wanna take care of (what if X11 is not available, what if the X11 so is named differentely on a platform etc.), I'll probably add a macro though which disables the usage of those 3 X11 functions (since they are just convenience) and you simply have to pass a valid screen and display instead of NULL.

Dav1dde avatar Jun 15 '18 16:06 Dav1dde

@BlGene try compiling with -DGLAD_GLX_NO_X11, glad will not call X11 functions anymore, but you need to pass a valid display/screen to glad*LoadGLX.

Dav1dde avatar Jun 16 '18 09:06 Dav1dde

Shouldn't this be in the "glad space 2" milestone not the "glad2" milestone?

daltonhildreth avatar Jul 03 '18 21:07 daltonhildreth

Should I bother to call glXQueryExtension when using glad2 or is it unnecessary? I see that glXQueryVersion is used.

surafel911 avatar Sep 23 '18 02:09 surafel911

You don't have to, glad loads all extensions that were specified automatically. In order to check if an extension is supported you can use the global variable named after the extension and prefixed with GLAD_, e.g. to check if GLX_ARB_create_context_profile is supported:

If (GLAD_GLX_ARB_create_context_profile) {
    // supported
} 

Dav1dde avatar Sep 23 '18 07:09 Dav1dde

I can't find any of those global variables you're talking about. Is this something I have to query using a function?

surafel911 avatar Sep 23 '18 15:09 surafel911

They do exist:

#define GLX_VERSION_1_0 1
GLAD_API_CALL int GLAD_GLX_VERSION_1_0;
#define GLX_VERSION_1_1 1
GLAD_API_CALL int GLAD_GLX_VERSION_1_1;
#define GLX_VERSION_1_2 1
GLAD_API_CALL int GLAD_GLX_VERSION_1_2;
#define GLX_VERSION_1_3 1
GLAD_API_CALL int GLAD_GLX_VERSION_1_3;
#define GLX_VERSION_1_4 1
GLAD_API_CALL int GLAD_GLX_VERSION_1_4;
#define GLX_3DFX_multisample 1
GLAD_API_CALL int GLAD_GLX_3DFX_multisample;
#define GLX_ARB_create_context_profile 1
GLAD_API_CALL int GLAD_GLX_ARB_create_context_profile;

Dav1dde avatar Sep 23 '18 16:09 Dav1dde

I don't have anything past GLX_VERSION in my glx.h. I've added my glx.h file if you want proof.

glx.txt

surafel911 avatar Sep 23 '18 16:09 surafel911

You didn't add any extensions (from the header you attached):

/**
 * <snip>
 * Extensions: 0
 *
 * <snip>
 *
 * Commandline:
 *    --api='glx=1.4' --extensions='' c --loader --alias
 *
 * <snip>
 *
 */

If you want support for an extension you have to add it, on the website you can just click the extensions - on commandline you have to add them to the extension argument.

Dav1dde avatar Sep 23 '18 16:09 Dav1dde

What platforms does GLAD support? Does it support OpenGL ES 3.x

EDIT: Well, I see that it supports OpenGL ES 3.x but why is it listed as GLES 2. It is different enough to deserve a separate or clearer indication.

Zingam avatar Sep 25 '18 12:09 Zingam

GLES 2 is the API as defined by Khronos, you are using the version 3.2 of this API.

GLES 1 is the 'old' API.

Dav1dde avatar Sep 25 '18 13:09 Dav1dde

Khronos specifies the headers as <GLES3/gl32.h>. What confused me is the web service here: https://gen.glad.sh/ as all of the GL version are bunched together but the GLES are separated. I think it would be beneficial gles versions and platforms are mentioned in the documentation.

Zingam avatar Sep 26 '18 06:09 Zingam

I agree this should be added to the docs.

Dav1dde avatar Sep 26 '18 06:09 Dav1dde

The sample doesn't have the cast but I can't compile without it: gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);

Zingam avatar Sep 26 '18 11:09 Zingam

Can you link me the example? I don't remember having more than just this SDL exmaple.

Dav1dde avatar Sep 26 '18 12:09 Dav1dde

Sorry for the confusion. I copied this line from my source. What I mean is: https://github.com/Dav1dde/glad/tree/glad2 Shouldn't that example contain the cast too for the sake of clarity:

int version = gladLoadGL(glfwGetProcAddress);
    if (version == 0) {
        printf("Failed to initialize OpenGL context\n");
        return -1;
    }

https://github.com/Dav1dde/glad/blob/glad2/example/c%2B%2B/hellowindow2.cpp

Zingam avatar Sep 26 '18 15:09 Zingam

The cast here is not required because the types match, I actually prefer it without the cast (when possible), it makes sure you're not accidentally casting the wrong function and imo it looks a lot cleaner.

Dav1dde avatar Sep 26 '18 16:09 Dav1dde

I agree but for tutorial's the cast needs to be documented as this will save some learner's headbanging.

Zingam avatar Sep 27 '18 05:09 Zingam

I noticed that when using GLAD glXCreateContextAttribsARB hasn't been loaded (confirmed by GLAD_GLX_create_context and GLAD_GLX_create_context_profile being 0), but when I use the shared library version, the function is available and works fine in my project. Any ideas?

surafel911 avatar Sep 29 '18 21:09 surafel911

My opengl version using the old method for creating contexts is 4.5 (the highest my hardware allows). I did some googling and I found this link that has important info.

https://stackoverflow.com/a/12169748

surafel911 avatar Sep 29 '18 23:09 surafel911

I assume you've called gladLoadGLX, if so please paste the output of glxinfo somewhere (e.g. a gist).

Dav1dde avatar Sep 30 '18 09:09 Dav1dde

I have called gladLoaderLoadGLX.

https://gist.github.com/surafel911/e592470618d5ffe565087d8bed21508f

surafel911 avatar Sep 30 '18 13:09 surafel911

@surafel911 fixed in https://github.com/Dav1dde/glad/commit/e5090adad5319b4ff130963c3c03be74de5a7cab - I broke the extension detection.

Thanks!

Dav1dde avatar Sep 30 '18 16:09 Dav1dde

Will this patch be available in the extension loader or do I have to wait for the next release?

surafel911 avatar Sep 30 '18 16:09 surafel911

You can already re-generate from http://gen.glad.sh - For the glad2 branch I'll continuously update the web generator.

Dav1dde avatar Sep 30 '18 17:09 Dav1dde

I got some compiler errors.

https://gist.github.com/surafel911/46a8add9d1e79e7dbde7a790a4953b21

surafel911 avatar Oct 01 '18 01:10 surafel911

What options did you use to generate (should be listed on top of the header file)? Or please upload a zip containing the C and header files.

Dav1dde avatar Oct 01 '18 05:10 Dav1dde

Got the time to make a zip of my files.

glad.zip

surafel911 avatar Oct 03 '18 20:10 surafel911

Seems like you accidentally typed into the source file:

image

At least I cannot reproduce this with the options you used, also this is basically impossible to be generated by glad since all those variables are generated at the same place within one for loop.

Removing the marked line and the if at the beginning of the next makes the file compile.

Dav1dde avatar Oct 07 '18 06:10 Dav1dde