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

a design problem

Started by derek7 Apr 19, 2006 at 3:11 AM 1 replies 600+ views
Original Post
derek7
derek7
below is my Material class, but I found IDirect3DTexture9 * m_texture is actually unused . according to refactor it should be remove it out. but texture should be together with material. remove it or not? reason?


class Material
{
public:
    /** Constructor - use resource manager's create method rather than this.
       */
	Material();
    ~Material();
    Material& operator=( const Material& rhs );
  
	bool isTransparent(void) const;
 
    // -------------------------------------------------------------------------------
		  D3DCOLORVALUE & ambient();
	const D3DCOLORVALUE & diffuse();
	const D3DCOLORVALUE & specular();
    const D3DCOLORVALUE & emissive();
    void  power();

	void setAmbient(const D3DXCOLOR& ambient);
	void setDiffuse(const D3DXCOLOR& diffuse);
	void setSpecular(const D3DXCOLOR& specular);
    void setEmissive(const D3DXCOLOR& selfIllum);
	void addEmissive(const D3DXCOLOR& selfIllum);
	void addDiffuse(const D3DXCOLOR& diffuse);
	void addAmbient(const D3DXCOLOR& ambient);
	void setPower(float val);
	void addBright();
	void subBright();

	D3DMATERIAL9 &material9();
	void setMaterial9( D3DMATERIAL9* );

	IDirect3DTexture9 * texture() const;
	void setTexture(IDirect3DTexture9 * t);

	void setLightingEnabled(bool enabled);

protected:
	std::string				m_name;
	bool					m_transparent;
	bool					m_lightEnabled;

	D3DMATERIAL9			m_dxMaterial;
	IDirect3DTexture9		*m_texture;

	/** Internal method which sets the material up from the default settings.
	*/
	void init(void);

	/** Overridden from Resource.
	*/
};


Matsen
Matsen
If it is correct to say that Material has a texture, then texture should be owned by Material. But, having a class where a texture is rarely used makes using the Material class a bit cumbersome, as you have to check if a texture is available. My suggestion would be to either create a sub class of Material which always have a texture, as "Material" is a very abstract concept. If this do not fit your design, you could always create some sort of a null-texture, so that the rest of the design can assume a texture always being present.
Basiror
Basiror
In my engine I consider materials and textures as shaders

so I put them all together in a shader object.

Why? There s no need to make a difference between textures and shaders anymore since my engine will only use fixed function pipeline for very very basic things, the rest is completely shader driven.
http://www.8ung.at/basiror/theironcross.html

Topic Locked

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

Sign in to reply to this topic.