Reusing Textures

Started by
-1 comments, last by somedxquestions 15 years, 1 month ago
hello all am here looking for some suggestions on how to design a texture handling class for directx8 (yes i know, outdated.. but upgrading is not an option for this project) a friend and i are working on a set of classes for drawing text and are working on optimizing the overall engine to avoid recreating new textures for every single object as well as recreating new vertexbuffers for each object. instead, we are trying to design the entire overall engine to only require two vertexbuffers and only as many textures as needed for unique font objects currently we are using a redesigned version of the cd3dfont class that comes with the directx sdk. the class is created to extend the objects to be able to do various other things such as inline coloring, as well as having background primitives to give the objects a background to render onto. (thus the need for the 2nd vertex buffer) the current font object by itself recreated creates massive lag when there are lots of objects being drawn, a performance loss is noticeable with about 25 objects rendering at once. we are trying to redesign the overall font object to become more of a font engine to allow reusing of textures for fonts that are the same for multiple objects to avoid creating unneeded textures. we are also moving into using two vertex buffers for the whole engine (for the fonts) instead of 2 per object to limit the amount of lock/unlock calls that get made. each design we have drawn out, however, loops back into each class and then lands up proving to get stuck in various iterations and we cant seem to find a structure for the classes that we feel comfortable with. we are looking to reduce the lag and issues seen with using single objects vs. using a handler engine for the font objects. any tips on how things should/could be setup would be great :) a basic overview of our last implementation, am sorry its not the full code but its no where near done and we decided to ask for suggestions because we already saw a lot of flaws in this setup as well.
namespace std {
	typedef basic_string< TCHAR > tstring;
}

typedef struct _TEXTURE_ENTRY {
	std::tstring 	Name;
	CTexture*		Texture;
	DWORD			Width;
	DWORD			Height;
	DWORD			Quality;
	float			Scale;
	float			Coords[96][4];
} TEXTURE_ENTRY, *LPTEXTURE_ENTRY;

//
// .. CTexture Overview
//
class CTexture {
public:
	CTexture( LPDIRECT3DTEXTURE8 pTexture );
	~CTexture( void );
	
	// .. property handlers
	
private:
	IDirect3DTexture8* m_pTexture;
};

//
// .. CTextureFactory Overview
//
class CTextureFactory {
	CTextureFactory( LPDIRECT3DDEVICE8 lpDevice );
	~CTextureFactory( void );
	
	// .. property handlers
	
private:
	IDirect3DDevice8* 		m_Direct3DDevice;
	std::list< TEXTURE_ENTRY* > 	m_Textures;
};

//
// .. CTextRender Overview
//
class CTextRender {
public:
	CTextRender( LPDIRECT3DDEVICE8 lpDevice );
	~CTextRender();
	
	// .. property handlers
	// .. batch drawing handlers
	
private:
	IDirect3DDevice8* 	m_Direct3DDevice;
	CVertexBuffer*		m_FontVertex;
	CVertexBuffer*		m_PrimVertex;
};

//
// .. CTextObject Overview
//
class CTextObject {
public:
	CTextObject( const std::tstring tszName );
	~CTextObject();
	
	// .. property handlers
	
private:
	std::tstring m_strName;
};

//
// .. CTextObjectHandler Overview
//
class CTextObjectHandler {
public:
	CTextObjectHandler( LPDIRECT3DDEVICE8 lpDevice );
	~CTextObjectHandler();
	
	// .. property handlers
	
private:
	IDirect3DDevice8* m_Direct3DDevice;
	
	std::auto_ptr< CTextureFactory > 	m_TextureFactory;
	std::auto_ptr< CTextRender > 		m_TextRender;
	std::list< CTextObject* >		m_TextObjects;
};

This topic is closed to new replies.

Advertisement