Commits

Jason McKesson  committed 9c73180

glscene: style mesh and texture parsing.

  • Participants
  • Parent commits 8bde3f7

Comments (0)

Files changed (4)

File glscene/Test/test.glscene

 
 resources
-	sampler_res <ident>
+	sampler_res <spl>
 		mag [linear]
 		compare [pass]
 		aniso 1
 	end
 	
 	mesh_res <ident> [ground_plane] 3 20
-	texture_res <ident> "foo.file[ground_plane]"
+	texture_res <tex> "foo.file[ground_plane]"
 end
 
 scene
 
 			style <id>
 				using <ident2>
+				
+				mesh <ident>
+				texture 0 <tex> <spl>
 			end
 		end
 		

File glscene/source/Parse.cpp

 		TOK_MATRIX,
 	};
 
+	const size_t g_legalStyleTokens[] =
+	{
+		TOK_MESH,
+		TOK_TEXTURE,
+	};
+
 	//////////////////////////////////////////////////////////////////////////
 	// The lexer.
 	template <typename Lexer>
 
 			dest.scope.AddToScope(local);
 
-			ParseStyleData(local.data);
+			ParseStyleData(local.data, TOK_LOCAL);
 
 			ExpectAndEatEndToken();
 		}
 					ThrowParseError("`using` members must be identifier strings.", curr_throw);
 			}
 
-			ParseStyleData(style.data);
+			ParseStyleData(style.data, TOK_STYLE);
 
 			ExpectAndEatEndToken();
 		}
 
-		void ParseStyleData(ParsedStyleData &data)
+		void ParseStyleData(ParsedStyleData &data, size_t owningId)
 		{
-
+			while(IsCurrTokenOneOf(g_legalStyleTokens))
+			{
+				FilePosition pos = GetPositionForCurrToken();
+				typename Range::value_type tok = m_rng.front();
+				switch(tok.id())
+				{
+				case TOK_MESH:
+					{
+						if(data.mesh.is_initialized())
+							throw MultipleUseOfCommandError(tok, owningId);
+						EatOneToken();
+						data.mesh = ParsedMeshRefDef(ParseIdentifier(m_resources.meshes, true, tok.id()));
+						ParsedMeshRefDef &def = data.mesh.get();
+						def.pos = pos;
+						if(IsCurrToken(TOK_GRAPH_NAME))
+							def.variant = ParseGraphName();
+					}
+					break;
+				case TOK_TEXTURE:
+					{
+						EatOneToken();
+						unsigned int texUnit = ParseSingleUInt();
+						IdString textureId = ParseIdentifier(m_resources.textures, true, tok.id());
+						IdString samplerId = ParseIdentifier(m_resources.samplers, true, TOK_SAMPLER_RES);
+						data.textures.push_back(ParsedTextureRefDef(textureId, samplerId));
+						data.textures.back().pos = pos;
+						data.textures.back().texUnit = texUnit;
+					}
+					break;
+				}
+			}
 		}
 
 		template<typename MapType>

File glscene/source/ParsedData.h

 
 	typedef boost::container::flat_set<std::string> LayerSet;
 
+	struct ParsedMeshRefDef
+	{
+		FilePosition pos;
+		IdString meshId;
+		boost::optional<std::string> variant;
+
+		ParsedMeshRefDef(const IdString &_id) : meshId(_id) {}
+	};
+
+	struct ParsedTextureRefDef
+	{
+		FilePosition pos;
+		unsigned int texUnit;
+		IdString textureId;
+		IdString samplerId;
+
+		ParsedTextureRefDef(const IdString &_textureId, const IdString &_samplerId)
+			: textureId(_textureId)
+			, samplerId(_samplerId)
+		{}
+	};
+
 	struct ParsedStyleData
 	{
-		
+		boost::optional<ParsedMeshRefDef> mesh;
+		std::vector<ParsedTextureRefDef> textures;
 	};
 
 	struct ParsedLocalDef

File glscene/source/keywords.incl

 	MAC(LOCAL,			"local",		"local declaration",		"local declaration")
 	MAC(STYLE,			"style",		"style declaration",		"style declaration")
 	MAC(USING,			"using",		"using inclusion",			"using inclusion")
+	MAC(MESH,			"mesh",			"mesh reference",			"mesh reference")
+	MAC(PROGRAM,		"program",		"program reference",		"program reference")
+	MAC(PIPELINE,		"pipeline",		"pipeline reference",		"pipeline reference")
+	MAC(TEXTURE,		"texture",		"texture reference",		"texture reference")
+	MAC(UNIFORM,		"uniform",		"uniform reference",		"uniform reference")