Jump to content
  • Advertisement
Sign in to follow this  

Managed dx9 engine design

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In unmanaged code you'd write your TexturePools and such for your media to remove data duplication. Is anything of the sort already implemented in managed code, or will i still have to write those? (c# dx9) Are there any other design things i should keep in mind when writing an engine under C# dx9 or should i just stick with the same design as with c++ dx9?

Share this post


Link to post
Share on other sites
Advertisement
Yea, you have to check it yourself. Managed DirectX is basically DirectX wrapped into DirectX, everything you can do in DX you can do in MDX and vice versa.

Share this post


Link to post
Share on other sites
x_o You don't have to tell me stuff i already know, i'm just asking as to how would i have to rethink an engine design when it comes to texture management, mesh management etc... and if mdx has any pool design already made. I found an object called Resource though and meshes seem to have meshmanagers etc.

I was just curious if the Texture object had builtin reference counting or such so i wouldn't have to worry about loading the same texture twice, hence not needing to write a TexturePool class.

I just need to know as to how far Tom Miller and his crew took the "management" part of C# dx9 concerning resource/memory management.

For example, if i had 100 models that needed to be loaded. All of these models share textures here and there and by just loading them in following the guidlines i'd have loaded 99 copies of the same blody texture if atleast one subset of each model shared the same texture. That's not acceptable, everyone knows that, that's why you write TexturePools and such. That's why i'm asking if those type of obvious things were made for the MDX to cut back on development time.

If i were to load a Texture a; and then pass Texture b = a; If i dispose/cleaned up b would a's data still be there? Will b reference a or make a copy of all the data?

[Edited by - Cybrosys on March 2, 2005 8:49:42 AM]

Share this post


Link to post
Share on other sites
Try this,


using System;
using System.IO;
using System.Collections;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Tankers
{
/// <summary>
/// The texture pool class
/// </summary>
class TexturePool
{
// Constant texture path
private const string TexturePath = "Textures\\";
// The hash table of valid textures
private static Hashtable textureTable = new Hashtable();

/// <summary>
/// Create a new texture, or return one from the pool
/// </summary>
/// <param name="file">Texture file to create</param>
/// <returns>A texture</returns>
public static Texture CreateTexture(Device renderDevice, string file)
{
// Make sure a texture was passed in
if ((file == null) || (file.Length == 0))
{
// No texutre
return null;
}

// Before we create a texture, return one from the
// pool if it exists
string lowerCaseFile = file.ToLower();
if (textureTable.ContainsKey(lowerCaseFile))
{
return textureTable[lowerCaseFile] as Texture;
}

// We've made it here, this is a new texture, Create the texture and add it to the pool
Texture t = TextureLoader.FromFile(renderDevice, GameEngine.MediaPath + TexturePath + file);

System.Diagnostics.Debug.Assert(t != null, "Created Texture is null",
"Textures being loaded by the pool should never be null");

// Add it to the pool
textureTable.Add(lowerCaseFile, t);

return t;
}


/// <summary>
/// Release all textures that have been created thus far
/// </summary>
public static void ReleaseAllTextures()
{
foreach(string s in textureTable.Keys)
{
// Simply dispose of each texture in the list
(textureTable[s] as Texture).Dispose();
}

// Clear the texture list
textureTable.Clear();
}

}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!