Skip to main content
GameDev.net gamedev.net
🔒 Locked

design - common interfaces

Started by brekehan Oct 7, 2008 at 12:15 AM 0 replies 350+ views
Original Post
brekehan
brekehan
I guess I should describe my current plana and then the problem I am having with it. I have no guidance and no resources to go by. I am getting confused everytime I sit down to work! This is DX10 in C++ btw. 1) I basically want to contain all my resources in a render queue So, my render queue will contain collections of cameras, light sets, shaders, materials, and meshes. 2) In the render queue, when it comes time to render: I iterate through my mesh collections query each mesh for the material and shader it is using by name I then go to my shader and material collections and get those So my render queue now has the current mesh, camera, light set, material and shader. 3) I query the mesh for its vertices and indices and give those along with the material, light set, and camera to the shader. The shader then syncs the material attributes to the HLSL variables, and renders. 4) Later my render queue may be renamed, and it could become some sort of scene hierarchy, sorting things when they need to be sorted, performing occlusion, space partitioning, and the like, but for now just simple queue with everything in it. -------------------------------- I was thinking that every shader has a specific material that it accepts parameters from. So, an my "emmisive shader" will only accept a "emmisive material", A "car metal" shader will only accept a "car metal" material. I do not see any common attributes or interfaces for materials. Every material is different. So, the problem is: If I am going to store a collection of materials, I need some Base Interface, so I can have some base class pointer. If I am going to store a collection of shaders, I also need some Base Interface, so I can have some base class pointer. Then, I can make a std::vector or linked list or map of the materials. I can do the same with the shaders. Right now, there is no inheritance for shaders or materials, I do not see anything in common from one to the other. All have differant attributes and methods with different parameters! So how then do I create the collection? ------------------------------------------------ I certainly do not want to hardcode a map for every type. I also want the flexibilty for the user to create thier own material and shaders. Any ideas? Should my shader class be responsible for doing the rendering or did I decide to put it in the wrong place? Does my design just suck? How do people do this? ------------------------------------------------ I am basically lost when trying to design the "what lives where" and "what is associated with what" I know every mesh (mesh subset later) is going to be associated with a material and a shader. I do now know how I am going to code that relationship.
freeworld
freeworld
try to think generically, then fine tune things.

you have main resources (you may have more) for example, Mesh, Material and Shader.

I'd create a structure/object that will hold all these, this will be you draw, ofcourse it will contain everything else about you how you wish this to be drawn. along with these resources I keep a dynamic array using a std::map to store various values that should be passed to the shader.

Further more I sort my draw calls into render_lists, that are determined by the call i.e. Draw_Something(render_list, ...);

These render list are thne processed seperately and are presented to they're defined render target, wether it be a temporary for post processing or the primary back buffer that will be presented to the screen after everything is processed.

Every resource is contained in its own manager, and though every shader may look different and every material may look different they are all the same at the bottom level.

I keep it so the renderer manages all the resource with the help of sub managers and the game code just makes use of the resources.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.