• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
davepl1968

Loading model meshes into device vertex buffers

6 posts in this topic

It seems that every sample I've come across so far simply loads models with Content.Load<Model>(etc).

 

Then, when its time to draw them (in the XNA case) you wind up looping through the model.Meshes and drawing them.  This can't be very fast if its has to push all the vertex data of the model back to the card (or graphics device, whatever) each time.

 

So, I presumed that the right thing to do (especially if you have a model that's reused a lot) would be to load each of the meshes into a vertex buffer, keep track of the index, all of that.  Then, when you draw, you could use your card's vertex buffer DrawIndexedPrimitive() instead of mesh.Draw(), and it would use the vertexes already loaded into the card-controlled memory.

 

My questions are

(a) is this happening behind the scenes with Load<Model> and mesh.Draw() and I just don't realize it?

(b) if not, does anyone have an example they could point me at that does it "right" that I can learn from?

 

Thanks!

Dave

Edited by davepl1968
0

Share this post


Link to post
Share on other sites

The Model vertex data is loaded into vertex buffers when the model is loaded by the ContentManager. You can actually access these vertex buffers using the VertexBuffer property of ModelMeshPart.

2

Share this post


Link to post
Share on other sites

But aren't those in the user space, and would be drawn with DrawUserPrimitive (etc) as opposed to in card memory so they could be drawn with the DrawPrimitive (etc) calls?

0

Share this post


Link to post
Share on other sites

No. DrawUserPrimitive only works with arrays of vertex data, not with vertex buffers.

0

Share this post


Link to post
Share on other sites

Thanks.  So just to be clear, when I call mesh.Draw() it's using a vertex buffer on the graphics card that was loaded back when I loaded the model, is that right?

 

My vocabulary might be wrong, so by "vertex buffer" I mean memory actually on the GPU die without having to go through northbridge/southbridge/whatever.

 

And some magical force takes care of allocating and managing the memory of the vertex buffer?  I notice that Model and ModelMesh don't implement IDisposable, so I'm curious as to when and how it would know to free up the vertex buffer. 

0

Share this post


Link to post
Share on other sites
Yes. mesh.Draw is essentially just calling DrawIndexedPrimitives under the covers. As MJP mentioned, the vertex and index buffers are accessible as properties on the ModelMesh/ModelMeshPart if you want to draw the mesh with DrawIndexedPrimitives directly.

And some magical force takes care of allocating and managing the memory of the vertex buffer?  I notice that Model and ModelMesh don't implement IDisposable, so I'm curious as to when and how it would know to free up the vertex buffer.

Yeah, that's kind of weird they don't implement IDisposable. I'm guessing that ContentManager must keep track of the vertex and index buffers that were created when the Model was loaded. So they would be freed when ContentManager is Disposed, just like the other resources.
1

Share this post


Link to post
Share on other sites

The "magical force" you speak of is the content pipeline. The content processor for models understands the concept of vertex and index buffers, so the model processor is able to take the vertex/index data and create vertex buffer and index buffer assets. Then when you load the model at runtime, the model automatically loads its vertex and index buffer assets. These assets create vertex buffers and index buffers on the GPU, and fill them with the data that was created in the content pipeline. A similar process happens with textures.

The way that content loaded from the content pipeline works is that you don't dispose of individual assets. Instead, the ContentManager that you used to load them is considered to have ownership of all assets that it loaded. To dispose of assets loaded with the stock ContentManager, you would call Unload or Dispose on the ContentManager itself. If you needed to dispose of individual assets, I think it should be possible if your derive from ContentManager to make a custom class.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0