瀏覽代碼

Major changes in Font and Material too

Daniele Bartolini 13 年之前
父節點
當前提交
3b035fb865
共有 4 個文件被更改,包括 164 次插入210 次删除
  1. 4 46
      src/Font.cpp
  2. 5 10
      src/Font.h
  3. 102 102
      src/Material.cpp
  4. 53 52
      src/Material.h

+ 4 - 46
src/Font.cpp

@@ -29,64 +29,22 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Image.h"
 #include "Log.h"
 #include "Filesystem.h"
-#include "TextureManager.h"
 
 namespace crown
 {
 
-Font::Font() :
+FontResource::FontResource() :
 	mMaxTextHeight(0),
 	mMaxCharacterHeight(0),
 	mMaxCharacterWidth(0)
 {
 }
 
-Font::~Font()
+FontResource::~FontResource()
 {
 }
 
-void Font::LoadFromFile(const Str& filename)
-{
-	mTexture = GetTextureManager()->Load(filename.c_str(), false);
-
-	if (mTexture)
-	{
-		mTexture->SetFilter(TF_NEAREST);
-	}
-
-	Filesystem* filesystem = GetFilesystem();
-
-	Stream* fontDef = filesystem->OpenStream((filename + Str(".txt")).c_str(), SOM_READ);
-
-	if (fontDef)
-	{
-		TextReader textReader(fontDef);
-		char buf[1024];
-
-		while (textReader.read_string(buf, 1024) != NULL)
-		{
-			int32_t ch;
-			float a, b, c, d, e, f, g, h;
-
-			sscanf(buf, "%d %f %f %f %f %f %f %f %f\n", &ch, &a, &b, &c, &d, &e, &f, &g, &h);
-
-			SetCodeGlyphMetrics(ch, a, b, c, d, e, f, g, h);
-		}
-
-		filesystem->Close(fontDef);
-	}
-}
-
-void Font::Load(const char* name)
-{
-	LoadFromFile(name);
-}
-
-void Font::Unload(const char* name, bool reload)
-{
-}
-
-Glyph& Font::GetGlyph(uint32_t code)
+Glyph& FontResource::GetGlyph(uint32_t code)
 {
 	if (mCodeGlyphDict.Contains(code))
 	{
@@ -97,7 +55,7 @@ Glyph& Font::GetGlyph(uint32_t code)
 	return nullGlyph;
 }
 
-void Font::SetCodeGlyphMetrics(uint32_t code, float left, float right, float bottom, float top, float width, float height, float advance, float baseline)
+void FontResource::SetCodeGlyphMetrics(uint32_t code, float left, float right, float bottom, float top, float width, float height, float advance, float baseline)
 {
 	if (mCodeGlyphDict.Contains(code))
 	{

+ 5 - 10
src/Font.h

@@ -41,20 +41,15 @@ class Texture;
 /**
 	Font resource for using in text rendering.
 */
-class Font : public Resource
+class FontResource
 {
 
 	typedef Dictionary<uint32_t, Glyph> CodeGlyphDict;
 
 public:
 
-							Font();	//! Constructor
-							~Font();	//! Destructor
-
-	virtual void			Load(const char* name);
-	virtual void			Unload(const char* name, bool reload);
-
-	void					LoadFromFile(const Str& filename);
+							FontResource();
+							~FontResource();
 
 	Glyph&					GetGlyph(uint32_t code);	//! Returns the glyph for the desired point32_t code
 	void					SetCodeGlyphMetrics(uint32_t code, float left, float right, float bottom, float top, float width, float height, float advance, float baseline);
@@ -63,7 +58,7 @@ public:
 	inline uint32_t			_GetMaxCharacterHeight() { return mMaxCharacterHeight; }
 	inline uint32_t			_GetMaxCharacterWidth() { return mMaxCharacterWidth; }
 
-	Texture*				GetTexture() { return mTexture; }
+	ResourceId				GetTexture() { return mTexture; }
 
 private:
 
@@ -73,7 +68,7 @@ private:
 	uint32_t				mMaxCharacterHeight;
 	uint32_t				mMaxCharacterWidth;
 
-	Texture*				mTexture;
+	ResourceId				mTexture;
 };
 
 } // namespace crown

+ 102 - 102
src/Material.cpp

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

+ 53 - 52
src/Material.h

@@ -26,7 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
-#include "Texture.h"
+#include "TextureResource.h"
+#include "Resource.h"
 #include "Vec3.h"
 
 namespace crown
@@ -110,16 +111,16 @@ enum BlendFunction
 	BF_COUNT
 };
 
-class Material : public Resource
+class MaterialResource
 {
 
 public:
 
 	//! Constructor
-	Material();
+	MaterialResource();
 
 	//! Destructor
-	~Material();
+	~MaterialResource();
 
 	//! Returns the ambient reflectance
 	const Color4& GetAmbient() const;
@@ -336,10 +337,10 @@ public:
 
 	//! Sets "texture" to layer "layer"
 	//! Returns true if success
-	bool SetTextureLayer(uint32_t layer, Texture* texture);
+	bool SetTextureLayer(uint32_t layer, ResourceId texture);
 
 	//! Returns the texture at layer "layer"
-	Texture* GetTextureLayer(uint32_t layer) const;
+	ResourceId GetTextureLayer(uint32_t layer) const;
 
 	//! Sets the texture mode for all layers
 	void SetTextureMode(TextureMode mode);
@@ -355,52 +356,52 @@ public:
 
 //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;
-
-	//! A material can contain up to MAX_TEXTURE_LAYERS texture layers.
-	//! However, the maximum number of texture layers really usable is renderer-dependent.
-	Texture* mTextureLayer[MAX_TEXTURE_LAYERS];
+	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;
+
+	// 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];
 };
 
 } // namespace crown