GithubHelp home page GithubHelp logo

fendevel / guide-to-modern-opengl-functions Goto Github PK

View Code? Open in Web Editor NEW
1.0K 22.0 40.0 119 KB

A guide to using modern OpenGL functions.

License: Creative Commons Zero v1.0 Universal

dsa modern modern-opengl-functions opengl textureview texture-atlas pipeline-object uniform direct-state-access modern-opengl

guide-to-modern-opengl-functions's Issues

Incorrect CLAMP parameters

The README document describes the following in the following section

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

Do you probably want GL_CLAMP_TO_EDGE for these texture_wrap parameters?

https://www.khronos.org/opengl/wiki/Common_Mistakes

Never use GL_CLAMP; what you intended was GL_CLAMP_TO_EDGE. Indeed, GL_CLAMP was removed from core GL 3.1+, so it's not even an option anymore.

Index and Vertex data under a single buffer

First of all... let me just say, this modern OpenGL guide has been extremely helpful for me, so that you for putting it together.

Regarding the guidance on storing index + vertex data within a single buffer (link)

It states that:
All we need to do is store the indices before the vertex data and tell OpenGL where the vertices begin, this is achieved with glVertexArrayVertexBuffer's offset parameter.

Maybe this is no secret to some, but it eluded me for a while. It turns out it is entirely possible to reference index data from anywhere within a vertex buffer, there is no need for it to reside before/after the vertex data in particular.

Simply indicate the byte offset into the relevant buffer via the offset parameter of glDrawElements:

// Assume we have a prepopulated buffer, vertex attributes followed by index elements.

glCreateVertexArrays(1, &vao);
glVertexArrayVertexBuffer(vao, 0, buffer, buffer_size, sizeof(vertex_t));
glVertexArrayElementBuffer(vao, buffer);

size_t indices_offset = get_indices_offset(buffer);

at render time

glDrawElements(GL_TRIANGLES, indices_count, indices_format, (void *) indices_offset);

glProgramUniformXX is not defined by ARB_direct_state_access

This is a very minor thing I dug details into when doing extensions.
For shader introspection, the following two function are actually defined with the extension ARB_separate_shader_objects and not ARB_direct_state_access. I think this should be mentioned in the page.

glProgramUniformXX, glProgramUniformXXv

I'm aware this is basically a non issue because if you support direct state access then you most likely support separate shader objects

Some links to the docs
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_direct_state_access.txt
https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_separate_shader_objects.txt

Discord tag doesn't work

Hi, I tried to add you on Discord, so I could message you but when I entered your tag (Fen#0110) into the add friend bar there were no results. My guess is that if you had Nitro and used it to set your Discriminator, it may have run out and your discrim might have been rerandomized as a result.

It is not necessary to use the GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT parameter for the example of storing index and vertex data in a single buffer.

Everything is in the title, your example is good but I don't understand why you use GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT.

Solution :

`GLuint vao = GL_NONE;
GLuint buffer = GL_NONE;

auto const ind_len = GLsizei(ind_count * sizeof(element_t));
auto const vrt_len = GLsizei(vrt_count * sizeof(vertex));

auto const ind_offset = vrt_len;
auto const vrt_offset = 0;

glCreateBuffers(1, &buffer);
glNamedBufferStorage(buffer, ind_len + vrt_len, nullptr, GL_DYNAMIC_STORAGE_BIT);

glNamedBufferSubData(buffer, ind_offset, ind_len, ind_data);
glNamedBufferSubData(buffer, vrt_offset, vrt_len, vrt_data);

glCreateVertexArrays(1, &vao);
glVertexArrayVertexBuffer(vao, 0, buffer, vrt_offset, sizeof(vertex));
glVertexArrayElementBuffer(vao, buffer);`

incorrect glTextureStorage3D parameter

According to the spec:

An INVALID_VALUE error is generated if width, height, depth or levels are less than 1, for commands with the corresponding parameters.

This line in your guide will generate an INVALID_VALUE error since levels is set to 0;
glTextureStorage3D(texarray, 0, GL_RGBA8, width, height, layers);

You did set it to 1 in the other examples so I'm guessing this is just a typo.

farewell `glGetError()`, nope

Excellent tutorial on the DSA features! Thank you very much for making this easily understandable.

I just want to point out that, farewell glGetError() is not true, the new DebugMessageCallback() does make debugging easier, but it doesn't work all the time. Sometimes it cannot catch an error even if glGetError() returned some error code. My point is that, very often during debugging, glGetError() can still help us a lot in finding errors, so I think we should use these two debugging functions together.

I always like to wrap glGetError() in a function like this, then insert the call across multiple places in my code, while keeping track of each checkpoint. This can help us quickly find the line of code that triggers the error when DebugMessageCallback() silently fails. Hope this helps!

    void Log::CheckGLError(int checkpoint) {
        GLenum err_code;
        while ((err_code = glGetError()) != GL_NO_ERROR) {
            CORE_ERROR("OpenGL error detected at checkpoint {0}: {1}", checkpoint, err_code);
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.