architecture - Proper way to manage shaders in OpenGL -


i'm writing code in c++ deal usual 3d stuff - models, materials, lights, etc. however, i'm finding work, needs know shader. eg, set uniform variables material, need know handles shader; load mesh memory, need know handles different in locations.

i've ended having models, materials, etc. each have handle shader can things gluniform1f(shader->getkdlocation(),kd), kind of hot potato seems bad design me. i've seen tutorials uniforms , ins , outs hardcoded in shader (eg layout = 0) , bound gluniform1f(0,kd),. however, means rest of code function specially laid out shaders , therefore seems suboptimal solution. also, don't think can subroutines, makes inconsistent option.

it seems choice between getting shader reference , in cases being unable instantiate without 1 (eg meshes) or hardcoding numbers in more places , having deal problems follow hardcoding.

i should able have these models, lights, etc. live/operate independently , "work" when set shader scene, can't seem find solid way this. bottom line question best practice handling shaders? i'm okay if doesn't solve problems, want know design decision(s) , why.

the problem engine architecture,or it's lack.in many game engines game objects divided several categories mesh object takes care of geometry (vertex buffers etc),material objects(responsible appearance of mesh object).in such design material entity contains info uniforms being passed shaders during rendering.such design allows amount of flexibility can reuse,reassign different materials between different renderable objects.so starter can set specific shader program specific material type each time mesh drawn, materials interacts shader program passing in needed uniforms.

i suggest take @ open source opengl engine idea how works.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -