What is the "OpenGL State Machine"? -
my brain tends favor structuring concepts in hierarchical, object-oriented, component-like ways. unfortunately, preventing me understanding opengl--and suspect source of confusion in misunderstanding of "opengl state machine" is. got graphics pipeline, specific individual program objects draw user's graphical components, right?
- what master state machine?
- is opengl api, or frame i'm trying draw, or user defines--like pipeline?
- what different states can exist in?
- is event-driven?
- what inputs affect different states machine can in?
- can hierarchical, oop concepts applied state machine?
this broad question, i'll give overview.
- what master state machine?
the state machine combination of complete opengl api , selected rendering context. rendering context contains of states makes state machine, while opengl api provides inputs change these states.
- what different states can exist in?
there many list. example, capabilities toggled glenable , gldisable (e.g. gl_texture_2d, gl_fog, gl_blend) part of state. name of current texture set glbindtexture; name of current shader program gluseprogram; contents of modelview , projection matrices plus state of glmatrixmode tells matrix glmultmatrix (etc.) calls affect; , on, part of state
- what inputs affect different states machine can in?
the initial state of machine given opengl specification, modulo gpu drivers. inputs can put machine different state calls opengl api.
- can hierarchical, oop concepts applied state machine?
this question vague. "hierarchical, oop concepts"?
it's possible take object-oriented approach wrapping opengl api. can create "texture" object class allocates texture name using glgentextures when initialized, , provides methods uploading texture image or changing texture parameters call glbindtexture before calling relevant apis methods. approach tricky still have keep track of current state through object , sub-object method calls.
opengl provides several "stacks" (vis. glpushmatrix, glpushattrib) meant manage hierarchies of objects. pushing part of current state onto stack, calling methods of child object, , popping state off of stack, can restore state 1 expected parent object.
the general object-oriented approach using opengl api through scenegraph - directed, acyclic graph of objects, each object represents change state machine's state. object pushes 1 or more opengl stacks, applies state using opengl api calls, calls methods of child objects, , pops off of opengl stacks restore previous state.
Comments
Post a Comment