Commits

Jason McKesson committed e239ec9

Core loaders up, as well as the loading header.
Ready for the actual loader.

  • Participants
  • Parent commits b4332f6

Comments (0)

Files changed (5)

modules/Specs.lua

 function wgl_spec.LoadSpec() return LoadSpec.LoadLuaSpec(util.GetSpecFilePath() .. "wglspec.lua", wgl_spec) end
 function glx_spec.LoadSpec() return LoadSpec.LoadLuaSpec(util.GetSpecFilePath() .. "glxspec.lua", glX_spec) end
 
+--Name for displaying.
+function gl_spec.DisplayName() return "OpenGL" end
+function wgl_spec.DisplayName() return "WGL" end
+function glx_spec.DisplayName() return "GLX" end
+
 ---FilePrefix
 function gl_spec.FilePrefix() return "gl_" end
 function wgl_spec.FilePrefix() return "wgl_" end

modules/StructGLLoad.lua

 
 local function CoreLoaderStruct(funcFilter)
 	return
-{ type="group",
-	{ type="core-ext-iter",
+	{ type="group",
+		{ type="core-ext-iter",
+			{ type="func-iter",
+				{ type="filter", name= funcFilter .. "(func)",
+					{ type="write", name="LoadFunctionCore(hFile, func, typemap, spec, options)", },
+				},
+			},
+		},
 		{ type="func-iter",
-			{ type="filter", name= funcFilter .. "(func)",
+			{ type="filter", name=funcFilter .. "(func)",
 				{ type="write", name="LoadFunctionCore(hFile, func, typemap, spec, options)", },
 			},
 		},
-	},
-	{ type="func-iter",
-		{ type="filter", name=funcFilter .. "(func)",
-			{ type="write", name="LoadFunctionCore(hFile, func, typemap, spec, options)", },
-		},
-	},
-}
+	}
 end
 
 local source_struct = 
 	},
 	{ type="blank"},
 	{ type="func-seen",
+		--Write the extension functions and ext loaders.
 		{ type="ext-iter",
 			{ type="func-iter",
 				{ type="write", name="FuncDef(hFile, func, typemap, spec, options)", },
 			},
 			{ type="blank", cond="func-iter"},
 		},
+		{ type="blank"},
+		--Write the core functions (not already written) and the individual core loaders.
 		{ type="version-iter",
 			{ type="func-iter",
 				{ type="write", name="FuncDefCond(hFile, func, typemap, spec, options, funcSeen)", },
 			},
 		},
-		{ type="blank"},
+		{ type="blank", cond="version-iter"},
 		{ type="version-iter",
 			{ type="filter", name="VersionHasCoreFuncs(version, specData, spec, options)",
 				{ type="block", name="LoadCoreFuncs(hFile, version, spec, options)",
 				},
 			},
 		},
+		{ type="blank", cond="version-iter"},
 	},
+	
+	--Write the aggregate core loaders (ie: load all for version X and below)
+	{ type="version-iter",
+		{ type="block", name="LoadAllCoreFunc(hFile, version, spec, options)",
+			{ type="sub-version-iter",
+				{ type="filter", name="VersionHasCoreFuncs(sub_version, specData, spec, options)",
+					{ type="write", name="CallCoreLoad(hFile, sub_version, spec, options)" },
+				},
+				{ type="filter", name="HasCompatibility(version, specData, spec, options)", neg=true,
+					{ type="filter", name="VersionHasCompFuncs(sub_version, specData, spec, options)",
+						{ type="write", name="CallCoreCompLoad(hFile, sub_version, spec, options)" },
+					},
+				},
+			},
+		},
+		{ type="blank" },
+		{ type="filter", name="HasCompatibility(version, specData, spec, options)",
+			{ type="block", name="LoadAllCoreCompFunc(hFile, version, spec, options)",
+				{ type="sub-version-iter",
+					{ type="filter", name="VersionHasCoreFuncs(sub_version, specData, spec, options)",
+						{ type="write", name="CallCoreLoad(hFile, sub_version, spec, options)" },
+					},
+					{ type="filter", name="VersionHasCompFuncs(sub_version, specData, spec, options)",
+						{ type="write", name="CallCoreCompLoad(hFile, sub_version, spec, options)" },
+					},
+				},
+			},
+			{ type="blank" },
+		},
+	},
+	
+
 }
 
-
-local my_struct =
-{
+local decl_header_struct =
+{ type="group",
 -- Internal header files.
 { type="enum-seen",
 { type="func-seen",
 },
 },
 
+}
+
+
+local my_struct =
+{
+	decl_header_struct,
+
 	--Main header files.
 	{ type="version-iter",
 		{ type="file", style="incl_hdr", name="VersionFilenameCore(basename, version, spec, options)",
 
 	--Header to load things.
 	{ type="file", style="load_hdr", name="GetFilename(basename, spec, options)",
+		{ type="write", name="LoaderDecl(hFile, spec, options)" },
 	},
 	
 	--Source file.

modules/Structure.lua

 
 - file: Creates a TabbedFile.
 -		name: The style function to call. It should return a filename. The defualt parameters are (basename, options)
--		style: This represents a scoping for the style for all children of the file. So if your style has a "header" subtable with functions for creating header files, you set `style` to "header".
 
 - block: Represents a block. Must be in a file scope.
 -		name: Part of the function name to call. When starting the block, it will call "WriteBlockBegin"..name. To end it, it will call "WriteBlockEnd"..name. The default parameters are (hFile, spec, options).
 
 - name: The name of a function to call, or part of a name. This can also include a parenthesized list of parameters. The parameter names much match those in the above list of parameters, and those parameters must be available in this particular scope (different actions create different scopes. If a particular parameter is not available in a context, a runtime error will occur.
 
+- style: This represents a scoping for the style for all children of this action. It will access the main style using the given string, and it expects a table of functions. All names within this action will be expected to be in that style; if they are not, they'll check the previous style, on down until the first style. These can be nested, but note that the fetching of the table is always done in the *main* style, not the "current" style.
+
 - first: When set, this particular action (and any of its child actions) will only be executed the first time through the most recent iteration loop. Note that this only works for the most recent iteration loop. And it only works within an interation loop, since they are the only ones who execute their children multiple times.
 
 - last: Like first, except for the last time through a block. Usually for inserting blank space.
 local filterAction = {}
 
 function filterAction:PreProcess(context)
-	return not self:CallFunction(context, self.name)
+	local shouldFilter = self:CallFunction(context, self.name)
+	if(self.neg) then
+		shouldFilter = not shouldFilter
+	end
+	return not shouldFilter
 end
 
 MakeActionType("filter", filterAction, function(self, data)
 	assert(data.name, "Filter actions must have a `name`")
 	self.name = "Filter" .. self.name
+	self.neg = data.neg
 	self.params = self.params or {}
 end)
 
 end)
 
 conditionals["version-iter"] = function(context)
-	assert(context.version, "Cannot have a version-iter conditional outside of a version.")
-	return context.version ~= nil
+	return #context.spec.GetVersions() ~= 0
 end
 
 

modules/StyleGLLoadC.lua

 	return dir .. glload.headerDirectory .. spec.FilePrefix() .. "load.h"
 end
 
+function load_hdr.WriteLoaderDecl(hFile, spec, options)
+	hFile:writeblock(glload.GetLoaderHeaderString(spec, options))
+end
 
 ----------------------------------------------------------
 -- Source file.
 end
 
 function source.WriteBlockBeginLoadExtensionFuncs(hFile, extName, spec, options)
-	hFile:fmt("static int %s()\n",
+	glload.WriteLoaderFuncBegin(hFile,
 		glload.GetLoadExtensionFuncName(extName, spec, options))
-	hFile:write("{\n")
-	hFile:inc()
-	hFile:write("int numFailed = 0;\n")
 end
 
 function source.WriteBlockEndLoadExtensionFuncs(hFile, extName, spec, options)
-	hFile:write("return numFailed;\n")
-	hFile:dec()
-	hFile:write("}\n")
+	glload.WriteLoaderFuncEnd(hFile)
 end
 
 function source.WriteLoadFunction(hFile, func, typemap, spec, options)
 end
 
 function source.WriteBlockBeginLoadCoreFuncs(hFile, version, spec, options)
-	hFile:fmt("static int %s()\n",
+	glload.WriteLoaderFuncBegin(hFile,
 		glload.GetLoadCoreFuncName(version, spec, options))
-	hFile:write("{\n")
-	hFile:inc()
-	hFile:write("int numFailed = 0;\n")
 end
 
 function source.WriteBlockEndLoadCoreFuncs(hFile, version, spec, options)
-	hFile:write("return numFailed;\n")
-	hFile:dec()
-	hFile:write("}\n")
+	glload.WriteLoaderFuncEnd(hFile)
 end
 
 function source.WriteBlockBeginLoadCoreFuncsComp(hFile, version, spec, options)
-	hFile:fmt("static int %s()\n",
+	glload.WriteLoaderFuncBegin(hFile,
 		glload.GetLoadCoreCompFuncName(version, spec, options))
-	hFile:write("{\n")
-	hFile:inc()
-	hFile:write("int numFailed = 0;\n")
 end
 
 function source.WriteBlockEndLoadCoreFuncsComp(hFile, version, spec, options)
-	hFile:write("return numFailed;\n")
-	hFile:dec()
-	hFile:write("}\n")
+	glload.WriteLoaderFuncEnd(hFile)
 end
 
 function source.WriteLoadFunctionCore(hFile, func, typemap, spec, options)
 	end
 end
 
+function source.WriteBlockBeginLoadAllCoreFunc(hFile, version, spec, options)
+	glload.WriteLoaderFuncBegin(hFile,
+		glload.GetLoadAllCoreFuncName(version, spec, options))
+end
+
+function source.WriteBlockEndLoadAllCoreFunc(hFile, version, spec, options)
+	glload.WriteLoaderFuncEnd(hFile)
+end
+
+function source.WriteBlockBeginLoadAllCoreCompFunc(hFile, version, spec, options)
+	hFile:fmt("static int %s()\n",
+		glload.GetLoadAllCoreCompFuncName(version, spec, options))
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function source.WriteBlockEndLoadAllCoreCompFunc(hFile, version, spec, options)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
+function source.WriteCallCoreLoad(hFile, sub_version, spec, options)
+	hFile:fmt("numFailed += %s();\n",
+		glload.GetLoadCoreFuncName(sub_version, spec, options))
+end
+
+function source.WriteCallCoreCompLoad(hFile, sub_version, spec, options)
+	hFile:fmt("numFailed += %s();\n",
+		glload.GetLoadCoreCompFuncName(sub_version, spec, options))
+end
+
+
+------------------------------------------------------
+-- Filters
+
 my_style =
 {
 	type_hdr = type_hdr,

modules/glload_util.lua

 ]]
 end
 
+function data.WriteLoaderFuncBegin(hFile, funcName)
+	hFile:fmt("static int %s()\n", funcName)
+	hFile:write("{\n")
+	hFile:inc()
+	hFile:write("int numFailed = 0;\n")
+end
+
+function data.WriteLoaderFuncEnd(hFile)
+	hFile:write("return numFailed;\n")
+	hFile:dec()
+	hFile:write("}\n")
+end
+
 function data.GetClearExtVarsFuncName(spec, options)
 	return "ClearExtensionVariables"
 end
 	return "LoadCore_Version_" .. version:gsub("%.", "_") .. "_Comp"
 end
 
+function data.GetLoadAllCoreFuncName(version, spec, options)
+	return "LoadVersion_" .. version:gsub("%.", "_")
+end
+
+function data.GetLoadAllCoreCompFuncName(version, spec, options)
+	return "LoadVersion_" .. version:gsub("%.", "_") .. "_Comp"
+end
+
+--[[
+$<specname>
+$<prefix>
+$<desc>
+$<extra>
+]]
+
+local hdr_extra_spec =
+{
+	wgl = "",
+	glX = "",
+	gl = [=[
+/**
+This function retrieves the major GL version number. Only works after LoadFunctions has been called.
+**/
+int $<prefix>GetMajorVersion();
+
+/**
+This function retrieves the minor GL version number. Only works after LoadFunctions has been called.
+**/
+int $<prefix>GetMinorVersion();
+
+///Returns non-zero if the current GL version is greater than or equal to the given version.
+int $<prefix>IsVersionGEQ(int iMajorVersion, int iMinorVersion);
+]=],
+}
+
+local hdr_desc =
+{
+	wgl = [[Loads function pointers for WGL extensions.]],
+	glX = [[Loads function pointers for GLX extensions.]],
+	gl = [[Loads function pointers for OpenGL. This function will also load the core OpenGL functions (ie: not in extensions). It will only load the version and profile specified by the current OpenGL context. So if you get a 3.2 compatibility context, then it will load only try to load 3.2 compatibility in addition to any available extensions.]],
+}
+
+local hdr_pattern = 
+[=[
+/**
+\file
+\brief C header to include if you want to initialize $<specname>.
+
+**/
+
+///\addtogroup module_glload_cinter
+///@{
+
+/**
+\brief The loading status returned by the loading functions.
+
+**/
+enum
+{
+	$<prefix>LOAD_FAILED = 0;
+	$<prefix>LOAD_SUCCEEDED = 0;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif //__cplusplus
+
+/**
+\brief Loads all of the function pointers available.
+
+$<desc>
+
+\return Will return $<prefix>LOAD_FAILED if the loading failed entirely and nothing was loaded. Returns $<prefix>LOAD_SUCCEEDED if the loading process worked as planned. If it is neither, then the (return value - $<prefix>LOAD_SUCCEEDED) is the number of core functions that fialed to load.
+**/
+int $<prefix>LoadFunctions();
+
+$<extra>
+///@}
+
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+]=]
+
+function data.GetLoaderHeaderString(spec, options)
+	local ret = hdr_pattern
+	ret = ret:gsub("%$%<extra%>", hdr_extra_spec[options.spec])
+	ret = ret:gsub("%$%<specname%>", spec.DisplayName())
+	ret = ret:gsub("%$%<prefix%>", spec.DeclPrefix())
+	ret = ret:gsub("%$%<desc%>", hdr_desc[options.spec])
+	return ret
+end
+
 
 return data