Jason McKesson avatar Jason McKesson committed 7573ab1

Added ability to specify scene graph.

Comments (0)

Files changed (5)

Documents/sceneFormat.rnc

         sc.xml.id.attribute, sc.mesh.file.attribute
         
     sc.texture.attlist =
-        sc.xml.id.attribute, sc.texture.file.attribute
+        sc.xml.id.attribute, sc.texture.file.attribute, sc.texture.srgb.attribute?
     
     sc.prog.attlist =
         sc.xml.id.attribute,
     sc.texture.file.attribute =
         ##The texture's filename.
         attribute file { acc.filename.type }
+        
+    sc.texture.srgb.attribute =
+        ##True if the texture if in the srgb format.
+        attribute srgb { xsd:boolean }
     
     sc.prog.vert.attribute =
         ##The vertex shader filename for this program

Tut 17 Spotlight on Textures/Double Projection.cpp

 	LightBlock lightData;
 	lightData.ambientIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
 	lightData.lightAttenuation = 1.0f / (5.0f * 5.0f);
-	lightData.maxIntensity = 4.0f;
+	lightData.maxIntensity = 3.0f;
 	lightData.lights[0].lightIntensity = glm::vec4(2.0f, 2.0f, 2.5f, 1.0f);
 	lightData.lights[0].cameraSpaceLightPos = camMatrix *
 		glm::normalize(glm::vec4(-0.2f, 0.5f, 0.5f, 0.0f));

Tut 17 Spotlight on Textures/data/dp_scene.xml

 	<mesh xml:id="m_longBar" file="LongBar.xml"/>
 	<mesh xml:id="m_diorama" file="UnitDiorama.xml"/>
 	<mesh xml:id="m_floor" file="UnitPlane.xml"/>
-    <texture xml:id="t_stone" file="seamless_rock1_small.dds"/>
-    <texture xml:id="t_concrete_wall" file="concrete649_small.dds"/>
-    <texture xml:id="t_sandy_ground" file="dsc_1621_small.dds"/>
-    <texture xml:id="t_stone_pillar" file="rough645_small.dds"/>
-    <texture xml:id="t_wood_pillar" file="wood4_rotate.dds"/>
+    <texture xml:id="t_stone" file="seamless_rock1_small.dds" srgb="true"/>
+    <texture xml:id="t_concrete_wall" file="concrete649_small.dds" srgb="true"/>
+    <texture xml:id="t_sandy_ground" file="dsc_1621_small.dds" srgb="true"/>
+    <texture xml:id="t_stone_pillar" file="rough645_small.dds" srgb="true"/>
+    <texture xml:id="t_wood_pillar" file="wood4_rotate.dds" srgb="true"/>
     <prog
         xml:id="p_unlit"
         vert="Unlit.vert"

framework/Scene.cpp

 	class SceneTexture
 	{
 	public:
-		SceneTexture(const std::string &filename)
+		SceneTexture(const std::string &filename, unsigned int creationFlags)
 		{
 			std::string pathname(Framework::FindFileOrThrow(filename));
 
 				pImageSet.reset(glimg::loaders::stb::LoadFromFile(pathname.c_str()));
 			}
 
-			m_texObj = glimg::CreateTexture(pImageSet.get(), 0);
+			m_texObj = glimg::CreateTexture(pImageSet.get(), creationFlags);
 			//TODO: FIX THIS!!
 			m_texType = GL_TEXTURE_2D;
 		}
 			PARSE_THROW(pNameNode, "Texture found with no `xml:id` name specified.");
 			PARSE_THROW(pFilenameNode, "Texture found with no `file` filename specified.");
 
+			const xml_attribute<> *pSrgbNode = TexNode.first_attribute("srgb");
+
 			std::string name = make_string(*pNameNode);
 			if(m_textures.find(name) != m_textures.end())
 				throw std::runtime_error("The texture named \"" + name + "\" already exists.");
 
 			m_textures[name] = NULL;
 
-			SceneTexture *pTexture = new SceneTexture(make_string(*pFilenameNode));
+			unsigned int creationFlags = 0;
+			if(get_attrib_bool(TexNode, "srgb"))
+				creationFlags |= glimg::FORCE_SRGB_COLORSPACE_FMT;
+
+			SceneTexture *pTexture = new SceneTexture(make_string(*pFilenameNode), creationFlags);
 
 			m_textures[name] = pTexture;
 		}

framework/rapidxml_helpers.h

 		return pNode;
 	}
 
+	//If it's not there
+	inline bool get_attrib_bool(const xml_node<> &node, const std::string &attribName, bool optRet = false)
+	{
+		const xml_attribute<> *pAttrib = node.first_attribute(attribName.c_str());
+		if(!pAttrib)
+			return optRet;
+
+		const std::string &test = make_string(*pAttrib);
+		if(test == "true")
+			return true;
+
+		return false;
+	}
+
 	template<typename Callable>
 	int attrib_to_int(const xml_attribute<> &attrib, Callable FailFunc)
 	{
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.