Concept Questions for HW03
Concept Questions for HW03
- (5 pts) In the OpenGL Shading Language (GLSL), what is a uniform variable? What is an "in" variable? What is an "out" variable? How does a vertex shader pass data to a fragment shader?
- (5 pts) MyGL contains two member variables that are std::unordered_maps. What do the GLuints that these maps store represent? How are they assigned values in the first place?
Question 1
uniform
Uniforms are constant across all instances of a shader program. It retains the same value across all processed vertices or fragments. Uniforms are typically used for constants that do not change during the execution of a draw call, such as transformation matrices, lighting parameters, or texture samplers.
"in" variable
An "in" variable in GLSL is an input to a shader stage. In a vertex shader, "in" variables typically represent vertex attributes (e.g., position, normal, texture coordinates). In a fragment shader, "in" variables represent the interpolated outputs from the vertex shader.
"out" variable
An "out" variable in GLSL is an output from a shader stage. In a vertex shader, "out" variables represent data that will be passed on to the next stage, which is typically the fragment shader. In a fragment shader, "out" variables represent the final color or other data to be written to the framebuffer.
pass data
A vertex shader passes data to a fragment shader by declaring out variables, which are then received as in variables in the fragment shader.
Question 2
represent
The GLuints in the two std::unordered_maps
represent the CPU-side handles for the "in" (attribute) and uniform variables defined in the shader program. Each key in the maps is the literal name of the variable as specified in the shader (e.g., vs_Pos
for attributes and u_ScreenDimensions
for uniforms), and each value is the handle (type GLint
) associated with that variable.
assigned values
These handles are assigned values by using the OpenGL functions glGetAttribLocation
and glGetUniformLocation
. When the getHandlesForShaderVariables
function is called, it activates the specified shader program and retrieves the location of each variable in the shader. The obtained handle IDs are then stored in shaderAttribVariableHandles
and shaderUniformVariableHandles
with their corresponding variable names as keys.