OpenGL OpenGL MCQ 4 — Questions and Answers
Question 1: Which OpenGL feature allows drawing multiple instances of a mesh with a single draw call?
- Geometry shaders
- Instanced rendering via glDrawArraysInstanced() (Correct answer)
- Multi-draw indirect
- Transform feedback
Correct answer: Instanced rendering via glDrawArraysInstanced()
glDrawArraysInstanced() submits the geometry once and renders it a specified number of times, with gl_InstanceID available in the vertex shader to differentiate instances.
Question 2: What is the purpose of mipmaps in OpenGL texturing?
- Increase texture resolution at close range
- Provide pre-filtered smaller texture versions to reduce aliasing at distance (Correct answer)
- Enable multi-layer texture blending
- Store normal map data alongside color data
Correct answer: Provide pre-filtered smaller texture versions to reduce aliasing at distance
Mipmaps are pre-computed downscaled versions of a texture used when the textured surface is small on screen, reducing aliasing and improving performance.
Question 3: In GLSL, what does the 'varying' keyword (or 'in/out' in modern GLSL) represent?
- A compile-time constant
- Data interpolated across a primitive from vertex shader to fragment shader (Correct answer)
- A texture sampling function
- A uniform buffer block member
Correct answer: Data interpolated across a primitive from vertex shader to fragment shader
Varying variables carry per-vertex data (like color or texture coordinates) that are automatically interpolated by the rasterizer before reaching fragment shaders.
Question 4: Which OpenGL query object type measures how long a GPU operation takes?
- GL_SAMPLES_PASSED
- GL_TIME_ELAPSED (Correct answer)
- GL_PRIMITIVES_GENERATED
- GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
Correct answer: GL_TIME_ELAPSED
GL_TIME_ELAPSED query objects measure the number of nanoseconds elapsed on the GPU between glBeginQuery() and glEndQuery() calls.
Question 5: What does enabling GL_SCISSOR_TEST do in OpenGL?
- Clips primitives to the view frustum
- Restricts rendering to a rectangular region of the framebuffer (Correct answer)
- Enables stencil masking
- Activates depth clamping
Correct answer: Restricts rendering to a rectangular region of the framebuffer
The scissor test discards fragments outside the scissor rectangle defined by glScissor(), useful for UI clipping or partial screen updates.
Question 6: Which texture format stores only a single channel of floating-point data in OpenGL?
- GL_RGB32F
- GL_R32F (Correct answer)
- GL_LUMINANCE
- GL_DEPTH_COMPONENT
Correct answer: GL_R32F
GL_R32F is a single-channel 32-bit floating-point internal texture format, useful for heightmaps, AO maps, or any scalar data.
Question 7: What is the purpose of the stencil buffer in OpenGL?
- Stores per-pixel depth values for hidden surface removal
- Provides an arbitrary per-fragment mask for effects like outlines and shadows (Correct answer)
- Holds the accumulated color during multi-pass rendering
- Caches geometry for instanced rendering
Correct answer: Provides an arbitrary per-fragment mask for effects like outlines and shadows
The stencil buffer stores per-pixel integer values that can be used to mask rendering regions, enabling effects like reflections, outlines, and portals.
Which OpenGL feature allows drawing multiple instances of a mesh with a single draw call?