Commits

Jason McKesson committed 2153ed0

GL Load code generation basically works. At least on Windows.

  • Participants
  • Parent commits 7f8c521

Comments (0)

Files changed (6)

File modules/CommonStyle.lua

 function common.WriteExternCStart(hFile)
 	hFile:write("#ifdef __cplusplus\n")
 	hFile:write('extern "C" {\n')
-	hFile:write("#endif //__cplusplus\n")
+	hFile:write("#endif /*__cplusplus*/\n")
 	hFile:write("\n")
 end
 
 function common.WriteExternCEnd(hFile)
 	hFile:write("#ifdef __cplusplus\n")
 	hFile:write('}\n')
-	hFile:write("#endif //__cplusplus\n")
+	hFile:write("#endif /*__cplusplus*/\n")
 	hFile:write("\n")
 end
 
 
 	while(*strCurrPos)
 	{
-		//Get the extension at our position.
+		/*Get the extension at our position.*/
 		int iStrLen = 0;
 		const char *strEndStr = strchr(strCurrPos, ' ');
 		int iStop = 0;
 	strDotPos = strchr(strVersion + iLength + 1, ' ');
 	if(!strDotPos)
 	{
-		//No extra data. Take the whole rest of the string.
+		/*No extra data. Take the whole rest of the string.*/
 		strcpy(strWorkBuff, strVersion + iLength + 1);
 	}
 	else
 	{
-		//Copy only up until the space.
+		/*Copy only up until the space.*/
 		int iLengthMinor = (int)((ptrdiff_t)strDotPos - (ptrdiff_t)strVersion);
 		iLengthMinor = iLengthMinor - (iLength + 1);
 		strncpy(strWorkBuff, strVersion + iLength + 1, iLengthMinor);

File modules/StructGLLoad.lua

 		{ type="write", name="ExtVariable(hFile, extName, spec, options)" },
 	},
 	{ type="blank"},
-	{ type="block", name="ClearExtVars(hFile, spec, options)",
-		{ type="ext-iter",
-			{ type="write", name="ClearExtVar(hFile, extName, spec, options)" },
-		},
-	},
-	{ type="blank"},
 	{ type="func-seen",
 		--Write the extension functions and ext loaders.
 		{ type="ext-iter",
 				{ type="write", name="IncludeIntExts(hFile, spec, options)"},
 				{ type="blank" },
 				{ type="sub-version-iter",
-					{ type="write", name="IncludeIntVersionCore(hFile, sub_version, spec, options)"},
+					{ type="write", name="IncludeIntVersionCore(hFile, sub_version, specData, spec, options)"},
 					{ type="blank", last=true, },
 				},
 			},
 					{ type="write", name="IncludeIntExts(hFile, spec, options)"},
 					{ type="blank" },
 					{ type="sub-version-iter",
-						{ type="write", name="IncludeIntVersionCore(hFile, sub_version, spec, options)"},
+						{ type="write", name="IncludeIntVersionCore(hFile, sub_version, specData, spec, options)"},
 						{ type="write", name="IncludeIntVersionComp(hFile, sub_version, specData, spec, options)"},
 						{ type="blank", last=true, },
 					},
 			{ type="write", name="IncludeIntExts(hFile, spec, options)"},
 			{ type="blank" },
 			{ type="version-iter",
-				{ type="write", name="IncludeIntVersionCore(hFile, version, spec, options)"},
+				{ type="write", name="IncludeIntVersionCore(hFile, version, specData, spec, options)"},
 				{ type="write", name="IncludeIntVersionComp(hFile, version, specData, spec, options)"},
 				{ type="blank", last=true, },
 			},

File modules/StyleGLLoadC.lua

 end
 
 function type_hdr.WriteBlockEndIncludeGuard(hFile, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetTypeHdrFileIncludeGuard(spec, options))
+	hFile:fmt("#endif /*%s*/\n", glload.GetTypeHdrFileIncludeGuard(spec, options))
 end
 
 function type_hdr.WriteInit(hFile, spec, options)
 end
 
 function ext_hdr.WriteBlockEndIncludeGuard(hFile, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetExtFileIncludeGuard(spec, options))
+	hFile:fmt("#endif /*%s*/\n", glload.GetExtFileIncludeGuard(spec, options))
 end
 
 function ext_hdr.WriteTypedefs(hFile, specData, spec, options)
-	common.WritePassthruData(hFile, specData.funcData.passthru)
+--	common.WritePassthruData(hFile, specData.funcData.passthru)
 end
 
 function ext_hdr.WriteBlockBeginExtern(hFile, spec, options)
 end
 
 function core_hdr.WriteBlockEndIncludeGuard(hFile, version, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetCoreHdrFileIncludeGuard(version, spec, options))
+	hFile:fmt("#endif /*%s*/\n", glload.GetCoreHdrFileIncludeGuard(version, spec, options))
 end
 
 function core_hdr.WriteBlockBeginIncludeGuardRem(hFile, version, spec, options)
 end
 
 function core_hdr.WriteBlockEndIncludeGuardRem(hFile, version, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetCoreHdrFileIncludeGuard(version, spec, options, true))
+	hFile:fmt("#endif /*%s*/\n", glload.GetCoreHdrFileIncludeGuard(version, spec, options, true))
 end
 
 function core_hdr.WriteBlockBeginExtern(hFile, spec, options)
 end
 
 function incl_hdr.WriteBlockEndIncludeGuardCore(hFile, version, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetInclFileIncludeGuard(version, spec, options))
+	hFile:fmt("#endif /*%s*/\n", glload.GetInclFileIncludeGuard(version, spec, options))
 end
 
 function incl_hdr.WriteBlockBeginIncludeGuardComp(hFile, version, spec, options)
 end
 
 function incl_hdr.WriteBlockEndIncludeGuardComp(hFile, version, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetInclFileCompIncludeGuard(version, spec, options))
+	hFile:fmt("#endif /*%s*/\n", glload.GetInclFileCompIncludeGuard(version, spec, options))
 end
 
 function incl_hdr.WriteBlockBeginIncludeGuardAll(hFile, spec, options)
 end
 
 function incl_hdr.WriteBlockEndIncludeGuardAll(hFile, spec, options)
-	hFile:fmt("#endif //%s\n", glload.GetInclFileAllIncludeGuard(spec, options))
+	hFile:fmt("#endif /*%s*/\n", glload.GetInclFileAllIncludeGuard(spec, options))
 end
 
 function incl_hdr.WriteIncludeIntType(hFile, spec, options)
 	hFile:fmt('#include "%s"\n', glload.GetExtsHeaderBasename(spec, options))
 end
 
-function incl_hdr.WriteIncludeIntVersionCore(hFile, sub_version, spec, options)
+function incl_hdr.WriteIncludeIntVersionCore(hFile, sub_version, specData, spec, options)
+	if(not my_style.FilterVersionHasCore(sub_version, specData, spec, options)) then
+		return
+	end
+
 	hFile:fmt('#include "%s"\n', glload.GetCoreHeaderBasename(sub_version, spec, options))
 end
 
 
 function load_hdr.GetFilename(basename, spec, options)
 	local basename, dir = util.ParsePath(basename)
-	return dir .. glload.headerDirectory .. spec.FilePrefix() .. "load.h"
+	return dir .. glload.headerDirectory .. glload.GetLoaderBasename(spec, options)
 end
 
 function load_hdr.WriteLoaderDecl(hFile, spec, options)
 function source.WriteIncludes(hFile, spec, options)
 	hFile:writeblock[[
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 ]]
 	hFile:fmt('#include "%s"\n', glload.headerDirectory .. 
 		glload.GetAllBasename(spec, options))
+	hFile:fmt('#include "%s"\n', glload.headerDirectory .. 
+		glload.GetLoaderBasename(spec, options))
 end
 
 function source.WritePointerLoading(hFile, specData, spec, options)
 		glload.GetExtVariableName(extName, spec, options))
 end
 
-function source.WriteBlockBeginClearExtVars(hFile, spec, options)
-	hFile:fmtblock("static void %s()\n{\n",
-		glload.GetClearExtVarsFuncName(spec, options))
-	hFile:inc()
-end
-
-function source.WriteBlockEndClearExtVars(hFile, spec, options)
-	hFile:dec()
-	hFile:write("}\n")
-end
-
-function source.WriteClearExtVar(hFile, extName, spec, options)
-	hFile:fmt("%s = 0;\n",
-		glload.GetExtVariableName(extName, spec, options))
-end
-
 function source.WriteFuncDef(hFile, func, typemap, spec, options)
 	hFile:fmt("%s %s = NULL;\n",
 		glload.GetFuncTypedefName(func, spec, options),
 	for(; loop < g_numVersionMapEntries; ++loop)
 	{
 		if(
-			(g_versionMapTable[loop].major == major) &&
-			(g_versionMapTable[loop].minor == minor) &&
+			(g_versionMapTable[loop].majorVersion == major) &&
+			(g_versionMapTable[loop].minorVersion == minor) &&
 			(g_versionMapTable[loop].compatibilityProfile == compatibilityProfile))
 		{
-			return g_versionMapTable[loop].LoadVersion()
+			return g_versionMapTable[loop].LoadVersion();
 		}
 	}
 	
-	return 0;
+	return -1;
 }
 ]])
 		hFile:write "\n"
 		strFunc = glload.GetFuncPtrName(strFunc, spec, options)
 		
 		hFile:write "\n"
-		hFile:fmt("ParseVersionFromString(&g_majorVersion, &g_minorVersion, (const char*)%s(GL_VERSION))", strFunc)
+		hFile:fmt("ParseVersionFromString(&g_majorVersion, &g_minorVersion, (const char*)%s(GL_VERSION));\n", strFunc)
 		hFile:write "\n"
 		
 		--Load extensions in different ways, based on version.
 		hFile:write "{\n"
 		hFile:inc()
 		--Load the file from a list of extensions. We already have the string getter.
-		hFile:fmt("ProcExtsFromExtString((const char*)%s());\n", strFunc)
+		hFile:fmt("ProcExtsFromExtString((const char*)%s(GL_EXTENSIONS));\n", strFunc)
 		hFile:dec()
 		hFile:write "}\n"
 		hFile:write "else\n"
 if(g_majorVersion >= 3)
 {
 	if(g_majorVersion == 3 && g_minorVersion == 0)
-	{ //Deliberately empty. Core/compatibility didn't exist til 3.1.
+	{ /*Deliberately empty. Core/compatibility didn't exist til 3.1.*/
 	}
 	else if(g_majorVersion == 3 && g_minorVersion == 1)
 	{
 
 		hFile:fmtblock([[
 numFailed = LoadVersionFromMap(g_majorVersion, g_minorVersion, compProfile);
-if(numFailed == 0)
+if(numFailed == -1) /*Couldn't find something to load.*/
 {
-	//Unable to find a compatible one. Load max version+compatibility.
-	numFailed = LoadVersionFromMap(4, 3, compProfile);
+	/*Unable to find a compatible one. Load max version+compatibility.*/
+	numFailed = LoadVersionFromMap(%i, %i, 1);
+	if(numFailed == -1) /*Couldn't even load it.*/
+		return %sLOAD_FAILED;
 }
 
-return numFailed;
-]], major, minor)
+return %sLOAD_SUCCEEDED + numFailed;
+]], major, minor, spec.DeclPrefix(), spec.DeclPrefix())
 		
 	else
 		hFile:fmt("return %s;\n", spec.DeclPrefix() .. "LOAD_SUCCEEDED")

File modules/glload_util.lua

 data.headerDirectory = ""
 data.sourceDirectory = ""
 
+function data.GetLoaderBasename(spec, options)
+	return spec.FilePrefix() .. "load.h"
+end
+
 function data.GetVersionCoreBasename(version, spec, options)
-	return spec.FilePrefix() .. version .. ".h"
+	return spec.FilePrefix() .. version:gsub("%.", "_") .. ".h"
 end
 
 function data.GetVersionCompBasename(version, spec, options)
-	return spec.FilePrefix() .. version .. "_comp.h"
+	return spec.FilePrefix() .. version:gsub("%.", "_") .. "_comp.h"
 end
 
 function data.GetAllBasename(spec, options)
 end
 
 function data.GetCoreHeaderBasename(version, spec, options)
-	return data.internalPrefix .. spec.FilePrefix() .. version .. ".h"
+	return data.internalPrefix .. spec.FilePrefix() .. version:gsub("%.", "_") .. ".h"
 end
 
 function data.GetRemHeaderBasename(version, spec, options)
-	return data.internalPrefix .. spec.FilePrefix() .. version .. "_rem.h"
+	return data.internalPrefix .. spec.FilePrefix() .. version:gsub("%.", "_") .. "_rem.h"
 end
 
 function data.GetExtVariableName(extName, spec, options)
 	return [[
 #ifdef __cplusplus
 extern "C" {
-#endif //__cplusplus
+#endif /*__cplusplus*/
 ]]
 end
 
 	return [[
 #ifdef __cplusplus
 }
-#endif //__cplusplus
+#endif /*__cplusplus*/
 ]]
 end
 
 	hFile:write("}\n")
 end
 
-function data.GetClearExtVarsFuncName(spec, options)
-	return "ClearExtensionVariables"
-end
-
 function data.GetLoadExtensionFuncName(extName, spec, options)
 	return "LoadExt_" .. extName
 end
 **/
 int $<prefix>GetMinorVersion();
 
-///Returns non-zero if the current GL version is greater than or equal to the given version.
+/**Returns non-zero if the current GL version is greater than or equal to the given version.**/
 int $<prefix>IsVersionGEQ(int testMajorVersion, int testMinorVersion);
 ]=],
 }
 
 **/
 
-///\addtogroup module_glload_cinter
-///@{
+/**\addtogroup module_glload_cinter**/
+/**@{**/
 
 /**
 \brief The loading status returned by the loading functions.
 **/
 enum
 {
-	$<prefix>LOAD_FAILED = 0;
-	$<prefix>LOAD_SUCCEEDED = 0;
+	$<prefix>LOAD_FAILED = 0,
+	$<prefix>LOAD_SUCCEEDED,
 };
 
 #ifdef __cplusplus
 extern "C" {
-#endif //__cplusplus
+#endif /*__cplusplus*/
 
 /**
 \brief Loads all of the function pointers available.
 int $<prefix>LoadFunctions($<params>);
 
 $<extra>
-///@}
+/**@}**/
 
 #ifdef __cplusplus
 }
-#endif //__cplusplus
+#endif /*__cplusplus*/
 ]=]
 
 function data.GetLoaderHeaderString(spec, options)

File test/premake4.lua

 	files {"*.c"}
 	files {"*.hpp"}
 	files {"*.h"}
+	
+	files {"glload/*.cpp"}
+	files {"glload/*.c"}
+	files {"glload/*.hpp"}
+	files {"glload/*.h"}
 
 	UseLibs {"freeglut"}
 	

File test/test.cpp

 #include <stdio.h>
 #include <stdlib.h>
 
-#include "gl_test.h"
+#include "glload/gl_4_3.h"
+#include "glload/gl_load.h"
+#include "glload/wgl_all.h"
+#include "glload/wgl_load.h"
 #include <GL/freeglut.h>
 
 GLuint positionBufferObject;
 
 	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
 
-	ogl_LoadFunctions();
+	int numFailed = ogl_LoadFunctions();
+	printf("OpenGL: %i\n", numFailed);
 
 	init();
 
+	HDC hdc = wglGetCurrentDC();
+	numFailed = wgl_LoadFunctions(hdc);
+	printf("WGL: %i\n", numFailed);
+
 	glutDisplayFunc(display); 
 	glutReshapeFunc(reshape);
 	glutKeyboardFunc(keyboard);