Commits

Jason McKesson committed 412e072

Fixed a major bug in the loag generator.
Ported StylePointerC to structure system.

Comments (0)

Files changed (6)

 local status, options = pcall(opts.GetOptions, arg)
 
 if(not status) then
+	io.write(options, "\n")
 	return
 end
 

modules/CmdLineOptions.lua

 	if(not test) then
 		io.stdout:write(msg, "\n")
 		self:DisplayHelp()
-		error("")
+		error("", 0)
 	end
 end
 

modules/CommonStyle.lua

 	{ type="file", style="header", name="GetFilename",
 		{ type="block", name="IncludeGuard(hFile, spec, options)",
 			{ type="blank"},
+			{ type="write", name="Init(hFile, spec, options)", },
+			{ type="blank"},
 			{ type="write", name="StdTypedefs(hFile, specData, options)",},
 			{ type="blank"},
 			{ type="write", name="SpecTypedefs(hFile, specData, options)",},
 	{ type="file", style="source", name="GetFilename",
 		{ type="write", name="Includes(hFile, basename, spec, options)",},
 		{ type="blank"},
+		{ type="write", name="LoaderData(hFile, spec, options)",},
+		{ type="blank"},
 		{ type="block", name="Def(hFile, spec, options)",
 			{ type="block", name="ExtVarDef(hFile, spec, options)",
 				{ type="ext-iter",
 							},
 						},
 					},
+					{ type="blank"},
 				},
+				{ type="write", name="ExtStringFuncDef(hFile, specData, spec, options, funcSeen)"},
 			},
 			{ type="block", name="SysDef(hFile, spec, options)",
 				{ type="write", name="UtilityDefs(hFile, specData, spec, options)",},

modules/GetOptions.lua

 		parseOpts:AssertParse(versionTest[options.version], "The version " .. options.version .. " is not a legal version number.")
 	else
 		--Check to see that no versions are offered.
-		parseOpts:AssertParse(#spec.GetCoreVersions() == 0, "You cannot specify a version for the specification " .. options.spec)
+		parseOpts:AssertParse(#spec.GetCoreVersions() == 0, "You must specify a version for the specification " .. options.spec)
 	end
 	
 	spec.VerifyOptions(options, parseOpts)
 	--Load and collate the extensions.
 	options.extensions = options.extensions or {}
 	options.extfiles = options.extfiles or {}
+	options.stdexts = options.stdexts or {}
 	
 	for _, file in ipairs(options.extfiles) do
 		LoadExtFile(options.extensions, util.ParsePath(file)) --vararg

modules/StylePointerC.lua

 
 local common = require "CommonStyle"
 local struct = require "Structure"
+local util = require "util"
 
 
 local my_style = {}
 	hFile:fmt("#endif //%s\n", inclGuard)
 end
 
+function my_style.header.WriteInit(hFile, spec, options)
+	hFile:rawwrite(spec.GetHeaderInit())
+end
+
 function my_style.header.WriteStdTypedefs(hFile, specData, options)
 	local defArray = common.GetStdTypedefs()
 	
 #define strcasecmp(lhs, rhs) _stricmp((lhs), (rhs))
 #endif
 ]])
-	hFile:fmt('#include "%s"\n', my_style.source.GetFilename(basename, options))
-	
+	local base = util.ParsePath(my_style.header.GetFilename(basename, options))
+	hFile:fmt('#include "%s"\n', base)
+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
 
 function my_style.source.WriteGetExtStringFuncDef(hFile, func, typemap, spec, options)
-	hFile:fmt("static %s = NULL;\n",
-		GetFuncPtrDef(hFile, func, typemap, spec, options))
+end
+
+
+
+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")
+		hFile:fmt("static %s = NULL;\n",
+			GetFuncPtrDef(hFile, extStringFunc, specData.typemap, spec, options))
+		hFile:write("\n")
+	end
 end
 
 local function GetMapTableStructName(spec, options)
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "gl_test_cpp.hpp"
-#include "wgl_test_cpp.hpp"
+#include "gl_test.h"
 #include <GL/freeglut.h>
 
 GLuint positionBufferObject;
 
 GLuint BuildShader(GLenum eShaderType, const std::string &shaderText)
 {
-	GLuint shader = gl::CreateShader(eShaderType);
+	GLuint shader = glCreateShader(eShaderType);
 	const char *strFileData = shaderText.c_str();
-	gl::ShaderSource(shader, 1, &strFileData, NULL);
+	glShaderSource(shader, 1, &strFileData, NULL);
 
-	gl::CompileShader(shader);
+	glCompileShader(shader);
 
 	GLint status;
-	gl::GetShaderiv(shader, gl::COMPILE_STATUS, &status);
-	if(!status)
+	glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
+	if (status == GL_FALSE)
 	{
 		GLint infoLogLength;
-		gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &infoLogLength);
+		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
 
 		GLchar *strInfoLog = new GLchar[infoLogLength + 1];
-		gl::GetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
+		glGetShaderInfoLog(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()
 {
-	gl::GenVertexArrays(1, &vao);
-	gl::BindVertexArray(vao);
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
 
 	const float vertexPositions[] = {
 		0.75f, 0.75f, 0.0f, 1.0f,
 		-0.75f, -0.75f, 0.0f, 1.0f,
 	};
 
-	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);
+	glGenBuffers(1, &positionBufferObject);
+	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
+	glBindBuffer(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 = gl::CreateProgram();
-	gl::AttachShader(program, vertShader);
-	gl::AttachShader(program, fragShader);	
-	gl::LinkProgram(program);
+	program = glCreateProgram();
+	glAttachShader(program, vertShader);
+	glAttachShader(program, fragShader);	
+	glLinkProgram(program);
 
 	GLint status;
-	gl::GetProgramiv (program, gl::LINK_STATUS, &status);
-	if(!status)
+	glGetProgramiv (program, GL_LINK_STATUS, &status);
+	if (status == GL_FALSE)
 	{
 		GLint infoLogLength;
-		gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &infoLogLength);
+		glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
 
 		GLchar *strInfoLog = new GLchar[infoLogLength + 1];
-		gl::GetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
+		glGetProgramInfoLog(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()
 {
-	gl::ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-	gl::Clear(gl::COLOR_BUFFER_BIT);
+	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+	glClear(GL_COLOR_BUFFER_BIT);
 
-	gl::UseProgram(program);
+	glUseProgram(program);
 
-	gl::BindBuffer(gl::ARRAY_BUFFER, positionBufferObject);
-	gl::EnableVertexAttribArray(0);
-	gl::VertexAttribPointer(0, 4, gl::FLOAT, gl::FALSE_, 0, 0);
+	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
 
-	gl::DrawArrays(gl::TRIANGLES, 0, 3);
+	glDrawArrays(GL_TRIANGLES, 0, 3);
 
-	gl::DisableVertexAttribArray(0);
-	gl::UseProgram(0);
+	glDisableVertexAttribArray(0);
+	glUseProgram(0);
 
 	glutSwapBuffers();
 }
 //This is an opportunity to call glViewport or glScissor to keep up with the change in size.
 void reshape (int w, int h)
 {
-	gl::Viewport(0, 0, (GLsizei) w, (GLsizei) h);
+	glViewport(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);
 
-	gl::exts::LoadTest test = gl::sys::LoadFunctions();
-
-	if(test)
-		printf("%i\n", test.GetNumMissing());
-	else
-		return 1;
+	ogl_LoadFunctions();
 
 	init();