Przeglądaj źródła

Rework MaterialResource a bit

Daniele Bartolini 12 lat temu
rodzic
commit
c59bc3bd24
2 zmienionych plików z 78 dodań i 722 usunięć
  1. 19 434
      src/MaterialResource.cpp
  2. 59 288
      src/MaterialResource.h

+ 19 - 434
src/MaterialResource.cpp

@@ -29,451 +29,36 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-MaterialResource::MaterialResource() :
-	mAmbient(0.5f, 0.5f, 0.5f, 1.0f),
-	mDiffuse(0.5f, 0.5f, 0.5f, 1.0f),
-	mSpecular(0.5f, 0.5f, 0.5f, 1.0f),
-	mEmission(0.0f, 0.0f, 0.0f, 1.0f),
-	mShininess(0),
-	mLighting(true),
-	mTexturing(false),
-	mBackfaceCulling(true),
-	mSeparateSpecularColor(true),
-	mDepthTest(true),
-	mDepthWrite(true),
-	mRescaleNormals(false),
-	mBlending(false),
-	mColorWrite(true),
-	mFog(false),
-	mAlphaTest(false),
-	mPointSprite(false),
-	mShadingType(ST_SMOOTH),
-	mPolygonMode(PM_FILL),
-	mFrontFace(FF_CCW),
-	mDepthFunc(CF_LEQUAL),
-	mFogMode(FM_LINEAR),
-	mFogDensity(1.0f),
-	mFogStart(0.0f),
-	mFogEnd(1.0f),
-	mFogColor(0.0f, 0.0f, 0.0f, 0.0f),
-	mAlphaFunc(CF_ALWAYS),
-	mAlphaRef(0.0f),
-	mPointSize(1.0f),
-	mPointSizeMin(0.0f),
-	mPointSizeMax(1.0f),
-	mBlendEquation(BE_FUNC_ADD),
-	mBlendSrc(BF_SRC_ALPHA),
-	mBlendDst(BF_ONE_MINUS_SRC_ALPHA),
-	mBlendColor(0.0f, 0.0f, 0.0f, 0.0f)
+//-----------------------------------------------------------------------------
+MaterialResource* MaterialResource::load(Allocator& allocator, ResourceArchive* archive, ResourceId id)
 {
-//	for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
-//	{
-//		mTextureLayer[i] = 0;
-//	}
-}
-
-MaterialResource::~MaterialResource()
-{
-}
-
-const Color4& MaterialResource::GetAmbient() const
-{
-	return mAmbient;
-}
-
-void MaterialResource::SetAmbient(const Color4& ambient)
-{
-	mAmbient = ambient;
-}
-
-const Color4& MaterialResource::GetDiffuse() const
-{
-	return mDiffuse;
-}
-
-void MaterialResource::SetDiffuse(const Color4& diffuse)
-{
-	mDiffuse = diffuse;
-}
-
-const Color4& MaterialResource::GetSpecular() const
-{
-	return mSpecular;
-}
-
-void MaterialResource::SetSpecular(const Color4& specular)
-{
-	mSpecular = specular;
-}
-
-const Color4& MaterialResource::GetEmission() const
-{
-	return mEmission;
-}
-
-void MaterialResource::SetEmission(const Color4& emission)
-{
-	mEmission = emission;
-}
-
-int32_t MaterialResource::GetShininess() const
-{
-	return mShininess;
-}
-
-void MaterialResource::SetShininess(int32_t shininess)
-{
-	mShininess = shininess;
-}
-
-bool MaterialResource::GetLighting() const
-{
-	return mLighting;
-}
-
-void MaterialResource::SetLighting(bool lighting)
-{
-	mLighting = lighting;
-}
-
-bool MaterialResource::GetTexturing() const
-{
-	return mTexturing;
-}
-
-void MaterialResource::SetTexturing(bool texturing)
-{
-	mTexturing = texturing;
-}
-
-bool MaterialResource::GetBackfaceCulling() const
-{
-	return mBackfaceCulling;
-}
-
-void MaterialResource::SetBackfaceCulling(bool culling)
-{
-	mBackfaceCulling = culling;
-}
-
-bool MaterialResource::GetSeparateSpecularColor() const
-{
-	return mSeparateSpecularColor;
-}
-
-void MaterialResource::SetSeparateSpecularColor(bool separate)
-{
-	mSeparateSpecularColor = separate;
-}
-
-bool MaterialResource::GetDepthTest() const
-{
-	return mDepthTest;
-}
-
-void MaterialResource::SetDepthTest(bool test)
-{
-	mDepthTest = test;
-}
-
-bool MaterialResource::GetDepthWrite() const
-{
-	return mDepthWrite;
-}
-
-void MaterialResource::SetDepthWrite(bool write)
-{
-	mDepthWrite = write;
-}
-
-bool MaterialResource::GetRescaleNormals() const
-{
-	return mRescaleNormals;
-}
-
-void MaterialResource::SetRescaleNormals(bool rescale)
-{
-	mRescaleNormals = rescale;
-}
-
-bool MaterialResource::GetBlending() const
-{
-	return mBlending;
-}
-
-void MaterialResource::SetBlending(bool blending)
-{
-	mBlending = blending;
-}
-
-bool MaterialResource::GetColorWrite() const
-{
-	return mColorWrite;
-}
-
-void MaterialResource::SetColorWrite(bool write)
-{
-	mColorWrite = write;
-}
-
-bool MaterialResource::GetFog() const
-{
-	return mFog;
-}
-
-void MaterialResource::SetFog(bool fog)
-{
-	mFog = fog;
-}
-
-bool MaterialResource::GetAlphaTest() const
-{
-	return mAlphaTest;
-}
-
-void MaterialResource::SetAlphaTest(bool test)
-{
-	mAlphaTest = test;
-}
-
-bool MaterialResource::GetPointSprite() const
-{
-	return mPointSprite;
-}
-
-void MaterialResource::SetPointSprite(bool sprite)
-{
-	mPointSprite = sprite;
-}
-
-ShadingType MaterialResource::GetShadingType() const
-{
-	return mShadingType;
-}
-
-void MaterialResource::SetShadingType(ShadingType type)
-{
-	mShadingType = type;
-}
-
-PolygonMode MaterialResource::GetPolygonMode() const
-{
-	return mPolygonMode;
-}
-
-void MaterialResource::SetPolygonMode(PolygonMode mode)
-{
-	mPolygonMode = mode;
-}
-
-FrontFace MaterialResource::GetFrontFace() const
-{
-	return mFrontFace;
-}
-
-void MaterialResource::SetFrontFace(FrontFace front)
-{
-	mFrontFace = front;
-}
-
-CompareFunction MaterialResource::GetDepthFunc() const
-{
-	return mDepthFunc;
-}
-
-void MaterialResource::SetDepthFunc(CompareFunction func)
-{
-	mDepthFunc = func;
-}
-
-FogMode MaterialResource::GetFogMode() const
-{
-	return mFogMode;
-}
-
-void MaterialResource::SetFogMode(FogMode mode)
-{
-	mFogMode = mode;
-}
-
-float MaterialResource::GetFogDensity() const
-{
-	return mFogDensity;
-}
-
-void MaterialResource::SetFogDensity(float density)
-{
-	mFogDensity = density;
-}
-
-float MaterialResource::GetFogStart() const
-{
-	return mFogStart;
-}
-
-void MaterialResource::SetFogStart(float start)
-{
-	mFogStart = start;
-}
-
-float MaterialResource::GetFogEnd() const
-{
-	return mFogEnd;
-}
-
-void MaterialResource::SetFogEnd(float end)
-{
-	mFogEnd = end;
-}
-
-const Color4& MaterialResource::GetFogColor() const
-{
-	return mFogColor;
-}
-
-void MaterialResource::SetFogColor(const Color4& color)
-{
-	mFogColor = color;
-}
-
-CompareFunction MaterialResource::GetAlphaFunc() const
-{
-	return mAlphaFunc;
-}
-
-void MaterialResource::SetAlphaFunction(CompareFunction func)
-{
-	mAlphaFunc = func;
-}
-
-float MaterialResource::GetAlphaRef() const
-{
-	return mAlphaRef;
-}
-
-void MaterialResource::SetAlphaRef(float ref)
-{
-	mAlphaRef = ref;
-}
-
-float MaterialResource::GetPointSize() const
-{
-	return mPointSize;
-}
-
-void MaterialResource::SetPointSize(float size)
-{
-	mPointSize = size;
-}
-
-float MaterialResource::GetPointSizeMin() const
-{
-	return mPointSizeMin;
-}
-
-void MaterialResource::SetPointSizeMin(float min)
-{
-	mPointSizeMin = min;
-}
-
-float MaterialResource::GetPointSizeMax() const
-{
-	return mPointSizeMax;
-}
+	(void)allocator;
+	(void)archive;
+	(void)id;
+	// TODO
 
-void MaterialResource::SetPointSizeMax(float max)
-{
-	mPointSizeMax = max;
+	return NULL;
 }
 
-BlendFunction MaterialResource::GetSrcBlendFunc() const
+//-----------------------------------------------------------------------------
+void MaterialResource::online(MaterialResource* material)
 {
-	return mBlendSrc;
+	(void)material;
+	// TODO
 }
 
-void MaterialResource::SetSrcBlendFunc(BlendFunction src)
+//-----------------------------------------------------------------------------
+void MaterialResource::unload(Allocator& allocator, MaterialResource* material)
 {
-	mBlendSrc = src;
+	(void)allocator;
+	(void)material;
+	// TODO
 }
 
-BlendFunction MaterialResource::GetDstBlendFunc() const
+//-----------------------------------------------------------------------------
+void MaterialResource::offline()
 {
-	return mBlendDst;
-}
-
-void MaterialResource::SetDstBlendFunc(BlendFunction dst)
-{
-	mBlendDst = dst;
-}
-
-void MaterialResource::SetBlendFunc(BlendFunction src, BlendFunction dst)
-{
-	mBlendSrc = src;
-	mBlendDst = dst;
-}
-
-Color4& MaterialResource::GetBlendColor()
-{
-	return mBlendColor;
-}
-
-void MaterialResource::SetBlendColor(const Color4& color)
-{
-	mBlendColor = color;
-}
-
-bool MaterialResource::SetTextureLayer(uint32_t layer, ResourceId texture)
-{
-	if (layer >= MAX_TEXTURE_LAYERS)
-	{
-		return false;
-	}
-
-	mTextureLayer[layer] = texture;
-	return true;
-}
-
-ResourceId MaterialResource::GetTextureLayer(uint32_t layer) const
-{
-//	if (layer >= MAX_TEXTURE_LAYERS)
-//	{
-//		return 0;
-//	}
-
-	return mTextureLayer[layer];
-}
-
-void MaterialResource::SetTextureMode(TextureMode mode)
-{
-//	for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
-//	{
-//		if (mTextureLayer[i] == 0)
-//			continue;
-
-//		mTextureLayer[i]->SetMode(mode);
-//	}
-}
-
-void MaterialResource::SetTextureFilter(TextureFilter filter)
-{
-//	for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
-//	{
-//		if (mTextureLayer[i] == 0)
-//			continue;
-
-//		mTextureLayer[i]->SetFilter(filter);
-//	}
-}
-
-void MaterialResource::SetTextureWrap(TextureWrap wrap)
-{
-//	for (uint32_t i = 0; i < MAX_TEXTURE_LAYERS; i++)
-//	{
-//		if (mTextureLayer[i] == 0)
-//			continue;
-
-//		mTextureLayer[i]->SetWrap(wrap);
-//	}
+	// TODO
 }
 
 } // namespace crown

+ 59 - 288
src/MaterialResource.h

@@ -36,302 +36,73 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-//! Max texture layers supported by the material.
-//! Note that the maximum number of usable layers
-//! depends on the graphic card.
+/// Max texture layers supported by the material.
+/// @note The maximum number of usable layers depends on the graphic card/Renderer config.
 const uint32_t MAX_TEXTURE_LAYERS = 8;
 
+class ResourceArchive;
+class Allocator;
+
+/// A material describes the visual properties of a surface.
+/// It is primarly intended for rendering purposes but can
+/// also be used to drive other types of systems such as sounds or physics.
 class MaterialResource
 {
-
 public:
 
-	//! Constructor
-	MaterialResource();
-
-	//! Destructor
-	~MaterialResource();
-
-	//! Returns the ambient reflectance
-	const Color4& GetAmbient() const;
-
-	//! Sets the ambient reflectance
-	void SetAmbient(const Color4& ambient);
-
-	//! Returns the diffuse reflectance
-	const Color4& GetDiffuse() const;
-
-	//! Sets the diffuse reflectance
-	void SetDiffuse(const Color4& diffuse);
-
-	//! Returns the specular reflectance
-	const Color4& GetSpecular() const;
-
-	//! Sets the specular reflectance
-	void SetSpecular(const Color4& specular);
-
-	//! Returns the emitted light int32_tensity
-	const Color4& GetEmission() const;
-
-	//! Sets the emitted light int32_tensity
-	void SetEmission(const Color4& emission);
-
-	//! Returns the shininess
-	int32_t GetShininess() const;
-
-	//! Sets the shininess
-	void SetShininess(int32_t shininess);
-
-	//! Returns whether lighting is enabled
-	bool GetLighting() const;
-
-	//! Sets whether lighting is enabled
-	void SetLighting(bool lighting);
-
-	//! Returns whether texturing is enabled
-	bool GetTexturing() const;
-
-	//! Sets whether texturing is enabled
-	void SetTexturing(bool texturing);
-
-	//! Returns whether backface culling is enabled
-	bool GetBackfaceCulling() const;
-
-	//! Sets whether backface culling is enabled
-	void SetBackfaceCulling(bool culling);
-
-	//! Returns whether separate specular color is enabled
-	bool GetSeparateSpecularColor() const;
-
-	//! Sets whether separate specular color is enabled
-	void SetSeparateSpecularColor(bool separate);
-
-	//! Returns whether depth test is enabled
-	bool GetDepthTest() const;
-
-	//! Sets whether depth test is enabled
-	void SetDepthTest(bool test);
-
-	//! Returns whether depth writing is enabled
-	bool GetDepthWrite() const;
-
-	//! Returns whether depth writing is enabled
-	void SetDepthWrite(bool write);
-
-	//! Returns whether auto normal rescaling is enabled
-	bool GetRescaleNormals() const;
-
-	//! Sets whether auto normal rescaling is enabled
-	void SetRescaleNormals(bool rescale);
-
-	//! Returns whether blending is enabled
-	bool GetBlending() const;
-
-	//! Sets whether blending is enabled
-	void SetBlending(bool blending);
-
-	//! Returns whether writing int32_to the color buffer is enabled
-	bool GetColorWrite() const;
-
-	//! Sets whether writing int32_to the color buffer is enabled
-	void SetColorWrite(bool write);
-
-	//! Returns whether fog is enabled
-	bool GetFog() const;
-
-	//! Sets whether fog is enabled
-	void SetFog(bool fog);
-
-	//! Returns whether alpha test is enabled
-	bool GetAlphaTest() const;
-
-	//! Sets whether alpha test is enabled
-	void SetAlphaTest(bool test);
-
-	//! Returns whether point32_t sprite is enabled
-	bool GetPointSprite() const;
-
-	//! Sets whether point32_t sprite is enabled
-	void SetPointSprite(bool sprite);
-
-	//! Returns the shading type
-	ShadingType GetShadingType() const;
-
-	//! Sets the shading type
-	void SetShadingType(ShadingType type);
-
-	//! Returns the polygon mode
-	PolygonMode GetPolygonMode() const;
-
-	//! Sets the polygon mode
-	void SetPolygonMode(PolygonMode mode);
-
-	//! Returns the front face
-	FrontFace GetFrontFace() const;
-
-	//! Sets the front face
-	void SetFrontFace(FrontFace front);
-
-	//! Returns the depth function
-	CompareFunction GetDepthFunc() const;
-
-	//! Sets the depth function
-	void SetDepthFunc(CompareFunction func);
-
-	//! Returns the fog mode
-	FogMode GetFogMode() const;
-
-	//! Sets the fog mode
-	void SetFogMode(FogMode mode);
-
-	//! Returns the fog density
-	float GetFogDensity() const;
-
-	//! Sets the fog density
-	void SetFogDensity(float density);
-
-	//! Returns the fog start
-	float GetFogStart() const;
-
-	//! Sets the fog start
-	void SetFogStart(float start);
-
-	//! Returns the fog end
-	float GetFogEnd() const;
-
-	//! Sets the fog end
-	void SetFogEnd(float end);
-
-	//! Returns the fog color
-	const Color4& GetFogColor() const;
-
-	//! Sets the fog color
-	void SetFogColor(const Color4& color);
-
-	//! Returns the alpha function
-	CompareFunction GetAlphaFunc() const;
-
-	//! Sets the alpha function
-	void SetAlphaFunction(CompareFunction func);
-
-	//! Returns the alpha reference
-	float GetAlphaRef() const;
-
-	//! Sets the alpha reference
-	void SetAlphaRef(float ref);
-
-	//! Returns the point size
-	float GetPointSize() const;
-
-	//! Sets the point size
-	void SetPointSize(float size);
-
-	//! Returns the minimum point size
-	float GetPointSizeMin() const;
-
-	//! Sets the minimum point size
-	void SetPointSizeMin(float min);
-
-	//! Returns the maximum point size
-	float GetPointSizeMax() const;
-
-	//! Sets the maximum point' size
-	void SetPointSizeMax(float max);
-
-	//! Returns the blending equation
-	BlendEquation GetBlendEquation() const;
-
-	//! Sets the blending equation
-	void SetBlendEquation(BlendEquation equation);
-
-	//! Returns the source blending function
-	BlendFunction GetSrcBlendFunc() const;
-
-	//! Sets the source blending function
-	void SetSrcBlendFunc(BlendFunction src);
-
-	//! Returns the destination blending function
-	BlendFunction GetDstBlendFunc() const;
-
-	//! Sets the destination blending function
-	void SetDstBlendFunc(BlendFunction dst);
-
-	//! Sets the blending function for both source and destination
-	void SetBlendFunc(BlendFunction src, BlendFunction dst);
-
-	//! Returns the blending color
-	Color4& GetBlendColor();
-
-	//! Sets the blending color
-	void SetBlendColor(const Color4& color);
-
-	//! Sets "texture" to layer "layer"
-	//! Returns true if success
-	bool SetTextureLayer(uint32_t layer, ResourceId texture);
-
-	//! Returns the texture at layer "layer"
-	ResourceId GetTextureLayer(uint32_t layer) const;
-
-	//! Sets the texture mode for all layers
-	void SetTextureMode(TextureMode mode);
-
-	//! Sets the texture filter for all layers
-	void SetTextureFilter(TextureFilter filter);
-
-	//! Sets the texture wrap mode for all layers
-	void SetTextureWrap(TextureWrap wrap);
-
-	//virtual void	Load(const char* name);
-	//virtual void	Unload(const char* name, bool reload);
-
-//private:
-
-	Color4			mAmbient;
-	Color4			mDiffuse;
-	Color4			mSpecular;
-	Color4			mEmission;
-	int32_t			mShininess;
-
-	bool			mLighting				: 1; // Whether lighting is enabled
-	bool			mTexturing				: 1; // Whether texturing is enabled
-	bool			mBackfaceCulling		: 1; // Whether backface-culling is enabled
-	bool			mSeparateSpecularColor : 1; // Whether separate specular color is enabled
-	bool			mDepthTest				: 1; // Whether depth test is enabled
-	bool			mDepthWrite			: 1; // Whether depth write is enabled
-	bool			mRescaleNormals		: 1; // Whether auto normal rescaling is enabled
-	bool			mBlending				: 1; // Whether blending is enabled
-	bool			mColorWrite			: 1; // Whether writing int32_to the color buffer is enabled
-	bool			mFog					: 1; // Whether fog is enabled
-	bool			mAlphaTest				: 1; // Whether alpha test is enabled
-	bool			mPointSprite			: 1; // Whether point sprite is enabled
-
-	ShadingType		mShadingType;
-	PolygonMode		mPolygonMode;
-	FrontFace		mFrontFace;
-
-	CompareFunction	mDepthFunc;
-
-	FogMode 		mFogMode;
-	float			mFogDensity;
-	float			mFogStart;
-	float			mFogEnd;
-	Color4			mFogColor;
-
-	CompareFunction	mAlphaFunc;
-	float			mAlphaRef;
-
-	float			mPointSize;
-	float			mPointSizeMin;
-	float			mPointSizeMax;
-
-	BlendEquation	mBlendEquation;
-	BlendFunction	mBlendSrc;
-	BlendFunction	mBlendDst;
-	Color4			mBlendColor;
+	static MaterialResource*	load(Allocator& allocator, ResourceArchive* archive, ResourceId id);
+	static void					online(MaterialResource* texture);
+	static void					unload(Allocator& allocator, MaterialResource* texture);
+	static void					offline();
+
+private:
+
+	Color4			m_ambient;
+	Color4			m_diffuse;
+	Color4			m_specular;
+	Color4			m_emission;
+	int32_t			m_shininess;
+
+	bool			m_lighting					: 1; // Lighting enabled
+	bool			m_texturing					: 1; // Texturing enabled
+	bool			m_backface_culling			: 1; // Backface-culling enabled
+	bool			m_separate_specular_color 	: 1; // Separate specular color enabled
+	bool			m_depth_test				: 1; // Depth test enabled
+	bool			m_depth_write				: 1; // Depth write enabled
+	bool			m_rescale_normals			: 1; // Auto normal rescaling enabled
+	bool			m_blending					: 1; // Blending enabled
+	bool			m_color_write				: 1; // Writing into color buffer enabled
+	bool			m_fog						: 1; // Fog enabled
+	bool			m_alpha_test				: 1; // Alpha test enabled
+	bool			m_point_sprite				: 1; // Point sprite enabled
+
+	ShadingType		m_shading_type;
+	PolygonMode		m_polygon_mode;
+	FrontFace		m_front_face;
+
+	CompareFunction	m_depth_func;
+
+	FogMode 		m_fog_mode;
+	float			m_fog_density;
+	float			m_fog_start;
+	float			m_fog_end;
+	Color4			m_fog_color;
+
+	CompareFunction	m_alpha_func;
+	float			m_alpha_ref;
+
+	float			m_point_size;
+	float			m_point_size_min;
+	float			m_point_size_max;
+
+	BlendEquation	m_blend_equation;
+	BlendFunction	m_blend_src;
+	BlendFunction	m_blend_dst;
+	Color4			m_blend_color;
 
 	// A material can contain up to MAX_TEXTURE_LAYERS texture layers.
-	// However, the maximum number of texture layers really usable is renderer-dependent.
-	ResourceId		mTextureLayer[MAX_TEXTURE_LAYERS];
+	// However, the maximum number of texture layers actually usable is Renderer-dependent.
+	ResourceId		m_textures[MAX_TEXTURE_LAYERS];
 };
 
 } // namespace crown