Commits

Jason McKesson  committed 3c581f5

pointer_cpp now ported to struct. Ready to delete the old way.

  • Participants
  • Parent commits 1839a92

Comments (0)

Files changed (5)

File modules/CommonStyle.lua

 				{ type="blank" },
 				{ type="write", name="MainLoaderFunc(hFile, specData, spec, options)",},
 				{ type="blank" },
-				{ type="write", name="VersioningFuncs(hFile, specData, spec, options)",},
-				{ type="blank" },
+				{ type="write", name="VersioningFuncs(hFile, specData, spec, options)", cond="version-iter"},
+				{ type="blank", cond="version-iter" },
 			},
 		},
 	},

File modules/StylePointerC.lua

 	end
 end
 
-function my_style.header.WriteEnumPrevDecl(hFile, enum, enumTable, spec, options, extName)
-	hFile:fmt("/*Copied %s%s From: %s*/\n",
-		spec.EnumNamePrefix(),
-		enum.name,
-		extName)
-end
-
 function my_style.header.WriteBlockBeginFuncDecl(hFile, specData, options)
 end
 
 
 function my_style.source.WriteLoaderData(hFile, spec, options)
 	hFile:writeblock(spec.GetLoaderFunc())
-	hFile:write("\n")
 end
 
 function my_style.source.WriteBlockBeginDef(hFile, spec, options) end
 	end
 end
 
-function my_style.source.WriteGetExtStringFuncDef(hFile, func, typemap, spec, options)
-end
-
-
-
 function my_style.source.WriteExtStringFuncDef(hFile, specData, spec, options, funcSeen)
 	if(funcSeen[spec.GetExtStringFuncName()]) then
 		return
 end
 
 function my_style.source.WriteVersioningFuncs(hFile, specData, spec, options)
-	--Only for GL
-	if(options.spec ~= "gl") then
-		return
-	end
-	
 	hFile:fmt("static int g_major_version = 0;\n")
 	hFile:fmt("static int g_minor_version = 0;\n")
 	hFile:write "\n"

File modules/StylePointerCPP.lua

 
 local common = require "CommonStyle"
+local util = require "util"
 
 local my_style = {}
 my_style.header = {}
 ------------------------------------------------------
 -- Header styling functions
 
-function my_style.header.CreateFile(basename, options)
-	local filename = basename .. ".hpp"
-	return common.CreateFile(filename, options.indent), filename
+function my_style.header.GetFilename(basename, options)
+	return basename .. ".hpp"
 end
 
 	local function GenIncludeGuardName(hFile, spec, options)
 		return str
 	end
 
-function my_style.header.WriteBeginIncludeGuard(hFile, spec, options)
+function my_style.header.WriteBlockBeginIncludeGuard(hFile, spec, options)
 	local inclGuard = GenIncludeGuardName(hFile, spec, options)
 	
 	hFile:fmt("#ifndef %s\n", inclGuard)
 	hFile:fmt("#define %s\n", inclGuard)
 end
 
-function my_style.header.WriteEndIncludeGuard(hFile, spec, options)
+function my_style.header.WriteBlockEndIncludeGuard(hFile, spec, options)
 	hFile:fmt("#endif //%s\n", GenIncludeGuardName(hFile, spec, options))
 end
 
+function my_style.header.WriteInit(hFile, spec, options)
+	hFile:rawwrite(spec.GetHeaderInit())
+end
+
 function my_style.header.WriteStdTypedefs(hFile, specData, spec, options)
 	local defArray = common.GetStdTypedefs()
 	hFile:write("#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS\n")
 		hFile:fmt("} //namespace %s\n", namespaceName or "")
 	end
 
-function my_style.header.WriteBeginDecl(hFile, spec, options)
+function my_style.header.WriteBlockBeginDecl(hFile, spec, options)
 	if(#options.prefix > 0) then
 		StartNamespace(hFile, options.prefix)
 	end
 	StartNamespace(hFile, spec.FuncNamePrefix())
 end
 
-function my_style.header.WriteEndDecl(hFile, spec, options)
+function my_style.header.WriteBlockEndDecl(hFile, spec, options)
 	EndNamespace(hFile, spec.FuncNamePrefix())
 	if(#options.prefix > 0) then
 		EndNamespace(hFile, options.prefix)
 };
 ]]
 
-function my_style.header.WriteBeginExtVarDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockBeginExtVarDecl(hFile, spec, options)
 	StartNamespace(hFile, extBlockNamespace)
 	hFile:writeblock(extVariableTypeDefinition)
 	hFile:write("\n")
 end
 
-function my_style.header.WriteEndExtVarDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockEndExtVarDecl(hFile, spec, options)
 	EndNamespace(hFile, extBlockNamespace)
 end
 
 		GenExtensionVarName(extName, spec, options));
 end
 
-function my_style.header.WriteBeginEnumDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockBeginEnumDecl(hFile, spec, options)
 	hFile:write("enum\n")
 	hFile:write("{\n")
 	hFile:inc()
 end
 
-function my_style.header.WriteEndEnumDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockEndEnumDecl(hFile, spec, options)
 	hFile:dec()
 	hFile:write("};\n")
 end
 		return enumName
 	end
 
-function my_style.header.WriteEnumDecl(hFile, enum, enumTable, spec, options)
-	local enumName = GenEnumName(enum)
-	local lenEnum = #enumName
-	local numIndent = 33
+function my_style.header.WriteEnumDecl(hFile, enum, enumTable, spec, options,
+	enumSeen)
+	if(enumSeen[enum.name]) then
+		hFile:fmt("//%s taken from ext: %s\n", enum.name, extName)
+	else
 	
-	local numSpaces = numIndent - lenEnum
-	if(numSpaces < 1) then
-		numSpaces = 1
+		local enumName = GenEnumName(enum)
+		local lenEnum = #enumName
+		local numIndent = 33
+		
+		local numSpaces = numIndent - lenEnum
+		if(numSpaces < 1) then
+			numSpaces = 1
+		end
+
+		hFile:fmt("%s%s= %s,\n",
+			enumName,
+			string.rep(" ", numSpaces),
+			common.ResolveEnumValue(enum, enumTable))
 	end
-
-	hFile:fmt("%s%s= %s,\n",
-		enumName,
-		string.rep(" ", numSpaces),
-		common.ResolveEnumValue(enum, enumTable))
 end
 
-function my_style.header.WriteEnumPrevDecl(hFile, enum, enumTable, spec, options, extName)
-	hFile:fmt("//%s taken from ext: %s\n", enum.name, extName)
-end
-
-function my_style.header.WriteBeginFuncDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockBeginFuncDecl(hFile, spec, options)
 	--Block containing all spec function declarations.
 end
 
-function my_style.header.WriteEndFuncDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockEndFuncDecl(hFile, spec, options)
 	--Block containing all spec function declarations.
 end
 
-function my_style.header.WriteBeginExtFuncDeclBlock(hFile, extName, spec, options)
+function my_style.header.WriteBlockBeginExtFuncDecl(hFile, extName, spec, options)
 	--Block containing all spec function declarations for a particular extension.
 	--Useful for include-guards around extension function pointers.
 end
 
-function my_style.header.WriteEndExtFuncDeclBlock(hFile, extName, spec, options)
+function my_style.header.WriteBlockEndExtFuncDecl(hFile, extName, spec, options)
 	--Block containing all spec function declarations for a particular extension.
 end
 
 		";\n")
 end
 
-function my_style.header.WriteBeginSysDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockBeginSysDecl(hFile, spec, options)
 	StartNamespace(hFile, "sys")
 end
 
-function my_style.header.WriteEndSysDeclBlock(hFile, spec, options)
+function my_style.header.WriteBlockEndSysDecl(hFile, spec, options)
 	EndNamespace(hFile, "sys")
 end
 
 
 --------------------------------------------------
 -- Source code styling functions.
-function my_style.source.CreateFile(basename, options)
-	return common.CreateFile(basename .. ".cpp", options.indent)
+function my_style.source.GetFilename(basename, options)
+	return basename .. ".cpp"
 end
 
-function my_style.source.WriteIncludes(hFile, spec, options)
+function my_style.source.WriteIncludes(hFile, basename, spec, options)
 	hFile:writeblock([[
 #include <algorithm>
 #include <vector>
 #include <string.h>
-#ifdef _MSC_VER
-#endif
 ]])
+
+	local base = util.ParsePath(my_style.header.GetFilename(basename, options))
+	hFile:fmt('#include "%s"\n', base)
 end
 
-function my_style.source.WriteBeginDef(hFile, spec, options)
+function my_style.source.WriteLoaderData(hFile, spec, options)
+	hFile:writeblock(spec.GetLoaderFunc())
+end
+
+function my_style.source.WriteBlockBeginDef(hFile, spec, options)
 	if(#options.prefix > 0) then
 		StartNamespace(hFile, options.prefix)
 	end
 	StartNamespace(hFile, spec.FuncNamePrefix())
 end
 
-function my_style.source.WriteEndDef(hFile, spec, options)
+function my_style.source.WriteBlockEndDef(hFile, spec, options)
 	EndNamespace(hFile, spec.FuncNamePrefix())
 	if(#options.prefix > 0) then
 		EndNamespace(hFile, options.prefix)
 	end
 end
 
-function my_style.source.WriteBeginExtVarDefBlock(hFile, spec, options)
+function my_style.source.WriteBlockBeginExtVarDef(hFile, spec, options)
 	StartNamespace(hFile, extBlockNamespace)
 end
 
-function my_style.source.WriteEndExtVarDefBlock(hFile, spec, options)
+function my_style.source.WriteBlockEndExtVarDef(hFile, spec, options)
 	EndNamespace(hFile, extBlockNamespace)
 end
 
 		GenExtensionVarName(extName, spec, options));
 end
 
-function my_style.source.WriteBeginExtFuncDefBlock(hFile, extName, spec, options)
+function my_style.source.WriteBlockBeginExtFuncDef(hFile, extName, spec, options)
 	--Block containing the extension function definitions and load function
 	--for the functions in the extension `extName`.
 end
 
-function my_style.source.WriteEndExtFuncDefBlock(hFile, extName, spec, options)
+function my_style.source.WriteBlockEndExtFuncDef(hFile, extName, spec, options)
 	--Block containing the extension function definitions and load function
 	--for the functions in the extension `extName`.
 end
 		return "Load_" .. extName;
 	end
 
-function my_style.source.WriteBeginExtLoaderBlock(hFile, extName, spec, options)
+function my_style.source.WriteBlockBeginExtLoader(hFile, extName, spec, options)
 	hFile:fmt("static int %s()\n", GenExtLoaderFuncName(extName, spec, options))
 	hFile:write("{\n")
 	hFile:inc()
 	hFile:write("int numFailed = 0;\n")
 end
 
-function my_style.source.WriteEndExtLoaderBlock(hFile, extName, spec, options)
+function my_style.source.WriteBlockEndExtLoader(hFile, extName, spec, options)
 	hFile:write "return numFailed;\n"
 	hFile:dec()
 	hFile:write("}\n")
 	hFile:fmt('if(!%s) ++numFailed;\n', GenFuncPtrName(func, spec, options))
 end
 
-function my_style.source.WriteBeginCoreFuncDefBlock(hFile, version, spec, options)
+function my_style.source.WriteBlockBeginCoreFuncDef(hFile, version, spec, options)
 	--Block containing the core functions for `version`.
 	--The block also contains the loading function for this version.
 end
 
-function my_style.source.WriteEndCoreFuncDefBlock(hFile, version, spec, options)
+function my_style.source.WriteBlockEndCoreFuncDef(hFile, version, spec, options)
 	--Block containing the core functions for `version`.
 end
 
-function my_style.source.WriteGetExtStringFuncDef(hFile, func, typemap,
-	spec, options)
-	WriteFuncPtrTypedefStmt(hFile, func, typemap, spec, options)
-	hFile:write("static ", GenFuncPtrDefTypedef(func, typemap, spec, options),
-		" = 0;\n")
-end
-
 	local function GenCoreLoaderFuncName(version, spec, options)
 		return "LoadCoreFunctions"
 	end
 
-function my_style.source.WriteBeginCoreLoaderBlock(hFile, version, spec, options)
+function my_style.source.WriteBlockBeginCoreLoader(hFile, version, spec, options)
 	hFile:fmt("static int %s()\n", GenCoreLoaderFuncName(version, spec, options))
 	hFile:write("{\n")
 	hFile:inc()
 
 end
 
-function my_style.source.WriteEndCoreLoaderBlock(hFile, version, spec, options)
+function my_style.source.WriteBlockEndCoreLoader(hFile, version, spec, options)
 	hFile:write "return numFailed;\n"
 	hFile:dec()
 	hFile:write("}\n")
 	end
 end
 
-function my_style.source.WriteBeginSysDefBlock(hFile, spec, options)
+function my_style.source.WriteExtStringFuncDef(hFile, specData, spec, options, funcSeen)
+	if(funcSeen[spec.GetExtStringFuncName()]) then
+		return
+	end
+	
+	--Check to see if its something we have to load.
+	local function FindFuncName(funcName)
+		for _, func in ipairs(specData.funcData.functions) do
+			if(func.name == funcName) then
+				return func
+			end
+		end
+		
+		return nil
+	end
+	
+	local extStringFunc = FindFuncName(spec.GetExtStringFuncName())
+
+	if(extStringFunc) then
+		hFile:write("\n")
+		local typemap = specData.typemap
+		WriteFuncPtrTypedefStmt(hFile, extStringFunc, typemap, spec, options)
+		hFile:write("static ", GenFuncPtrDefTypedef(extStringFunc, typemap, spec, options),
+			" = 0;\n")
+		hFile:write("\n")
+	end
+end
+
+function my_style.source.WriteBlockBeginSysDef(hFile, spec, options)
 	StartNamespace(hFile, "sys")
 end
 
-function my_style.source.WriteEndSysDefBlock(hFile, spec, options)
+function my_style.source.WriteBlockEndSysDef(hFile, spec, options)
 	EndNamespace(hFile, "sys")
 end
 
 -- Style retrieval machinery
 
 local function Create()
-	return common.DeepCopyTable(my_style)
+	return common.DeepCopyTable(my_style), common.GetStandardStructure()
 end
 
 return { Create = Create }

File modules/util.lua

 	
 	if(not status) then return end
 	
-	local mode = lfs.attributes(path, "mode")
+	--strip the last directory separator off.
+	path = path:match("^(.+)[/\\]$")
+	
+	local mode, err = lfs.attributes(path, "mode")
 	if(not mode) then
 		local creates = {}
 		local currPath = path
 		repeat
 			table.insert(creates, 1, currPath)
-			currPath = currPath:match("(.*[/\\])[^/\\]*[/\\]$")
+			currPath = currPath:match("(.*[/\\])[^/\\]*$")
+			print(currPath)
 			if(currPath) then
-				mode = lfs.attributes(currPath, "mode")
+				currPath = currPath:match("^(.+)[/\\]$")
+				print(currPath)
+				mode, err = lfs.attributes(currPath, "mode")
 			end
 		until(mode or currPath == nil)
 		
 		for _, newDir in ipairs(creates) do
+			print(newDir)
 			assert(lfs.mkdir(newDir))
 		end
 	end

File test/test.cpp

 #include <stdio.h>
 #include <stdlib.h>
 
-#include "glload/gl_4_3.h"
-#include "glload/gl_load.h"
-//#include "glload/wgl_all.h"
-//#include "glload/wgl_load.h"
+#include "gl_test.hpp"
+#include "wgl_test.hpp"
 #include <GL/freeglut.h>
 
 GLuint positionBufferObject;
 
 GLuint BuildShader(GLenum eShaderType, const std::string &shaderText)
 {
-	GLuint shader = glCreateShader(eShaderType);
+	GLuint shader = gl::CreateShader(eShaderType);
 	const char *strFileData = shaderText.c_str();
-	glShaderSource(shader, 1, &strFileData, NULL);
+	gl::ShaderSource(shader, 1, &strFileData, NULL);
 
-	glCompileShader(shader);
+	gl::CompileShader(shader);
 
 	GLint status;
-	glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
-	if (status == GL_FALSE)
+	gl::GetShaderiv(shader, gl::COMPILE_STATUS, &status);
+	if (status == gl::FALSE_)
 	{
 		GLint infoLogLength;
-		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
+		gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &infoLogLength);
 
 		GLchar *strInfoLog = new GLchar[infoLogLength + 1];
-		glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
+		gl::GetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
 
 		const char *strShaderType = NULL;
 		switch(eShaderType)
 		{
-		case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
-//		case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
-		case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
+		case gl::VERTEX_SHADER: strShaderType = "vertex"; break;
+//		case gl::GEOMETRY_SHADER: strShaderType = "geometry"; break;
+		case gl::FRAGMENT_SHADER: strShaderType = "fragment"; break;
 		}
 
 		fprintf(stderr, "Compile failure in %s shader:\n%s\n", strShaderType, strInfoLog);
 
 void init()
 {
-	glGenVertexArrays(1, &vao);
-	glBindVertexArray(vao);
+	gl::GenVertexArrays(1, &vao);
+	gl::BindVertexArray(vao);
 
 	const float vertexPositions[] = {
 		0.75f, 0.75f, 0.0f, 1.0f,
 		-0.75f, -0.75f, 0.0f, 1.0f,
 	};
 
-	glGenBuffers(1, &positionBufferObject);
-	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
-	glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
-	glBindBuffer(GL_ARRAY_BUFFER, 0);
+	gl::GenBuffers(1, &positionBufferObject);
+	gl::BindBuffer(gl::ARRAY_BUFFER, positionBufferObject);
+	gl::BufferData(gl::ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, gl::STATIC_DRAW);
+	gl::BindBuffer(gl::ARRAY_BUFFER, 0);
 
 	const std::string vertexShader(
 		"#version 330\n"
 		"}\n"
 		);
 
-	GLuint vertShader = BuildShader(GL_VERTEX_SHADER, vertexShader);
-	GLuint fragShader = BuildShader(GL_FRAGMENT_SHADER, fragmentShader);
+	GLuint vertShader = BuildShader(gl::VERTEX_SHADER, vertexShader);
+	GLuint fragShader = BuildShader(gl::FRAGMENT_SHADER, fragmentShader);
 
-	program = glCreateProgram();
-	glAttachShader(program, vertShader);
-	glAttachShader(program, fragShader);	
-	glLinkProgram(program);
+	program = gl::CreateProgram();
+	gl::AttachShader(program, vertShader);
+	gl::AttachShader(program, fragShader);	
+	gl::LinkProgram(program);
 
 	GLint status;
-	glGetProgramiv (program, GL_LINK_STATUS, &status);
-	if (status == GL_FALSE)
+	gl::GetProgramiv (program, gl::LINK_STATUS, &status);
+	if (status == gl::FALSE_)
 	{
 		GLint infoLogLength;
-		glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
+		gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &infoLogLength);
 
 		GLchar *strInfoLog = new GLchar[infoLogLength + 1];
-		glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
+		gl::GetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
 		fprintf(stderr, "Linker failure: %s\n", strInfoLog);
 		delete[] strInfoLog;
 
 //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
 void display()
 {
-	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-	glClear(GL_COLOR_BUFFER_BIT);
+	gl::ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+	gl::Clear(gl::COLOR_BUFFER_BIT);
 
-	glUseProgram(program);
+	gl::UseProgram(program);
 
-	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
-	glEnableVertexAttribArray(0);
-	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
+	gl::BindBuffer(gl::ARRAY_BUFFER, positionBufferObject);
+	gl::EnableVertexAttribArray(0);
+	gl::VertexAttribPointer(0, 4, gl::FLOAT, gl::FALSE_, 0, 0);
 
-	glDrawArrays(GL_TRIANGLES, 0, 3);
+	gl::DrawArrays(gl::TRIANGLES, 0, 3);
 
-	glDisableVertexAttribArray(0);
-	glUseProgram(0);
+	gl::DisableVertexAttribArray(0);
+	gl::UseProgram(0);
 
 	glutSwapBuffers();
 }
 
 //Called whenever the window is resized. The new window size is given, in pixels.
-//This is an opportunity to call glViewport or glScissor to keep up with the change in size.
+//This is an opportunity to call gl::Viewport or gl::Scissor to keep up with the change in size.
 void reshape (int w, int h)
 {
-	glViewport(0, 0, (GLsizei) w, (GLsizei) h);
+	gl::Viewport(0, 0, (GLsizei) w, (GLsizei) h);
 }
 
 //Called whenever a key on the keyboard was pressed.
 
 	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
 
-	int numFailed = ogl_LoadFunctions();
-	printf("OpenGL: %i\n", numFailed);
+	gl::exts::LoadTest didLoad = gl::sys::LoadFunctions();
+	if(!didLoad)
+		printf("OpenGL: %i\n", didLoad.GetNumMissing());
+	else
+		printf("OpenGL Loaded!\n");
 
 	init();
 
-//	HDC hdc = wglGetCurrentDC();
-//	numFailed = wgl_LoadFunctions(hdc);
-//	printf("WGL: %i\n", numFailed);
+	HDC hdc = wglGetCurrentDC();
+	wgl::exts::LoadTest load = wgl::sys::LoadFunctions(hdc);
+	if(!load)
+		printf("WGL: %i\n", load.GetNumMissing());
+	else
+		printf("WGL Loaded!\n");
 
 	glutDisplayFunc(display); 
 	glutReshapeFunc(reshape);