Commits

Jason McKesson committed 3905ae1

glload: Fixed things so that C or C++ loaders will get function pointers for the other.

Comments (0)

Files changed (9)

docs/Command_Line_Options.xml

                 <para>It must be one of the following values:</para>
                 <itemizedlist>
                     <listitem>
-                        <para><literal>pointer_c</literal>: default.</para>
+                        <para><link xlink:href="Style_Pointer_C"
+                            ><literal>pointer_c</literal></link>: Used for C-style header
+                            generation.</para>
+                    </listitem>
+                    <listitem>
+                        <para><link xlink:href="Style_Pointer_CPP"
+                                ><literal>pointer_cpp</literal></link>: Used for creating C++-style
+                            loaders, wrapping as much as possible in namespaces.</para>
+                    </listitem>
+                    <listitem>
+                        <para><link xlink:href="Style_No_Load_CPP"
+                                ><literal>noload_cpp</literal></link>: Used for creating C++-style
+                            loaders that you don't need to call an initialization function on to get
+                            function pointers.</para>
+                    </listitem>
+                    <listitem>
+                        <para><link><literal xlink:href="Style_GL_Load">glload</literal></link>: Do
+                            not use.</para>
                     </listitem>
                 </itemizedlist>
             </glossdef>

docs/Load Docs.xpr

         <file name="Home.xml"/>
         <file name="Structure_Reference.xml"/>
         <file name="Style_Creation.xml"/>
+        <file name="Style_No_Load_CPP.xml"/>
         <file name="Style_Pointer_C.xml"/>
         <file name="Style_Pointer_CPP.xml"/>
         <file name="Styles.xml"/>

docs/Style_GL_Load.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<?oxygen RNGSchema="http://docbook.org/xml/5.0/rng/docbookxi.rng" type="xml"?>
+<?oxygen SCHSchema="http://docbook.org/xml/5.0/rng/docbookxi.rng"?>
+<article xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"
+    xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
+    <title>Style GL Load</title>
+    <para>Reserved for future use.</para>
+</article>

docs/Style_No_Load_CPP.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<?oxygen RNGSchema="http://docbook.org/xml/5.0/rng/docbookxi.rng" type="xml"?>
+<?oxygen SCHSchema="http://docbook.org/xml/5.0/rng/docbookxi.rng"?>
+<article xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"
+    xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
+    <title>Style No Load</title>
+    <para>The <literal>noload_cpp</literal> style works a lot like the near-defunct GLee loader. You
+        don't need to call a function to load all of the function pointers; instead, you simply call
+        the GL functions as normal. If it hasn't been loaded, it will be. This makes it among the
+        most user-friendly of the loader styles.</para>
+    <para>As a C++ style, it follows the naming conventions of the <link><literal
+                xlink:href="Style_Pointer_CPP">pointer_cpp</literal></link> style. Everything is
+        scoped into namespaces. The enumerators don't have the <literal>GL_</literal> prefix on
+        them, and so forth.</para>
+    <para>The main difference is this. <literal>noload_cpp</literal> does have a system function
+        called <literal>sys::CheckExtensions</literal>. This function walks through the list of
+        advertised extensions and sets up the extension variables. It does not load anything, so
+        there is no way to tell if all of the function pointers that are advertised are actually
+        available.</para>
+</article>
                     Used for creating C++-style loaders, wrapping as much as possible in
                     namespaces.</para>
             </listitem>
+            <listitem>
+                <para><link xlink:href="Style_No_Load_CPP"><literal>noload_cpp</literal></link>:
+                    Used for creating C++-style loaders that you don't need to call an
+                    initialization function on to get function pointers.</para>
+            </listitem>
         </itemizedlist>
     </section>
     <section>

modules/StructGLLoad.lua

 		{ type="blank", },
 	},
 	--Loaders et. al.
+	{type="write", name="CopierC(hFile, specData, spec, options)", },
+	{ type="blank", },
+
 	{ type="block", name="SystemDefs(hFile, spec, options)",
 		{ type="write", name="MainLoader(hFile, specData, spec, options)", },
 		{ type="blank", },

modules/StyleGLLoad.lua

 	end
 	hFile:write "\n"
 	hFile:writeblock(common.GetProcessExtsFromStringFunc("LoadExtByName(%s)"))
+	
+	hFile:write "\n"
+	hFile:fmt("void %sCopyFromC();\n", spec.DeclPrefix())
 end
 
 function source.WriteMainLoader(hFile, specData, spec, options)
 		hFile:write "\n"
 	end
 
-	hFile:fmt("int %sLoadFunctions(%s)\n", spec.DeclPrefix(), spec.GetLoaderParams())
+	hFile:fmt("static int InternalLoad(%s)\n", spec.GetLoaderParams())
 	hFile:write "{\n"
 	hFile:inc()
 	
 	
 	hFile:dec()
 	hFile:write "}\n"
+	
+	hFile:write "\n"
+	
+	hFile:fmt("int %sLoadFunctions(%s)\n", spec.DeclPrefix(), spec.GetLoaderParams())
+	hFile:write "{\n"
+	hFile:inc()
+	hFile:fmtblock(
+[[int numFailed = 0;
+numFailed = InternalLoad(%s);
+]],
+		spec.GetExtStringParamList(function() return "" end))
+	--Call CPP loader.
+	hFile:fmt("%sCopyFromC();\n", spec.DeclPrefix())
+	hFile:write "return numFailed;\n"
+	hFile:dec()
+	hFile:write "}\n"
 end
 
 function source.WriteMainExtraFuncs(hFile, specData, spec, options)
 	glload.WriteNamespaceEnd(hFile)
 end
 
+function cpp.source.WriteCopierC(hFile, specData, spec, options)
+	hFile:fmtblock([[
+extern "C" void %sCopyFromC()
+{
+  %s::CopyExtensionVariables();
+  %s::CopyFunctionPointers();
+}
+]],
+	spec.DeclPrefix(), spec.FuncNamePrefix(), spec.FuncNamePrefix())
+end
+
 function cpp.source.WriteMainLoader(hFile, specData, spec, options)
 	hFile:fmt("glload::LoadTest LoadFunctions(%s)\n", spec.GetLoaderParams())
 	hFile:write "{\n"
 		spec.GetExtStringParamList(function() return "" end))
 		
 	hFile:fmtblock([[
-%s::CopyExtensionVariables();
-%s::CopyFunctionPointers();
+//The C loader will call the above function to copy the variables and such.
 
 if(test == 0)
 	return glload::LoadTest(false, 0);
 return glload::LoadTest(true, test - 1);
-]],
-		spec.FuncNamePrefix(), spec.FuncNamePrefix())
+]])
 	
 	hFile:dec()
 	hFile:write "}\n"

test/glload_cpp/test.cpp

 
 #include "glload/gl_all.hpp"
 #include "glload/gl_load.hpp"
+#include "glload/gl_load.h"
 #ifdef _WIN32
 #include "glload/wgl_all.hpp"
 #include "glload/wgl_load.hpp"
 
 	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
 
+/*
 	glload::LoadTest didLoad = glload::LoadFunctions();
-	if(!didLoad)
+	if(didLoad)
 		printf("OpenGL: %i\n", didLoad.GetNumMissing());
 	else
-		printf("OpenGL Loaded!\n");
+		printf("OpenGL Failed to Load!\n");
+*/
+	int numFailed = ogl_LoadFunctions();
+	if(numFailed)
+		printf("OpenGL: %i\n", numFailed - 1);
+	else
+		printf("OpenGL Failed to Load!\n");
 
 	init();
 
 #ifdef _WIN32
 	HDC hdc = wglGetCurrentDC();
 	glload::LoadTest load = glload::LoadFunctions(hdc);
-	if(!load)
+	if(load)
 		printf("WGL: %i\n", load.GetNumMissing());
 	else
-		printf("WGL Loaded!\n");
+		printf("WGL Failed to Loaded!\n");
 #else
 #endif
 

test/noload_cpp/test.cpp

 	gl::sys::CheckExtensions();
 	wgl::sys::CheckExtensions(wglGetCurrentDC());
 
-	if(gl::exts::EXT_texture_compression_s3tc)
+	if(gl::exts::var_EXT_texture_compression_s3tc)
 		printf("Yay!\n");
 	else
 		printf("Fooey.\n");