Motivation
A mesh, an image and a screen are all arrays, but they play different roles in a graphics system. A vertex buffer supplies structured inputs to primitive processing. A texture supplies reconstructed values queried by coordinates. A framebuffer receives sample results after enabled tests and blending. Confusing those roles produces errors that no change of camera matrix can repair. An object name identifies an API resource; it does not by itself say which resource a later draw will read or write.
This note uses native OpenGL 3.3 core concepts. The Khronos core specification defines the abstract state and observable operations. It does not promise a particular vendor's cache layout, execution-group width, number of processing units or scheduling order. A driver may execute work asynchronously while preserving required observable semantics. A draw call returning is consequently not a measurement that every fragment has physically finished.
The host constructs data and commands; programmable stages transform those data; primitive and sample operations determine image contributions. These are useful logical boundaries, not a claim that each stage occupies a separate physical chip unit. Input events first produce application decisions, such as a new transform or selection ray. The graphics API then consumes the corresponding state. Display presentation is another boundary involving a window system; producing an offscreen texture does not present it on a monitor.
Definitions
Definition 11.1.1
(Buffer storage and vertex-fetch description)
A buffer is a byte store. An enabled per-vertex attribute describes a buffer association, encoded element extent bytes, nonnegative offset , and effective positive stride . Vertex index requests bytes in . The effective stride includes the tightly packed interpretation when an API stride argument is zero. A vertex array object records vertex-input state; it is not another copy of the vertex bytes.
For the traditional binding interface, an attribute pointer records the buffer bound when that description is specified; rebinding the general array-buffer target later does not rewrite the recorded association. The Khronos vertex-array reference source and core vertex-array sections establish the object contract. The buffer-data reference distinguishes the buffer store from the client array used to initialize it. Index values, not merely the number of submitted indices, determine which vertex records are needed.
Definition 11.1.2
(Texture reconstruction and framebuffer attachments)
A texture image has dimensions, a format and levels. Coordinates select reconstructed texel values under filtering and wrap rules. A framebuffer object records attachments referring to images, plus read/draw routing; it is not itself the color array. A renderbuffer supplies renderable storage without the ordinary texture sampling interface. A sampler uniform identifies a texture unit, whose bindings determine the texture queried. If a sampler object is bound to that unit, its filtering and wrap state supersedes the texture's corresponding sampling parameters, as specified in core section 3.8.2.
The texture-image reference distinguishes internal storage from the incoming data format and type. A minification filter that needs mip levels requires a compatible complete level set. Mip generation derives levels from a base image; its availability does not promise a particular ideal box filter. Framebuffer binding selects read and draw destinations. These contracts remain separate from viewport dimensions and shader texture coordinates.
Theorem / proposition
Theorem 11.1.3
(A finite vertex-fetch bound)
Consider one described per-vertex attribute with effective stride , offset , extent , and a nonempty finite set of actual nonnegative vertex indices. Every requested byte interval lies in a buffer of size exactly when
For indexed draws, exclude primitive-restart markers before applying any base-vertex offset to form these effective indices. The index stream, if present, needs its own storage bound. This statement concerns the logical input description, not a guarantee that hardware physically fetches every unused attribute.
Theorem 11.1.4
(Normalized filtering does not amplify bounded sample error)
Let filter weights satisfy and . If source values obey , then , and the exact filtered value lies between the smallest and largest source value. For an integer , if the filtered result is then rounded to the nearest of uniformly spaced levels on , its additional error is at most , provided the unrounded value is in that interval. For the combined bound, assume exact source values lie in and clamp the perturbed filtered result to before rounding; then total error is at most .
The filtering theorem is a numerical stability statement. It does not say the samples determine an arbitrary unsampled signal or that a chosen filter removes aliasing. Its quantization clause is an explicit ideal round-to-nearest model, not a promise that every graphics conversion, dithering state and framebuffer format implements that exact rule.
Counterexample mode
Weights summing to one are not enough
A tempting claim is that any filter whose weights sum to one keeps sample errors below and stays in the source range. Take the three weights , which sum to one. Exact samples lie in , but the filtered value is . Errors give , and . The repair is nonnegative weights, or the bound .
Proof sketch or proof idea
Proof
(The largest index decides the fetch bound)
All fetch intervals begin at nonnegative positions because indices and offset are nonnegative. Their right endpoints increase with the index, so the largest requested endpoint is . If that endpoint is within , all others are too. Conversely, if it exceeds , the interval for the largest index is not contained. For an ordinary nonindexed draw with first index and count , the maximum is ; an indexed draw must inspect the actual maximum rather than substitute its count.
Proof
(Triangle inequality, convexity and clamped rounding)
For the filter, use the triangle inequality:
The same nonnegative weights express a convex combination, proving the range bound. Adjacent uniform quantization levels differ by ; every point in the interval is within half that spacing of a nearest level. For the combined claim the exact filtered target is in . Clamping a perturbed value to that interval cannot increase its distance to the target: an outside value moves toward every interval point, while an inside value is unchanged. Applying nearest rounding afterwards gives error at most . Negative reconstruction weights require a different bound involving , which can exceed one.
Proof X-ray
Where the weights, the clamp and the rounding enter
Each hypothesis of the filtering theorem has a definite role. Nonnegativity of the weights is what lets the triangle inequality pass the absolute value inside the sum without a sign change, and it also makes the average a convex combination, which gives the range statement. The condition turns into ; with weights summing to the bound would double.
The non-obvious move is the clamp. Rounding error is at most half a level spacing only for values inside , but a perturbed value can fall outside that interval. Clamping cannot increase the distance to an exact target that lies inside it, so the two error sources then add: before rounding, half a spacing after. Without the clamp the second term is not available. The argument closes by the triangle inequality for the two stages, and nothing in it says the stored data are the right data: a valid buffer can contain the wrong normal, and a stable average can blur an unresolved checkerboard. Layout, stability and approximation quality are checked separately.
Worked examples
Worked example 11.1.5
(An index count is not a maximum index)
Store three-float positions followed by two-float UV coordinates, giving stride twenty bytes. For indices , the UV extent is eight and its offset twelve. The bound is bytes. A 160-byte buffer suffices for that attribute; a 159-byte buffer does not. The position's last byte is 151, corresponding to interval ; the UV's last byte is 159, with interval . The buffer must span eight record slots even though only three records are fetched.
Worked example 11.1.6
(Minification needs a footprint, not just a smooth lookup)
A four-by-four checker texture repeated eight times across a sixteen-pixel target spans thirty-two texels in each image direction. One target pixel therefore spans about two source texels per direction in this affine example. An ideal two-by-two box average of the alternating checker is , whereas sampling one texel can alternate between zero and one. The two-to-one footprint motivates level of detail , meaning mip level one rather than a scale factor of one. The example explains an ideal filter; it does not assert the exact texels generated by every conforming mip-generation implementation.
Worked example 11.1.7
(Premultiplied blend factors and rounding)
Let a source have premultiplied RGB and alpha , over opaque destination . The over result is with alpha one. Using source factor one and destination factor implements this equation. Multiplying the already premultiplied source by alpha again gives the wrong red value . Under the theorem's eight-bit ideal rounding model, each final component acquires at most additional error. This bound concerns storage, not the display's radiometric calibration.
A complete native offscreen state contract
The following C++ routine creates and renders a small textured tile, returning its color texture. It assumes a fresh current OpenGL 3.3 core context and resolved platform-appropriate entry points; the declaration header does not create or load that context. It is complete for this offscreen operation, not a complete native window/bootstrap application. The caller later deletes the returned texture while a suitable context is current. The code changes state rather than restoring an arbitrary caller state. No GPU execution is claimed.
The embedded shaders use GLSL 3.30 revision 6. The routine uses a source texture distinct from its framebuffer attachment. Resource cleanup handles the routine's normal return and C++ exceptions.
// Preconditions: a fresh, current OpenGL 3.3 core context and resolved GL entry points.
// This file does not create a platform window/context or present an image.
#define GL_GLEXT_PROTOTYPES 1
#include <GL/glcorearb.h>
#include <stdexcept>
#include <string>
static GLuint compileTileShader(GLenum type, const char* source) {
GLuint shader = glCreateShader(type);
if (!shader) throw std::runtime_error("shader allocation failed");
glShaderSource(shader, 1, &source, nullptr);
glCompileShader(shader);
GLint ok = GL_FALSE;
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
if (!ok) {
char log[2048] = {};
glGetShaderInfoLog(shader, sizeof log, nullptr, log);
glDeleteShader(shader);
throw std::runtime_error(std::string("shader: ") + log);
}
return shader;
}
struct TileResources {
GLuint vs=0, fs=0, program=0, vao=0, vbo=0, source=0, color=0, fbo=0, depth=0;
~TileResources() {
if (program) glDeleteProgram(program);
if (vs) glDeleteShader(vs);
if (fs) glDeleteShader(fs);
glDeleteVertexArrays(1, &vao);
glDeleteBuffers(1, &vbo);
glDeleteFramebuffers(1, &fbo);
glDeleteRenderbuffers(1, &depth);
glDeleteTextures(1, &source);
glDeleteTextures(1, &color);
}
};
// Returns a 16 x 16 RGBA8 texture. The caller owns it and must later delete it.
// The routine changes GL state; it is not a state-preserving library wrapper.
GLuint renderOffscreenTile() {
TileResources r;
const char* vertex = R"GLSL(#version 330 core
layout(location=0) in vec2 position;
layout(location=1) in vec2 uv;
out vec2 textureCoordinate;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
textureCoordinate = uv;
}
)GLSL";
const char* fragment = R"GLSL(#version 330 core
in vec2 textureCoordinate;
uniform sampler2D image;
out vec4 color;
void main() { color = texture(image, textureCoordinate); }
)GLSL";
r.vs = compileTileShader(GL_VERTEX_SHADER, vertex);
r.fs = compileTileShader(GL_FRAGMENT_SHADER, fragment);
r.program = glCreateProgram();
if (!r.program) throw std::runtime_error("program allocation failed");
glAttachShader(r.program, r.vs);
glAttachShader(r.program, r.fs);
glLinkProgram(r.program);
GLint linked = GL_FALSE;
glGetProgramiv(r.program, GL_LINK_STATUS, &linked);
if (!linked) {
char log[2048] = {};
glGetProgramInfoLog(r.program, sizeof log, nullptr, log);
throw std::runtime_error(std::string("link: ") + log);
}
const GLfloat vertices[] = {
-1,-1, 0,0, 1,-1, 8,0, 1,1, 8,8,
-1,-1, 0,0, 1,1, 8,8, -1,1, 0,8
};
glGenVertexArrays(1, &r.vao);
glGenBuffers(1, &r.vbo);
glBindVertexArray(r.vao);
glBindBuffer(GL_ARRAY_BUFFER, r.vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat), nullptr);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(GLfloat),
reinterpret_cast<const void*>(2*sizeof(GLfloat)));
unsigned char pixels[4*4*4];
for (int y=0; y<4; ++y) for (int x=0; x<4; ++x) {
const int base = 4*(4*y+x);
const unsigned char value = ((x+y)%2) ? 255 : 0;
pixels[base]=value; pixels[base+1]=value;
pixels[base+2]=value; pixels[base+3]=255;
}
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &r.source);
glBindTexture(GL_TEXTURE_2D, r.source);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);
glGenTextures(1, &r.color);
glBindTexture(GL_TEXTURE_2D, r.color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 16, 16, 0,
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glGenFramebuffers(1, &r.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, r.fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, r.color, 0);
glGenRenderbuffers(1, &r.depth);
glBindRenderbuffer(GL_RENDERBUFFER, r.depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 16, 16);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, r.depth);
const GLenum attachment = GL_COLOR_ATTACHMENT0;
glDrawBuffers(1, &attachment);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
throw std::runtime_error("incomplete offscreen framebuffer");
glBindTexture(GL_TEXTURE_2D, r.source); // Read source; write the different color image.
glUseProgram(r.program);
glUniform1i(glGetUniformLocation(r.program, "image"), 0);
glViewport(0, 0, 16, 16);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glDisable(GL_CULL_FACE);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_FRAMEBUFFER_SRGB);
glClearColor(0,0,0,1);
glClearDepth(1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindVertexArray(0);
glUseProgram(0);
GLuint result = r.color;
r.color = 0; // Preserve only the returned texture when r releases other objects.
return result;
}
State, sampling and finite precision
The six fetched vertices assemble two triangles. Clipping and rasterization decide covered samples; the fragment shader queries the source texture. The depth test and depth write mask are separate: one controls comparison, the other whether accepted depth updates storage. Blending is also independent. For premultiplied over, additive blend equations and separate factors (ONE, ONE_MINUS_SRC_ALPHA) for RGB and alpha express the worked example; see the Khronos blend-factor reference. Correct factors do not solve transparent-surface ordering.
Binding an offscreen framebuffer does not resize the viewport. The routine explicitly matches both to sixteen by sixteen. Its color image uses a non-mipmapped minification filter; its source has generated mip levels. A framebuffer completeness test checks structural attachment requirements, not that the shader is reading the intended source. Reading an attached image while writing that same image can create an undefined rendering feedback loop even when the framebuffer is complete. Separate source and destination images, then change attachments or bindings deliberately for a later pass.
Texture coordinates are not byte addresses. In a width- image, texel centers occur at normalized coordinates . Filtering combines nearby samples; wrap state defines what happens beyond the edge. Upload layout is another contract: tightly packed RGB rows of width three occupy nine bytes, while a four-byte unpack alignment rounds each row stride up to twelve. Setting unpack alignment one describes the nine-byte layout. Neither the shader's coordinate scale nor its vertex stride fixes a mistaken pixel-upload stride.
Downsampling without a suitable low-pass filter loses information. The sequences and agree at every integer for integer . No later filtering can decide which continuous frequency produced those samples. A mip pyramid approximates suitable footprints at several scales; derivative-based scale selection and between-level interpolation still approximate the desired pixel integral. A long, narrow footprint also cannot generally be represented well by one isotropic level.
Precision must be interpreted in the quantity actually stored. Under a perspective depth map , , equal small depth increments correspond locally to distance increments about . Thus a fixed uniform depth grid allocates distance resolution unevenly. In color, an eight-bit normalized format has finite levels even if the shader computes in floating point. Repeated fixed-opacity over operations multiply previous destination error by the factor but introduce new storage rounding. More shader precision does not restore detail already lost in vertex encoding, texture acquisition or a previous framebuffer write.
A limited hardware cost model
A useful quantitative model separates arithmetic throughput from data transfer. If a particular execution requires arithmetic operations and actually transfers bytes across a bottleneck with positive upper/peak rates operations per second and bytes per second, its time is at least . Each resource must supply its own work even if computation and transfer overlap perfectly. This lower bound assumes the stated rates and work counts; it is not an OpenGL timing guarantee. Caches, compression, scheduling and incomplete overlap determine the actual counts and delay.
This explains why reducing shader arithmetic may have little effect on a bandwidth-limited workload, while reusing geometry or reducing a texture footprint may help. An indexed mesh expresses logical reuse but does not guarantee a specified number of physical memory transactions. Interleaving attributes may suit one access pattern while separate arrays suit another. A host readback also introduces a dependency on produced results and may force waiting that ordinary submission did not require. Measure a concrete implementation before making a vendor-performance claim; the API contract alone supplies neither cache hit rates nor frame latency.
Common mistakes
Counterexample mode
Framebuffer completeness does not make feedback safe
Attach texture image as the draw destination and also make the shader sample that same image at level zero. The attachment structure can be complete while the read/write operation has undefined feedback behavior under the stated core rules. An attractive result on one driver does not establish a defined algorithm. Repair it by reading image and writing a distinct image , then swapping their roles only after updating the relevant attachments and sampler bindings for the next pass.
Common mistake
(Taking the number of indices as the highest index)
Three indices describe three fetched records, but the buffer must reach record nine. A buffer sized for three records covers only the first three slots. The count controls the length of primitive submission; the maximum referenced index controls the highest address.
Common mistake
(Treating a successful compile as correct state)
A successful source compilation does not prove that the desired program, texture unit, attachments and blend state were bound at draw time. Check the state that the draw actually sees.
Common mistake
(Mixing the abstract machine with one vendor's behavior)
The API does not promise one physical shader invocation per displayed pixel, nor a universal vendor execution order. Hardware explanations should identify whether they describe the public abstract machine or one measured implementation; this note establishes only the former's contracts.
Summary
Buffers describe bytes, vertex arrays describe fetches, textures describe sampled images, and framebuffers describe destinations. Explicit fetch bounds and filter-error bounds expose different failure modes. Native offscreen rendering also needs compatible shaders, attachments, viewport, depth and blend state, and distinct read/write images. API-defined results, sampling approximations and vendor execution details are different levels of explanation.
Exercises
Quick check
(An attribute has offset sixteen, stride twenty-four and extent eight, and indices . Find the smallest sufficient buffer size. Would a buffer sized for only three records suffice?)
Apply the fetch bound with the largest index.
Solution · Answer
The largest endpoint is bytes. Three twenty-four-byte records give only 72 bytes and do not cover index nine. The number of indices controls primitive submission length, not the highest referenced vertex address.
Quick check
(A packed RGB image has width five and two rows. Compute row stride and the byte offset of the second row under unpack alignments four and one.)
A row holds data bytes.
Solution · Answer
Each row contains fifteen data bytes. Alignment four rounds stride to sixteen, so the second row begins at byte sixteen. Alignment one uses stride fifteen and second-row offset fifteen. The host array and unpack state must describe the same padding convention.
Quick check
(Exact sources lie in , sample errors are at most , and a normalized nonnegative filter is followed by clamping to and ideal ten-bit nearest rounding. Bound the total error. Why would negative filter weights require another argument?)
Ten bits give spacings.
Solution · Answer
The bound is . With negative weights the error is bounded by , not necessarily ; normalization of the signed sum alone does not make that absolute sum one.
Quick check
(Premultiplied source color is with alpha , and opaque destination is . Compute over and final alpha. Which images must be distinct if the destination is a texture sampled by the next pass?)
Use source factor one and destination factor .
Solution · Answer
The RGB result is and alpha is . In the next pass the image being sampled must be distinct from the image simultaneously attached for writing in the simple ping-pong construction. Merely swapping variable names without changing actual attachments and unit bindings does not change the dataflow.