liveBook · Manning

Draw call

As explained in Systems Programming with Zig

A draw call is a graphics API command that instructs the graphics system to render geometry using configured state.

A draw call tells the graphics system to render geometry using its current configuration. In OpenGL, it starts the rasterization pipeline: vertices are processed, geometry is assembled into shapes, and fragments are shaded and written to a framebuffer. section 7.1.2 section 7.6

OpenGL keeps much of that configuration in a context. A draw call uses the currently bound vertex array object (VAO) for vertex attributes and the currently bound shader program for processing. Bind the program with glUseProgram—not glBindProgram, despite the tempting name. section 7.4.1 section 7.4.6 section 7.4.4

For a simple triangle, glDrawArrays selects triangles and tells OpenGL to process three vertices. Other draw-call functions use different mechanisms. A draw call modifies the framebuffer only where it draws primitives, so clear the screen each frame to avoid leftovers from earlier frames. section 7.4.6 section 7.4.4

Listing 7.15 Drawing with data
while (c.GLFW_FALSE == c.glfwWindowShouldClose(window)) {
    c.glClearColor(0.1, 0.2, 0.2, 1.0); #1
    c.glClear(c.GL_COLOR_BUFFER_BIT); #2

    {
        c.glBindVertexArray(vao); #3
        defer c.glBindVertexArray(0);

        c.glUseProgram(shader_program); #3
        defer c.glUseProgram(0);

        c.glDrawArrays(c.GL_TRIANGLES, 0, 3); #4
    }

    c.glfwSwapBuffers(window); #5
    c.glfwPollEvents();
}

Follow the frame loop: clear the color buffer, bind the VAO and program, draw three vertices, then swap buffers and poll events. Zig's defer statements unbind the VAO and program when the inner scope ends. section 7.4.6

How Systems Programming with Zig covers it

How deep it goes
Explains bound state, vertex attributes, and a frame-loop draw sequence, while noting other draw-call variants without detailing them.
Examples
Illustrates a triangle drawn from three vertices in a window loop that clears and swaps buffers.
What you can do after
Apply it via OpenGL to configure bound state and issue a draw call.
How it connects
Connects draw calls to OpenGL contexts, vertex array objects, shaders, rasterization, and framebuffers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.