Jump to content
  • Advertisement
Sign in to follow this  
derek7

a design problem

This topic is 4504 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

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.
	*/
};


Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!