We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2230 - Render calls do not encapsulate glEnable/DisableVertexAttribArray properly
Summary: Render calls do not encapsulate glEnable/DisableVertexAttribArray properly
Status: RESOLVED WONTFIX
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.1
Hardware: All All
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-12 22:40 UTC by noone
Modified: 2017-08-15 04:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description noone 2013-11-12 22:40:58 UTC
Example from current 2.0.1 source code version SDL_render_gles2.c:

static int
GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
{
    GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
    GLfloat vertices[8];
    int idx;

    if (GLES2_SetDrawingState(renderer) < 0) {
        return -1;
    }

    /* Emit a line loop for each rectangle */
    for (idx = 0; idx < count; ++idx) {
        const SDL_FRect *rect = &rects[idx];

        GLfloat xMin = rect->x;
        GLfloat xMax = (rect->x + rect->w);
        GLfloat yMin = rect->y;
        GLfloat yMax = (rect->y + rect->h);

        vertices[0] = xMin;
        vertices[1] = yMin;
        vertices[2] = xMax;
        vertices[3] = yMin;
        vertices[4] = xMin;
        vertices[5] = yMax;
        vertices[6] = xMax;
        vertices[7] = yMax;
        data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    }
    return GL_CheckError("", renderer);
}


-------

If I do call glDisableVertexAttribArray(0) before this code is run, glVertexAttribPointer will fail. All OpenGL vertex attrib calls should properly encapsulated in glEnable/glDisable before using attrib data.

Does not fail on all system as some drivers behave different on disabling attrib 0, but encapsulation will solve this issue always.
Comment 1 Sam Lantinga 2013-11-16 20:07:32 UTC
SDL assumes that when you're using the render API that you're not doing other 3D calls, as an optimization. If you do need to do other 3D calls you should set and restore your state appropriately.

That said, I'm not opposed to a patch that implements encapsulation the way you describe as long as it doesn't negatively impact performance.
Comment 2 Sam Lantinga 2017-08-15 04:45:51 UTC
We won't fix this in SDL for performance reasons. Code that interoperates with SDL rendering should do it's own state push/pop to make sure everything is correct and consistent.