Proper asset management?

Wunkolo
  • Proper asset management? Wunkolo

    I am unable to wrap my mind around designing a good way to manage resources in my game. For instance, a vertex buffer in DirectX or OpenGL would lead me to believe I should have one central buffer in which I would adapt to my game. But how would I efficiently manage this? If I had 2 game objects which used the same model but with different properties such as color or position, I would I assume reading from the same section of memory for geometry and having them each passing there own properties to the vertex/pixel shader. But what boggles me is having them read from the same section of the vertex buffer and having the vertex buffer manage the streaming of new data.

    Textures and sound surface the same problem to me.

  • You need some raw data models. For example let's consider that you've made a model in blender of a sphere, let's call this sphere_model.

    On of your game classes is represented by a brown coloured sphere, the other one is represented by a blue sphere.

    You first initialize the brown sphere, the asset manager checks it's cache and sees that the sphere_model hasn't been loaded yet, it loads it for you and returns a pointer to a model primitive to the brown sphere.

    The primitive type has a vertex buffer assoctiated and should have some methods to make it actual.

    You then initialize the blue sphere, the asset manager sees that the sphere_model has already been loaded and directy returns a pointer to the model primitive.

    When drawing the brown sphere, you do something like SetVertexBuffer(my_model_primitive); after that you set the shader options (like colour = brown).

    When drawing the blue sphere you do again SetVertexBuffer(my_model_primitive) which sets the same vertex buffer, however by setting different shader options, (like colour, texture, WorldMatrix, etc..) the sphere will look different.

    In general proper asset management will need to statisfy the following:

    • Content primitives are only loaded once (model files, texture files, sound files)
    • Content primitives are mapped to a primitive class, like model_primitive, texture2d, soundEffect, etc...)
    • Primitive classes only retain the raw data, and methods to do something with this data, like actualizing the vertex buffer, but don't contain state.
    • Higher level classes contain the state and use the primitive classes. They can contain (visual) state like scale, tinting, etc..

    I hope this makes a bit of sense, feel free to ask more questions!

  • You store per-instance data in a vertex buffer too. You read from one section of GPU memory for the per-model data like the vertices and stuff, and then you read from a different section of GPU memory to determine the per-instance data.

    The general rule is, you should only be sending commands to the GPU, not data- except when your data changes, of course.

Tags
opengl c++ directx management asset-management
Related questions and answers
  • being accessed by game entities and other objects, and must allow (somewhat)easy optimization for them if needed. Anything that helps me make a decision is a good answer for my question, thanks...well... I'm building the animation system of my game engine (the skeletal and skinned animation stuff), and I came to a point where I added so much functionality in the frame and node structures... would end up with complex properties such as the ability of having a node hierarchy and transformation frames, animation type checks, and also require a lot of unnecessary creation parameters

  • in the first check. But then it gets a bit fuzzy simply because of a lack of understanding. Should I add them together to create a bigger buffer description and copy everything together? Or should I do it all separately? Basically how would I extend this code to include more vectors of vertices? if (temporary2DVerts.size() > 0) { // create the vertex buffer and store the pointer into pBuffer, which is created globally D3D10_BUFFER_DESC bd; bd.Usage = D3D10_USAGE_DYNAMIC; bd.ByteWidth = sizeof(VERTEX) * temporary2DVerts.size();// this breaks the create buffer line

  • in the shader code) for( int n = 0; n < vShaderArgs.size(); n ++) glBindAttribLocation( m_nProgramId, n, vShaderArgs[n].sFieldName.c_str() ); // Create and bind to a vertex array object, which... into a shader program, for use with glDrawArrays. My vertex data already exists in a VertexBufferObject that uses the following data structure to create a vertex buffer: class CustomVertex { public...]; // nx, ny, nz; float colour[4]; // r, g, b, a float padding[20]; // padded for performance }; I've already written a working VertexBufferObject class that creates a vertex buffer

  • Posted this question on SO but got no answers. Maybe somebody can help me here. I recently had a well-working program which streamed WAV and Ogg sounds with OpenAL. I then decided to abstract the source and buffer objects into C++ classes. I got as far as the source class. My function which returns the number of processed buffers is not altering the integer passed to alGetSourcei. int ALSource... this be expected behaviour? The OpenAL specification states that the value should be from 0 - any but is not really any more specific than that. The programmers' guide is the same.

  • ) Where should I place the messaging system for my game engine? Lua? C++? I'm tempted to just have C++ object to behave as servers, offering services to lua business logic. Things like physics system... them in lua. Now I have clear I'm going to write them in C++ and expose everything needed. Ussually only interfaces are exposed to lua, so I have come across that to export properties to be published... instantiate them. All this, is what I can think of now. I know my editor can still be using game objects even if it is external, but the game am I into is for iphone using cocos2d and the editor

  • Like many beginner graphics programmers I followed a tutorial which showed me how to set up buffer descriptions and fill out the vertex buffer etc... - the steps involved in drawing a simple indexed... the vertex buffer and only one object is drawn - the last one. So what are the options for drawing many of these cubes? Cube::Cube(D3DXCOLOR colour, D3DXVECTOR3 min, D3DXVECTOR3 max) { // create eight...}, }; // create the vertex buffer D3D10_BUFFER_DESC bd; bd.Usage = D3D10_USAGE_DYNAMIC; bd.ByteWidth = sizeof(VERTEX) * 8; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE

  • I'm using FMOD (with C++ syntax, not C) and I'm having trouble getting the wave data of a whole sound file. Channel::GetWave() only gets the wave data of the area on which it is currently playing... hasn't wrapped at the end of the buffer. But as I said, my goal is to be able to get the wave data of the beginning of a song to the end. ..., and could return the same data if it is called very quickly in succession. See the DSP API to capture a continual stream of wave data as it plays, or see Sound::lock / Sound::unlock if you want

  • After careful consideration to use middleware, I have decided on creating my own 3d file format format to export meshes from 3D authoring application (Softimage) into my game. I will need to export... on exporting animation information, especially when the mesh changes its geometry? I would be thankful for advices that could point me into right direction. It would be nice to save some time instead of wasting it on incorrect approaches. I use Softimage as my 3D authoring tool. Target platform is OpenGL ES 2.0 running on mobile devices (iOS, Android). Programming language: C++.

  • type we are using device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // select which vertex buffer and index buffer to display UINT stride = sizeof(VERTEX...Basically when placed in the same file this works fine, but if placed in separate files (and I have tested this) just after Init() is called, the pointer to ID3D10* device's value is suddenly...(); // close and release the vertex buffer pVertexLayout->Release(); // close and release the input layout object swapchain->Release(); // close and release the swap chain rtv->Release

Data information