提交 74ab96a3 编写于 作者: Z Zachary Lund

I removed GLEW, added glLoadGen (renamed to GL here), and added...

I removed GLEW, added glLoadGen (renamed to GL here), and added implementations for all platforms. Hopefully this goes better than GLAD did.
上级 31f9e3ef
......@@ -46,6 +46,7 @@ ltmain.sh
*.app
.DS_Store
.hg
.depend
tags
*.trace
......
......@@ -11,7 +11,8 @@ add_definitions(-DLIBOBS_EXPORTS)
if(WIN32)
set(libobs-opengl_PLATFORM_SOURCES
gl-windows.c)
gl-windows.c
wgl_obs.c)
elseif(APPLE)
set(libobs-opengl_PLATFORM_SOURCES
gl-cocoa.m)
......@@ -33,7 +34,8 @@ elseif(APPLE)
${IOSURF})
else()
set(libobs-opengl_PLATFORM_SOURCES
gl-x11.c)
gl-x11.c
GL/glx_obs.c)
endif()
set(libobs-opengl_SOURCES
......@@ -48,7 +50,7 @@ set(libobs-opengl_SOURCES
gl-texturecube.c
gl-vertexbuffer.c
gl-zstencil.c
glew/src/glew.c)
GL/gl_obs.c)
set(libobs-opengl_HEADERS
gl-exports.h
......
syntax: glob
test/glsdk/*
*.idb
*.sln
*.suo
*.ncb
*.vcproj
*.user
*.pdb
test/obj
docs/*.wiki
obj/*
*.exe
*.ilk
*.workspace
allwgl.txt
allglx.txt
allgl.txt
test/*
modules/UserStyles.lua
e80ca78f0d522aa89dd8efcf2d89824254a57a03 0.3
daece2f41ef8ddbf0be8bcdb03b88feae0376077 0.3.1
71be8cc83edca94737f5fd60ab0b0a0ef16ea8ce 1.0.0
60193bab2f45c94fd16d555d91b32762850bed80 1.0.1
09c56e6be87e62671c389774236e773a05b60ebb 1.0.2
001b6789ff2ad62e61da7ee4bdfc763c82ada849 1.0.3
c76a5cd7bdeee53f233e65f006fd43eeac0f155b 1.1.0
c76a5cd7bdeee53f233e65f006fd43eeac0f155b 1.1.0
b6fd46d21996792756f3d72c6c89e798c0a2dfcd 1.1.0
3afee3d983167126cc3aad84414f285edc1ca7d9 1.1.1
3f8908c5addcf15e44afa35151b6692febf14e5d 2.0.0rc1
local prelims =
{
[[lua $<dir>MakeAllExts.lua -spec=gl $<dir>allgl.txt]],
[[lua $<dir>MakeAllExts.lua -spec=wgl $<dir>allwgl.txt]],
[[lua $<dir>MakeAllExts.lua -spec=glX $<dir>allglx.txt]],
}
local tests =
{
[[lua $<dir>LoadGen.lua -spec=gl -version=4.4 -profile=core -style=pointer_cpp -stdext=gl_ubiquitous.txt $<dir>test/ptr_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=core -style=pointer_c -stdext=gl_ubiquitous.txt $<dir>test/ptr_c/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=core -style=func_cpp -stdext=gl_ubiquitous.txt $<dir>test/func_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=compatibility -style=pointer_cpp -stdext=gl_ubiquitous.txt $<dir>test/ptr_cpp_comp/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=2.1 -style=func_cpp -stdext=gl_ubiquitous.txt $<dir>test/func_cpp_comp/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=4.4 -profile=compatibility -style=pointer_c -stdext=gl_ubiquitous.txt $<dir>test/ptr_c_comp/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=compatibility -style=noload_cpp -stdext=gl_ubiquitous.txt $<dir>test/noload_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=compatibility -style=noload_cpp $<dir>test/noload_cpp_noext/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=core -style=noload_c -stdext=gl_ubiquitous.txt $<dir>test/noload_c/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=2.1 -style=noload_c -stdext=gl_ubiquitous.txt $<dir>test/noload_c_old/test]],
[[lua $<dir>LoadGen.lua -spec=gl -version=3.3 -profile=compatibility -style=noload_c $<dir>test/noload_c_noext/test]],
}
local platTests =
{
wgl =
{
[[lua $<dir>LoadGen.lua -spec=wgl -style=pointer_cpp -stdext=wgl_common.txt $<dir>test/ptr_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=pointer_c -stdext=wgl_common.txt $<dir>test/ptr_c/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=func_cpp -stdext=wgl_common.txt $<dir>test/func_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=pointer_cpp -stdext=wgl_common.txt $<dir>test/ptr_cpp_comp/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=func_cpp -stdext=wgl_common.txt $<dir>test/func_cpp_comp/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=pointer_c -stdext=wgl_common.txt $<dir>test/ptr_c_comp/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=noload_cpp -stdext=wgl_common.txt $<dir>test/noload_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=noload_cpp -stdext=wgl_common.txt $<dir>test/noload_cpp_noext/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=noload_c -stdext=wgl_common.txt $<dir>test/noload_c/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=noload_c -stdext=wgl_common.txt $<dir>test/noload_c_old/test]],
[[lua $<dir>LoadGen.lua -spec=wgl -style=noload_c $<dir>test/noload_c_noext/test]],
},
glX =
{
[[lua $<dir>LoadGen.lua -spec=glX -style=pointer_cpp -stdext=glx_common.txt $<dir>test/ptr_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=pointer_c -stdext=glx_common.txt $<dir>test/ptr_c/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=func_cpp -stdext=glx_common.txt $<dir>test/func_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=pointer_cpp -stdext=glx_common.txt $<dir>test/ptr_cpp_comp/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=func_cpp -stdext=glx_common.txt $<dir>test/func_cpp_comp/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=pointer_c -stdext=glx_common.txt $<dir>test/ptr_c_comp/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=noload_cpp -stdext=glx_common.txt $<dir>test/noload_cpp/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=noload_cpp -stdext=glx_common.txt $<dir>test/noload_cpp_noext/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=noload_c -stdext=glx_common.txt $<dir>test/noload_c/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=noload_c -stdext=glx_common.txt $<dir>test/noload_c_old/test]],
[[lua $<dir>LoadGen.lua -spec=glX -style=noload_c $<dir>test/noload_c_noext/test]],
},
}
local glXTests = {}
local baseDir = arg[0]:match("^(.*[\\/])")
baseDir = baseDir or "./"
local function ExecTests(testList)
for _, test in ipairs(testList) do
test = test:gsub("%$<dir>", baseDir)
print(test)
os.execute(test)
end
end
if(arg[1]) then
assert(platTests[arg[1]], "Invalid platform " .. arg[1])
end
ExecTests(prelims)
ExecTests(tests)
if(arg[1]) then
ExecTests(platTests[arg[1]])
end
Copyright (C) 2011-2013 by Jason L. McKesson
The source code in this distribution is licensed under the terms of the MIT license, as stated below. The source code generated by this tool is yours to do with as you will.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
assert(arg and arg[0], "You ran this script incorrectly.")
--Get the location of our modules relative to here.
local baseDir = arg[0]:match("^(.*[\\/])")
baseDir = baseDir or "./"
assert(baseDir, arg[0] .. " No directory")
--Fixup the package path to be relative to this directory.
package.path = baseDir .. "modules/?.lua;" .. package.path
--Make a function to get the correct directory name.
function SysRelPath(relativePath)
return baseDir .. relativePath
end
FixupPath = SysRelPath --Older name.
local opts = require "GetOptions"
local Specs = require "Specs"
local Styles = require "Styles"
local LoadSpec = require "LoadLuaSpec"
local util = require "util"
--Get the options.
local status, options = pcall(opts.GetOptions, arg)
if(not status) then
io.stdout:write(options, "\n")
return
end
--Load the spec data.
local spec = Specs.GetSpec(options.spec)
local specData = spec.LoadSpec()
--Verify that every extension in `options.extensions` is a real extension.
local badExts = {}
for _, extName in ipairs(options.extensions) do
if(not specData.extdefs[extName]) then
badExts[#badExts + 1] = extName
end
end
if(#badExts > 0) then
io.stdout:write("The following extensions are not in the spec ", options.spec, ":\n")
for _, extName in ipairs(badExts) do
io.stdout:write("\t", extName, "\n")
end
return
end
--Extract the path and base-filename from the filename.
local simplename, dir = util.ParsePath(options.outname)
dir = dir or "./"
assert(simplename,
"There is no filename in the path '" .. options.outname .. "'")
local style, structure = Styles.GetStyle(options.style)
--Compute the filename, minus style-specific suffix.
local basename = dir .. spec:FilePrefix() .. simplename
structure.Proc(basename, style, specData, spec, options)
assert(arg and arg[0], "You ran this script incorrectly.")
--Get the location of our modules relative to here.
local baseDir = arg[0]:match("^(.*[\\/])")
baseDir = baseDir or "./"
--Fixup the package path to be relative to this directory.
package.path = baseDir .. "modules/?.lua;" .. package.path
--Make a function to get the correct directory name.
function SysRelPath(relativePath)
return baseDir .. relativePath
end
FixupPath = SysRelPath --Older name.
local cmd = require "CmdLineOptions"
local Specs = require "Specs"
local parseOpts = cmd.CreateOptionGroup()
parseOpts:enum(
"spec",
"spec",
"Specification to use.",
{"gl", "glX", "wgl"})
parseOpts:pos_opt(
1,
"outname",
"Output filename to generate.",
"outname")
local options, pos_args = parseOpts:ProcessCmdLine(arg)
local dups = {}
local exts = {}
local spec = Specs.GetSpec(options.spec)
local specData = spec.LoadSpec()
local coreExts = spec.GetCoreExts()
for _, version in ipairs(specData.versions or {}) do
if(coreExts[version]) then
for _, extName in ipairs(coreExts[version]) do
if(not dups[extName]) then
exts[#exts + 1] = extName
dups[extName] = true
end
end
end
end
local sortExts = {}
for _, extName in ipairs(specData.extensions) do
if(not dups[extName]) then
sortExts[#sortExts + 1] = extName
dups[extName] = true
end
end
table.sort(sortExts)
local hFile = io.open(options.outname, "w")
for _, extName in ipairs(exts) do
hFile:write(extName, "\n")
end
for _, extName in ipairs(sortExts) do
hFile:write(extName, "\n")
end
hFile:close()
\ No newline at end of file
glLoadGenerator, version 1.0
Please see the documentation available on the web at https://bitbucket.org/alfonse/glloadgen/wiki/Home for detailed information on how to use this software.
The license for this distribution is available in the `License.txt` file.
Usage
-----
This loader generation system is used to create OpenGL headers and loading code for your specific needs. Rather than getting every extension and core enumerator/function all in one massive header, you get only what you actually want and ask for.
The scripts in this package are licensed under the terms of the MIT License. You will need to have Lua installed for this to work.
To use the code generator, with Lua in your path (assuming that "lua" is the name of your Lua executable), type this:
lua LoadGen.lua -style=pointer_c -spec=gl -version=3.3 -profile=core core_3_3
This tells the system to generate a header/source pair for OpenGL ("-spec=gl", as opposed to WGL or GLX), for version 3.3, the core profile. It will generate it in the "pointer_c" style, which means that it will use function pointer-style, with C linkage and source files. Such code is usable from C and C++, or other languages that can interface with C.
The option "core_3_3" is the basic component of the filename that will be used for the generation. Since it is generating OpenGL loaders (again, as opposed to WGL or GLX), it will generate files named "gl_core_3_3.*", where * is the extension used by the particular style.
The above command line will generate "gl_core_3_3.h" and "gl_core_3_3.c" files. Simply include them in your project; there is no library to build, no unresolved extenals to filter through. They just work.
Changes
-------
Version 1.0:
* New Noload loader. Works like GLee.
* -stdext now works relative to the extfiles directory, not just LoadGen. So no need to do -stdext=extfiles/gl_name_of_standard_file.txt.
* A test suite.
* Lua Filesystem is now in use; if it's not available, then you must create the destination directory yourself.
Version 0.3:
* Replaced the old generation system with a flexible structure system.
* Migrated the styles to the structure system.
\ No newline at end of file
require("ex")
require "ufs"
function FindFileInPath(filename)
local path = ex.getenv("PATH");
for pathname in path:gmatch("([^%;%\"]+)%;?") do
pathname = ufs.path(pathname);
local testName = pathname / filename;
if(ufs.exists(testName)) then
return tostring(testName);
end
end
return nil;
end
--[[ This function returns a table of core extensions and the versions they were made core in.
The table is indexed by version number (as a string). In each version is an array of extension names.
This list must be manually updated, as there is no equivalent in the spec files. Just add to the list. When a new version comes out with new core extensions, add a new list and add the local variable name to the master table as shown below.
]]
local coreExts1_2 = {
"ARB_imaging",
};
local coreExts3_0 = {
"ARB_vertex_array_object",
"ARB_texture_rg",
"ARB_texture_compression_rgtc",
"ARB_map_buffer_range",
"ARB_half_float_vertex",
"ARB_framebuffer_sRGB",
"ARB_framebuffer_object",
"ARB_depth_buffer_float",
};
local coreExts3_1 = {
"ARB_uniform_buffer_object",
"ARB_copy_buffer",
};
local coreExts3_2 = {
"ARB_depth_clamp",
"ARB_draw_elements_base_vertex",
"ARB_fragment_coord_conventions",
"ARB_provoking_vertex",
"ARB_seamless_cube_map",
"ARB_sync",
"ARB_texture_multisample",
"ARB_vertex_array_bgra",
};
local coreExts3_3 = {
"ARB_texture_rgb10_a2ui",
"ARB_texture_swizzle",
"ARB_timer_query",
"ARB_vertex_type_2_10_10_10_rev",
"ARB_blend_func_extended",
"ARB_occlusion_query2",
"ARB_sampler_objects",
};
local coreExts4_0 = {
"ARB_draw_indirect",
"ARB_gpu_shader5",
"ARB_gpu_shader_fp64",
"ARB_shader_subroutine",
"ARB_tessellation_shader",
"ARB_transform_feedback2",
"ARB_transform_feedback3",
};
local coreExts4_1 = {
"ARB_ES2_compatibility",
"ARB_get_program_binary",
"ARB_separate_shader_objects",
"ARB_vertex_attrib_64bit",
"ARB_viewport_array",
};
local coreExts4_2 = {
"ARB_base_instance",
"ARB_shading_language_420pack",
"ARB_transform_feedback_instanced",
"ARB_compressed_texture_pixel_storage",
"ARB_conservative_depth",
"ARB_internalformat_query",
"ARB_map_buffer_alignment",
"ARB_shader_atomic_counters",
"ARB_shader_image_load_store",
"ARB_shading_language_packing",
"ARB_texture_storage",
};
local coreExts4_3 = {
"KHR_debug",
"ARB_arrays_of_arrays",
"ARB_clear_buffer_object",
"ARB_compute_shader",
"ARB_copy_image",
"ARB_ES3_compatibility",
"ARB_explicit_uniform_location",
"ARB_fragment_layer_viewport",
"ARB_framebuffer_no_attachments",
"ARB_internalformat_query2",
"ARB_invalidate_subdata",
"ARB_multi_draw_indirect",
"ARB_program_interface_query",
"ARB_shader_image_size",
"ARB_shader_storage_buffer_object",
"ARB_stencil_texturing",
"ARB_texture_buffer_range",
"ARB_texture_query_levels",
"ARB_texture_storage_multisample",
"ARB_texture_view",
"ARB_vertex_attrib_binding",
};
return {
["1.2"] = coreExts1_2,
["3.0"] = coreExts3_0,
["3.1"] = coreExts3_1,
["3.2"] = coreExts3_2,
["3.3"] = coreExts3_3,
["4.0"] = coreExts4_0,
["4.1"] = coreExts4_1,
["4.2"] = coreExts4_2,
["4.3"] = coreExts4_3,
};
return {
"1.0",
"1.1",
"1.2",
"1.3",
"1.4",
"1.5",
"2.0",
"2.1",
"3.0",
"3.1",
"3.2",
"3.3",
"4.0",
"4.1",
"4.2",
"4.3",
"4.4",
}
--Initialization text for the 'gl' spec header.
return [[
#if defined(__glew_h__) || defined(__GLEW_H__)
#error Attempt to include auto-generated header after including glew.h
#endif
#if defined(__gl_h_) || defined(__GL_H__)
#error Attempt to include auto-generated header after including gl.h
#endif
#if defined(__glext_h_) || defined(__GLEXT_H_)
#error Attempt to include auto-generated header after including glext.h
#endif
#if defined(__gltypes_h_)
#error Attempt to include auto-generated header after gltypes.h
#endif
#if defined(__gl_ATI_h_)
#error Attempt to include auto-generated header after including glATI.h
#endif
#define __glew_h__
#define __GLEW_H__
#define __gl_h_
#define __GL_H__
#define __glext_h_
#define __GLEXT_H_
#define __gltypes_h_
#define __gl_ATI_h_
#ifndef APIENTRY
#if defined(__MINGW32__)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#elif (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#else
#define APIENTRY
#endif
#endif /*APIENTRY*/
#ifndef CODEGEN_FUNCPTR
#define CODEGEN_REMOVE_FUNCPTR
#if defined(_WIN32)
#define CODEGEN_FUNCPTR APIENTRY
#else
#define CODEGEN_FUNCPTR
#endif
#endif /*CODEGEN_FUNCPTR*/
#ifndef GLAPI
#define GLAPI extern
#endif
]]
--[[ The function pointer loading function takes a string and returns either NULL or a valid pointer. It is the responsibility of the loader to take care of any platform-specific oddities in pointer fetching.
]]
return [====[
#if defined(__APPLE__)
#include <mach-o/dyld.h>
static void* AppleGLGetProcAddress (const GLubyte *name)
{
static const struct mach_header* image = NULL;
NSSymbol symbol;
char* symbolName;
if (NULL == image)
{
image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
}
/* prepend a '_' for the Unix C symbol mangling convention */
symbolName = malloc(strlen((const char*)name) + 2);
strcpy(symbolName+1, (const char*)name);
symbolName[0] = '_';
symbol = NULL;
/* if (NSIsSymbolNameDefined(symbolName))
symbol = NSLookupAndBindSymbol(symbolName); */
symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
free(symbolName);
return symbol ? NSAddressOfSymbol(symbol) : NULL;
}
#endif /* __APPLE__ */
#if defined(__sgi) || defined (__sun)
#include <dlfcn.h>
#include <stdio.h>
static void* SunGetProcAddress (const GLubyte* name)
{
static void* h = NULL;
static void* gpa;
if (h == NULL)
{
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
gpa = dlsym(h, "glXGetProcAddress");
}
if (gpa != NULL)
return ((void*(*)(const GLubyte*))gpa)(name);
else
return dlsym(h, (const char*)name);
}
#endif /* __sgi || __sun */
#if defined(_WIN32)
#ifdef _MSC_VER
#pragma warning(disable: 4055)
#pragma warning(disable: 4054)
#endif
static int TestPointer(const PROC pTest)
{
ptrdiff_t iTest;
if(!pTest) return 0;
iTest = (ptrdiff_t)pTest;
if(iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1) return 0;
return 1;
}
static PROC WinGetProcAddress(const char *name)
{
HMODULE glMod = NULL;
PROC pFunc = wglGetProcAddress((LPCSTR)name);
if(TestPointer(pFunc))
{
return pFunc;
}
glMod = GetModuleHandleA("OpenGL32.dll");
return (PROC)GetProcAddress(glMod, (LPCSTR)name);
}
#define IntGetProcAddress(name) WinGetProcAddress(name)
#else
#if defined(__APPLE__)
#define IntGetProcAddress(name) AppleGLGetProcAddress(name)
#else
#if defined(__sgi) || defined(__sun)
#define IntGetProcAddress(name) SunGetProcAddress(name)
#else /* GLX */
#include <GL/glx.h>
#define IntGetProcAddress(name) (*glXGetProcAddressARB)((const GLubyte*)name)
#endif
#endif
#endif
]====]
return {
"1.1",
"1.2",
"1.3",
"1.4",
"1.5",
"2.0",
"2.1",
"3.0",
"3.1",
"3.2",
"3.3",
"4.0",
"4.1",
"4.2",
"4.3",
}
--Initialization text for the 'glX' spec header.
return [[
#ifdef __glxext_h_
#error Attempt to include glx_exts after including glxext.h
#endif
#define __glxext_h_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/glx.h>
#ifdef CODEGEN_FUNCPTR
#undef CODEGEN_FUNCPTR
#endif /*CODEGEN_FUNCPTR*/
#define CODEGEN_FUNCPTR
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef int GLsizei;
typedef unsigned char GLubyte;
typedef unsigned short GLushort;
typedef unsigned int GLuint;
typedef float GLfloat;
typedef float GLclampf;
typedef double GLdouble;
typedef double GLclampd;
#define GLvoid void
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
]]
return assert(dofile("data/gl_specloaderfunc.lua"))
--Initialization text for the 'glX' spec header.
return {}
-- Returns an array of strings, for proper indenting and such.
return {
--[[
"typedef unsigned int GLenum;\n",
"typedef unsigned char GLboolean;\n",
"typedef unsigned int GLbitfield;\n",
"typedef signed char GLbyte;\n",
"typedef short GLshort;\n",
"typedef int GLint;\n",
"typedef int GLsizei;\n",
"typedef unsigned char GLubyte;\n",
"typedef unsigned short GLushort;\n",
"typedef unsigned int GLuint;\n",
"typedef float GLfloat;\n",
"typedef float GLclampf;\n",
"typedef double GLdouble;\n",
"typedef double GLclampd;\n",
"#define GLvoid void\n",
]]
}
\ No newline at end of file
--Initialization text for the 'wgl' spec header.
return [[
#ifdef __wglext_h_
#error Attempt to include auto-generated WGL header after wglext.h
#endif
#define __wglext_h_
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#ifdef CODEGEN_FUNCPTR
#undef CODEGEN_FUNCPTR
#endif /*CODEGEN_FUNCPTR*/
#define CODEGEN_FUNCPTR WINAPI
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef int GLsizei;
typedef unsigned char GLubyte;
typedef unsigned short GLushort;
typedef unsigned int GLuint;
typedef float GLfloat;
typedef float GLclampf;
typedef double GLdouble;
typedef double GLclampd;
#define GLvoid void
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
]]
return assert(dofile("data/gl_specloaderfunc.lua"))
--ARB extensions implemented on 3.3 hardware by AMD.
ARB_transform_feedback2
ARB_transform_feedback3
ARB_texture_buffer_object_rgb32
ARB_shader_precision
ARB_draw_buffers_blend
--Core extensions frequently provided for 3.3-class hardware, yet aren't part of core 3.3.
--The extensions were added after 3.3 and there was no 3.4 to drop them into.
ARB_compressed_texture_pixel_storage
ARB_conservative_depth
ARB_ES2_compatibility
ARB_get_program_binary
ARB_explicit_uniform_location
ARB_internalformat_query
ARB_internalformat_query2
ARB_map_buffer_alignment
ARB_program_interface_query
ARB_separate_shader_objects
ARB_shading_language_420pack
ARB_shading_language_packing
ARB_texture_buffer_range
ARB_texture_storage
ARB_texture_view
ARB_vertex_attrib_binding
ARB_viewport_array
ARB_arrays_of_arrays
ARB_clear_buffer_object
ARB_copy_image
ARB_ES3_compatibility
ARB_explicit_uniform_location
ARB_fragment_layer_viewport
ARB_framebuffer_no_attachments
ARB_invalidate_subdata
ARB_program_interface_query
ARB_robust_buffer_access_behavior
ARB_stencil_texturing
ARB_texture_buffer_range
ARB_texture_query_levels
ARB_texture_storage_multisample
ARB_texture_view
ARB_vertex_attrib_binding
KHR_debug
-- All of the extensions supported by core 3.2 in MacOSX.
ARB_instanced_arrays
ARB_occlusion_query2
ARB_shader_bit_encoding
ARB_timer_query
EXT_depth_bounds_test
EXT_framebuffer_multisample_blit_scaled
EXT_texture_compression_s3tc
EXT_texture_filter_anisotropic
EXT_texture_mirror_clamp
EXT_texture_sRGB_decode
APPLE_client_storage
--APPLE_container_object_shareable
APPLE_object_purgeable
APPLE_rgb_422
APPLE_row_bytes
APPLE_texture_range
ARB_framebuffer_object
ARB_seamless_cube_map
ARB_separate_shader_objects
ARB_debug_output
ARB_copy_image
NV_copy_image
EXT_texture_mirror_clamp
\ No newline at end of file
-- Platform-specific non-core extensions that provide access to hardware features.
-- These extensions are fairly widely implemented.
NV_texture_barrier
NV_copy_image
--Extensions that are *widely* available and vital for basic functionality.
--IE: things that should be core, but aren't.
EXT_texture_compression_s3tc
EXT_texture_sRGB
EXT_texture_filter_anisotropic
\ No newline at end of file
ARB_create_context
ARB_create_context_profile
ARB_create_context_robustness
ARB_fbconfig_float
ARB_framebuffer_sRGB
ARB_multisample
EXT_create_context_es2_profile
EXT_fbconfig_packed_float
EXT_framebuffer_sRGB
EXT_import_context
EXT_swap_control
EXT_swap_control_tear
NV_present_video
NV_video_output
NV_gpu_affinity
NV_video_capture
NV_copy_image
NV_multisample_coverage
NV_DX_interop
NV_DX_interop2
ARB_multisample
ARB_extensions_string
ARB_pixel_format
ARB_pixel_format_float
ARB_framebuffer_sRGB
ARB_create_context
ARB_create_context_profile
ARB_create_context_robustness
EXT_swap_control
EXT_pixel_format_packed_float
EXT_create_context_es2_profile
EXT_swap_control_tear
NV_swap_group
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "glx_obs.h"
#if defined(__APPLE__)
#include <mach-o/dyld.h>
static void* AppleGLGetProcAddress (const GLubyte *name)
{
static const struct mach_header* image = NULL;
NSSymbol symbol;
char* symbolName;
if (NULL == image)
{
image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
}
/* prepend a '_' for the Unix C symbol mangling convention */
symbolName = malloc(strlen((const char*)name) + 2);
strcpy(symbolName+1, (const char*)name);
symbolName[0] = '_';
symbol = NULL;
/* if (NSIsSymbolNameDefined(symbolName))
symbol = NSLookupAndBindSymbol(symbolName); */
symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
free(symbolName);
return symbol ? NSAddressOfSymbol(symbol) : NULL;
}
#endif /* __APPLE__ */
#if defined(__sgi) || defined (__sun)
#include <dlfcn.h>
#include <stdio.h>
static void* SunGetProcAddress (const GLubyte* name)
{
static void* h = NULL;
static void* gpa;
if (h == NULL)
{
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
gpa = dlsym(h, "glXGetProcAddress");
}
if (gpa != NULL)
return ((void*(*)(const GLubyte*))gpa)(name);
else
return dlsym(h, (const char*)name);
}
#endif /* __sgi || __sun */
#if defined(_WIN32)
#ifdef _MSC_VER
#pragma warning(disable: 4055)
#pragma warning(disable: 4054)
#endif
static int TestPointer(const PROC pTest)
{
ptrdiff_t iTest;
if(!pTest) return 0;
iTest = (ptrdiff_t)pTest;
if(iTest == 1 || iTest == 2 || iTest == 3 || iTest == -1) return 0;
return 1;
}
static PROC WinGetProcAddress(const char *name)
{
HMODULE glMod = NULL;
PROC pFunc = wglGetProcAddress((LPCSTR)name);
if(TestPointer(pFunc))
{
return pFunc;
}
glMod = GetModuleHandleA("OpenGL32.dll");
return (PROC)GetProcAddress(glMod, (LPCSTR)name);
}
#define IntGetProcAddress(name) WinGetProcAddress(name)
#else
#if defined(__APPLE__)
#define IntGetProcAddress(name) AppleGLGetProcAddress(name)
#else
#if defined(__sgi) || defined(__sun)
#define IntGetProcAddress(name) SunGetProcAddress(name)
#else /* GLX */
#include <GL/glx.h>
#define IntGetProcAddress(name) (*glXGetProcAddressARB)((const GLubyte*)name)
#endif
#endif
#endif
int glx_ext_ARB_create_context = glx_LOAD_FAILED;
int glx_ext_ARB_create_context_profile = glx_LOAD_FAILED;
int glx_ext_ARB_create_context_robustness = glx_LOAD_FAILED;
int glx_ext_ARB_fbconfig_float = glx_LOAD_FAILED;
int glx_ext_ARB_framebuffer_sRGB = glx_LOAD_FAILED;
int glx_ext_ARB_multisample = glx_LOAD_FAILED;
int glx_ext_EXT_create_context_es2_profile = glx_LOAD_FAILED;
int glx_ext_EXT_fbconfig_packed_float = glx_LOAD_FAILED;
int glx_ext_EXT_framebuffer_sRGB = glx_LOAD_FAILED;
int glx_ext_EXT_import_context = glx_LOAD_FAILED;
int glx_ext_EXT_swap_control = glx_LOAD_FAILED;
int glx_ext_EXT_swap_control_tear = glx_LOAD_FAILED;
GLXContext (CODEGEN_FUNCPTR *_ptrc_glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *) = NULL;
static int Load_ARB_create_context()
{
int numFailed = 0;
_ptrc_glXCreateContextAttribsARB = (GLXContext (CODEGEN_FUNCPTR *)(Display *, GLXFBConfig, GLXContext, Bool, const int *))IntGetProcAddress("glXCreateContextAttribsARB");
if(!_ptrc_glXCreateContextAttribsARB) numFailed++;
return numFailed;
}
void (CODEGEN_FUNCPTR *_ptrc_glXFreeContextEXT)(Display *, GLXContext) = NULL;
GLXContextID (CODEGEN_FUNCPTR *_ptrc_glXGetContextIDEXT)(const GLXContext) = NULL;
Display * (CODEGEN_FUNCPTR *_ptrc_glXGetCurrentDisplayEXT)() = NULL;
GLXContext (CODEGEN_FUNCPTR *_ptrc_glXImportContextEXT)(Display *, GLXContextID) = NULL;
int (CODEGEN_FUNCPTR *_ptrc_glXQueryContextInfoEXT)(Display *, GLXContext, int, int *) = NULL;
static int Load_EXT_import_context()
{
int numFailed = 0;
_ptrc_glXFreeContextEXT = (void (CODEGEN_FUNCPTR *)(Display *, GLXContext))IntGetProcAddress("glXFreeContextEXT");
if(!_ptrc_glXFreeContextEXT) numFailed++;
_ptrc_glXGetContextIDEXT = (GLXContextID (CODEGEN_FUNCPTR *)(const GLXContext))IntGetProcAddress("glXGetContextIDEXT");
if(!_ptrc_glXGetContextIDEXT) numFailed++;
_ptrc_glXGetCurrentDisplayEXT = (Display * (CODEGEN_FUNCPTR *)())IntGetProcAddress("glXGetCurrentDisplayEXT");
if(!_ptrc_glXGetCurrentDisplayEXT) numFailed++;
_ptrc_glXImportContextEXT = (GLXContext (CODEGEN_FUNCPTR *)(Display *, GLXContextID))IntGetProcAddress("glXImportContextEXT");
if(!_ptrc_glXImportContextEXT) numFailed++;
_ptrc_glXQueryContextInfoEXT = (int (CODEGEN_FUNCPTR *)(Display *, GLXContext, int, int *))IntGetProcAddress("glXQueryContextInfoEXT");
if(!_ptrc_glXQueryContextInfoEXT) numFailed++;
return numFailed;
}
void (CODEGEN_FUNCPTR *_ptrc_glXSwapIntervalEXT)(Display *, GLXDrawable, int) = NULL;
static int Load_EXT_swap_control()
{
int numFailed = 0;
_ptrc_glXSwapIntervalEXT = (void (CODEGEN_FUNCPTR *)(Display *, GLXDrawable, int))IntGetProcAddress("glXSwapIntervalEXT");
if(!_ptrc_glXSwapIntervalEXT) numFailed++;
return numFailed;
}
typedef int (*PFN_LOADFUNCPOINTERS)();
typedef struct glx_StrToExtMap_s
{
char *extensionName;
int *extensionVariable;
PFN_LOADFUNCPOINTERS LoadExtension;
} glx_StrToExtMap;
static glx_StrToExtMap ExtensionMap[12] = {
{"GLX_ARB_create_context", &glx_ext_ARB_create_context, Load_ARB_create_context},
{"GLX_ARB_create_context_profile", &glx_ext_ARB_create_context_profile, NULL},
{"GLX_ARB_create_context_robustness", &glx_ext_ARB_create_context_robustness, NULL},
{"GLX_ARB_fbconfig_float", &glx_ext_ARB_fbconfig_float, NULL},
{"GLX_ARB_framebuffer_sRGB", &glx_ext_ARB_framebuffer_sRGB, NULL},
{"GLX_ARB_multisample", &glx_ext_ARB_multisample, NULL},
{"GLX_EXT_create_context_es2_profile", &glx_ext_EXT_create_context_es2_profile, NULL},
{"GLX_EXT_fbconfig_packed_float", &glx_ext_EXT_fbconfig_packed_float, NULL},
{"GLX_EXT_framebuffer_sRGB", &glx_ext_EXT_framebuffer_sRGB, NULL},
{"GLX_EXT_import_context", &glx_ext_EXT_import_context, Load_EXT_import_context},
{"GLX_EXT_swap_control", &glx_ext_EXT_swap_control, Load_EXT_swap_control},
{"GLX_EXT_swap_control_tear", &glx_ext_EXT_swap_control_tear, NULL},
};
static int g_extensionMapSize = 12;
static glx_StrToExtMap *FindExtEntry(const char *extensionName)
{
int loop;
glx_StrToExtMap *currLoc = ExtensionMap;
for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
{
if(strcmp(extensionName, currLoc->extensionName) == 0)
return currLoc;
}
return NULL;
}
static void ClearExtensionVars()
{
glx_ext_ARB_create_context = glx_LOAD_FAILED;
glx_ext_ARB_create_context_profile = glx_LOAD_FAILED;
glx_ext_ARB_create_context_robustness = glx_LOAD_FAILED;
glx_ext_ARB_fbconfig_float = glx_LOAD_FAILED;
glx_ext_ARB_framebuffer_sRGB = glx_LOAD_FAILED;
glx_ext_ARB_multisample = glx_LOAD_FAILED;
glx_ext_EXT_create_context_es2_profile = glx_LOAD_FAILED;
glx_ext_EXT_fbconfig_packed_float = glx_LOAD_FAILED;
glx_ext_EXT_framebuffer_sRGB = glx_LOAD_FAILED;
glx_ext_EXT_import_context = glx_LOAD_FAILED;
glx_ext_EXT_swap_control = glx_LOAD_FAILED;
glx_ext_EXT_swap_control_tear = glx_LOAD_FAILED;
}
static void LoadExtByName(const char *extensionName)
{
glx_StrToExtMap *entry = NULL;
entry = FindExtEntry(extensionName);
if(entry)
{
if(entry->LoadExtension)
{
int numFailed = entry->LoadExtension();
if(numFailed == 0)
{
*(entry->extensionVariable) = glx_LOAD_SUCCEEDED;
}
else
{
*(entry->extensionVariable) = glx_LOAD_SUCCEEDED + numFailed;
}
}
else
{
*(entry->extensionVariable) = glx_LOAD_SUCCEEDED;
}
}
}
static void ProcExtsFromExtString(const char *strExtList)
{
size_t iExtListLen = strlen(strExtList);
const char *strExtListEnd = strExtList + iExtListLen;
const char *strCurrPos = strExtList;
char strWorkBuff[256];
while(*strCurrPos)
{
/*Get the extension at our position.*/
int iStrLen = 0;
const char *strEndStr = strchr(strCurrPos, ' ');
int iStop = 0;
if(strEndStr == NULL)
{
strEndStr = strExtListEnd;
iStop = 1;
}
iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos);
if(iStrLen > 255)
return;
strncpy(strWorkBuff, strCurrPos, iStrLen);
strWorkBuff[iStrLen] = '\0';
LoadExtByName(strWorkBuff);
strCurrPos = strEndStr + 1;
if(iStop) break;
}
}
int glx_LoadFunctions(Display *display, int screen)
{
ClearExtensionVars();
ProcExtsFromExtString((const char *)glXQueryExtensionsString(display, screen));
return glx_LOAD_SUCCEEDED;
}
#ifndef POINTER_C_GENERATED_HEADER_GLXWIN_H
#define POINTER_C_GENERATED_HEADER_GLXWIN_H
#ifdef __glxext_h_
#error Attempt to include glx_exts after including glxext.h
#endif
#define __glxext_h_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/glx.h>
#ifdef CODEGEN_FUNCPTR
#undef CODEGEN_FUNCPTR
#endif /*CODEGEN_FUNCPTR*/
#define CODEGEN_FUNCPTR
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef int GLsizei;
typedef unsigned char GLubyte;
typedef unsigned short GLushort;
typedef unsigned int GLuint;
typedef float GLfloat;
typedef float GLclampf;
typedef double GLdouble;
typedef double GLclampd;
#define GLvoid void
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
#ifndef GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
#define GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS
#endif /*GL_LOAD_GEN_BASIC_OPENGL_TYPEDEFS*/
#ifndef GLEXT_64_TYPES_DEFINED
/* This code block is duplicated in glext.h, so must be protected */
#define GLEXT_64_TYPES_DEFINED
/* Define int32_t, int64_t, and uint64_t types for UST/MSC */
/* (as used in the GLX_OML_sync_control extension). */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
#include <inttypes.h>
#elif defined(__sun__) || defined(__digital__)
#include <inttypes.h>
#if defined(__STDC__)
#if defined(__arch64__) || defined(_LP64)
typedef long int int64_t;
typedef unsigned long int uint64_t;
#else
typedef long long int int64_t;
typedef unsigned long long int uint64_t;
#endif /* __arch64__ */
#endif /* __STDC__ */
#elif defined( __VMS ) || defined(__sgi)
#include <inttypes.h>
#elif defined(__SCO__) || defined(__USLC__)
#include <stdint.h>
#elif defined(__UNIXOS2__) || defined(__SOL64__)
typedef long int int32_t;
typedef long long int int64_t;
typedef unsigned long long int uint64_t;
#elif defined(_WIN32) && defined(__GNUC__)
#include <stdint.h>
#elif defined(_WIN32)
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
/* Fallback if nothing above works */
#include <inttypes.h>
#endif
#endif
typedef struct __GLXFBConfigRec *GLXFBConfig;
typedef XID GLXContextID;
typedef struct __GLXcontextRec *GLXContext;
typedef XID GLXPixmap;
typedef XID GLXDrawable;
typedef XID GLXPbuffer;
typedef void (APIENTRY *__GLXextFuncPtr)(void);
typedef XID GLXVideoCaptureDeviceNV;
typedef unsigned int GLXVideoDeviceNV;
typedef XID GLXVideoSourceSGIX;
typedef struct __GLXFBConfigRec *GLXFBConfigSGIX;
typedef XID GLXPbufferSGIX;
typedef struct {
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
int networkId;
} GLXHyperpipeNetworkSGIX;
typedef struct {
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
int channel;
unsigned int participationType;
int timeSlice;
} GLXHyperpipeConfigSGIX;
typedef struct {
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
int srcXOrigin, srcYOrigin, srcWidth, srcHeight;
int destXOrigin, destYOrigin, destWidth, destHeight;
} GLXPipeRect;
typedef struct {
char pipeName[80]; /* Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] */
int XOrigin, YOrigin, maxHeight, maxWidth;
} GLXPipeRectLimits;
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/
extern int glx_ext_ARB_create_context;
extern int glx_ext_ARB_create_context_profile;
extern int glx_ext_ARB_create_context_robustness;
extern int glx_ext_ARB_fbconfig_float;
extern int glx_ext_ARB_framebuffer_sRGB;
extern int glx_ext_ARB_multisample;
extern int glx_ext_EXT_create_context_es2_profile;
extern int glx_ext_EXT_fbconfig_packed_float;
extern int glx_ext_EXT_framebuffer_sRGB;
extern int glx_ext_EXT_import_context;
extern int glx_ext_EXT_swap_control;
extern int glx_ext_EXT_swap_control_tear;
#define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001
#define GLX_CONTEXT_FLAGS_ARB 0x2094
#define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
#define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
#define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
#define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
#define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252
#define GLX_NO_RESET_NOTIFICATION_ARB 0x8261
#define GLX_RGBA_FLOAT_BIT_ARB 0x00000004
#define GLX_RGBA_FLOAT_TYPE_ARB 0x20B9
#define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20B2
#define GLX_SAMPLES_ARB 100001
#define GLX_SAMPLE_BUFFERS_ARB 100000
#define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
#define GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT 0x00000008
#define GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT 0x20B1
#define GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20B2
#define GLX_SCREEN_EXT 0x800C
#define GLX_SHARE_CONTEXT_EXT 0x800A
#define GLX_VISUAL_ID_EXT 0x800B
#define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2
#define GLX_SWAP_INTERVAL_EXT 0x20F1
#define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
#ifndef GLX_ARB_create_context
#define GLX_ARB_create_context 1
extern GLXContext (CODEGEN_FUNCPTR *_ptrc_glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *);
#define glXCreateContextAttribsARB _ptrc_glXCreateContextAttribsARB
#endif /*GLX_ARB_create_context*/
#ifndef GLX_EXT_import_context
#define GLX_EXT_import_context 1
extern void (CODEGEN_FUNCPTR *_ptrc_glXFreeContextEXT)(Display *, GLXContext);
#define glXFreeContextEXT _ptrc_glXFreeContextEXT
extern GLXContextID (CODEGEN_FUNCPTR *_ptrc_glXGetContextIDEXT)(const GLXContext);
#define glXGetContextIDEXT _ptrc_glXGetContextIDEXT
extern Display * (CODEGEN_FUNCPTR *_ptrc_glXGetCurrentDisplayEXT)();
#define glXGetCurrentDisplayEXT _ptrc_glXGetCurrentDisplayEXT
extern GLXContext (CODEGEN_FUNCPTR *_ptrc_glXImportContextEXT)(Display *, GLXContextID);
#define glXImportContextEXT _ptrc_glXImportContextEXT
extern int (CODEGEN_FUNCPTR *_ptrc_glXQueryContextInfoEXT)(Display *, GLXContext, int, int *);
#define glXQueryContextInfoEXT _ptrc_glXQueryContextInfoEXT
#endif /*GLX_EXT_import_context*/
#ifndef GLX_EXT_swap_control
#define GLX_EXT_swap_control 1
extern void (CODEGEN_FUNCPTR *_ptrc_glXSwapIntervalEXT)(Display *, GLXDrawable, int);
#define glXSwapIntervalEXT _ptrc_glXSwapIntervalEXT
#endif /*GLX_EXT_swap_control*/
enum glx_LoadStatus
{
glx_LOAD_FAILED = 0,
glx_LOAD_SUCCEEDED = 1,
};
int glx_LoadFunctions(Display *display, int screen);
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif //POINTER_C_GENERATED_HEADER_GLXWIN_H
--[[
Will automatically generate all files from the current sources.
Takes three parameters:
- The destination directory, as a relative directory. This will create that directory and put the distro in that directory
- The Mercurial revision number to archive to the destination directory.
- The version number of the loader.
]]--
require "lfs"
require "ufs"
require "_FindFileInPath"
local baseDir, hgChangelist, versionNum = ...
if(#({...}) ~= 3) then
print("Not enough commandline parameters. You provided: " .. #({...}));
print("Paramters:")
print("\tDestination dir, relative to this path.")
print("\tMercurial revision to archive.")
print("\tVersion number of the SDK.")
return
end
local buildDirname = "glLoadGen_" .. versionNum:gsub("%.", "_")
lfs.mkdir(baseDir);
local pathDestDir = ufs.path(baseDir) / buildDirname;
local destDir = tostring(pathDestDir);
lfs.mkdir(destDir);
local pathCurrent = ufs.current_path()
local pathDest = pathCurrent / destDir;
local pathBase = pathCurrent / baseDir;
-----------------------------------------------------------
-- Step 1: Copy the Mercurial repo number to the location.
local clone = [[hg archive -r "%s" "%s"]];
clone = clone:format(hgChangelist, destDir);
print(clone);
os.execute(clone);
------------------------------------------------------------
-- Step 2: Delete select files from the destination location.
local toDelete =
{
--files
"make_distro.lua", ".hgignore", ".hgtags",
"_FindFileInPath.lua", ".hg_archival.txt",
--directories
}
for i, filename in ipairs(toDelete) do
local pathFile = pathDest / filename;
print("deleting:", pathFile);
ufs.remove_all(pathFile);
end
------------------------------------------------------------
-- Step 3: Create Zip archive of the distro.
local szFilename = "7z.exe"
local archiveName = buildDirname .. ".7z"
local pathSZ = ufs.path(FindFileInPath(szFilename))
if(pathSZ:empty()) then
print("Could not find 7zip.");
return;
end
ufs.current_path(pathBase);
local depProc = ex.spawn(tostring(pathSZ),
{args={"a", "-r", archiveName, buildDirname}});
depProc:wait(depProc);
------------------------------------------------------------
-- Step 4: Destroy the directory.
ufs.remove_all(pathDest);
--[[ The function CmdLineOptions takes the command-line options and processes them according to a series of functions it is given. It can handle any options of the standard forms, such as:
- "-optName param"
- "--optName option1 option2 option3"
- "-optName=param"
It takes the following parameters:
- An array of command-line options as strings.
- A table of functions, where the key name matches the options. Note that the match will be case-sensitive.
- A value to be passed to the functions. This allows them to be a bit more independent without having to use upvalue tricks.
The return value is a list of any positional arguments, in order.
The option processor functions take the following parameters:
- The value to be passed to the processor. A candidate for a `self` parameter.
- The first parameter string of the option, if any.
- A nullary iterator function to iterate over all of the options associated with the command. It can have 0 iterations. It is OK to iterate multiple times. The iterator returns two values: the parameter and the parameter's 1-base index.
The return value from the processing function is the number of options processed. If `nil` is returned, then it is assumed that *all* available options were processed.
The processor functions are called within a `pcall`, so any errors will be assumed to be processing errors related to that option. Appropriate error messages will be emitted mentioning the option name, so it doesn't need to keep its own name. It is up to each processor to decide if it has enough or too many parameters and error out if it does. Processing of command line options will error if there is a failure.
The processor assumes that strings that begin with a `-` character is an option. If a parameter is specified with the `-option=param` syntax, then it is assumed to have exactly one parameter. Thus the next value is assumed to be an option. For all other option formats, the number of processed arguments is decided upon by the processing function. If it returns `nil`, then it assumes all arguments were processed.
Any "options" that do not conform to option syntax are assumed to be positional arguments. They are stored in an array and returned by the function.
]]
local util = require "util"
--Returns nil if not an option. Otherwise returns the option and a possible
--parameter name if it is of the form "--option=foo".
local function GetOptionName(option)
local option, param = string.match(option, "^%-%-?([^%-%=][^%=]*)%=?(.*)")
if(param and #param == 0) then
param = nil
end
return option, param
end
--Returns a nullary function that iterates over a single parameter. Namely, this one.
local function GetParamIterator(param)
return function()
return function(s, var)
if(var) then
return nil, nil
else
return param, 1
end
end, nil, nil
end
end
--Returns a nullary function that iterates over all parameters from the given
--index to the next option.
local function GetParamListIterator(params, startIx)
return function()
local state = {startIx}
return function(state, var)
--Stop if out of parameters
if(state[1] > #params) then
return nil
end
--Stop if the parameter is an option name.
if(GetOptionName(params[state[1]])) then
return nil
end
state[1] = state[1] + 1
return params[state[1] - 1], state[1] - startIx
end, state, nil
end
end
local function CountNumOptions(iter)
local numOpts = 0
for _ in iter() do
numOpts = numOpts + 1
end
return numOpts
end
local function CallProcessor(func, option, value, param, iter)
local status, nargs = pcall(func, value, param, iter)
if(not status) then
error("The option '" .. option .. "' had an error:\n" .. nargs)
end
return nargs or CountNumOptions(iter)
end
local modTbl = {}
function modTbl.CmdLineOptions(cmd_line, processors, value)
local posArgs = {}
local optIx = 1
local numOpts = #cmd_line
while(optIx <= numOpts) do
local option, param = GetOptionName(cmd_line[optIx])
if(not option) then
posArgs[#posArgs + 1] = cmd_line[optIx]
optIx = optIx + 1
else
assert(processors[option], "The option '" .. option .. "' is not a valid option for this program.")
if(param) then
CallProcessor(processors[option], option, value,
param, GetParamIterator(param))
else
local paramIter = GetParamListIterator(cmd_line, optIx + 1)
local numOpts = CountNumOptions(paramIter)
if(numOpts > 0) then
param = cmd_line[optIx + 1]
end
local nargs = CallProcessor(processors[option], option, value,
param, paramIter)
optIx = optIx + nargs
end
optIx = optIx + 1
end
end
return posArgs
end
--------------------------------------------------
-- Option group logic.
local group = {}
local function ExtractDescArray(desc)
if(type(desc) == "table") then
local descArray = {}
for i, val in ipairs(desc) do
descArray[#descArray + 1] = val
end
return descArray
else
return { desc }
end
end
function group:value(optName, tblName, desc, default, optional)
table.insert(self._doc_order, optName)
self._procs[optName] = {
desc = desc,
tableName = tblName,
default = default,
optional = optional,
--self is the destination table, where the data goes
proc = function(self, param, iter)
assert(param, "This option needs a single parameter")
assert(not self[tblName], "Cannot specify the option twice")
self[tblName] = param
return 1
end,
document = function(self)
local docs = ExtractDescArray(self.desc)
if(self.default) then
docs[#docs + 1] = "Default value: " .. self.default
else
if(self.optional) then
docs[#docs + 1] = "This option is not required."
end
end
return docs
end,
}
end
function group:enum(optName, tblName, desc, values, defaultIx, optional)
table.insert(self._doc_order, optName)
local valuesInv = util.InvertTable(values)
self._procs[optName] = {
desc = desc,
tableName = tblName,
values = values,
valuesInv = valuesInv,
optional = optional,
proc = function(self, param, iter)
assert(param, "This option needs a parameter")
assert(valuesInv[param], param .. " is not a valid value.")
assert(not self[tblName], "Cannot specify this option twice.");
self[tblName] = param
return 1
end,
document = function(self)
local docs = ExtractDescArray(self.desc)
docs[#docs + 1] = "Allowed values:"
docs[#docs + 1] = table.concat(self.values, ", ")
if(self.default) then
docs[#docs + 1] = "Default value: " .. self.default
else
if(self.optional) then
docs[#docs + 1] = "This option is not required."
end
end
return docs
end,
}
if(defaultIx) then
self._procs[optName].default = values[defaultIx]
end
end
function group:array(optName, tblName, desc, modifier, optional)
table.insert(self._doc_order, optName)
self._procs[optName] = {
desc = desc,
tableName = tblName,
optional = optional,
proc = function(self, param, iter)
self[tblName] = self[tblName] or {}
local bFound = false
for ext in iter() do
if(modifier) then
ext = modifier(ext)
end
table.insert(self[tblName], ext)
bFound = true
end
assert(bFound, "Must provide at least one value.");
end,
document = function(self)
local docs = ExtractDescArray(self.desc)
return docs
end,
}
end
--Stores its data in an array, but it only takes one parameter.
function group:array_single(optName, tblName, desc, modifier, optional)
table.insert(self._doc_order, optName)
self._procs[optName] = {
desc = desc,
tableName = tblName,
optional = optional,
proc = function(self, param, iter)
assert(param, "This option needs a single parameter")
self[tblName] = self[tblName] or {}
if(modifier) then
param = modifier(param)
end
table.insert(self[tblName], param)
return 1
end,
document = function(self)
local docs = ExtractDescArray(self.desc)
docs[#docs + 1] = "Can be used multiple times."
return docs
end,
}
end
function group:pos_opt(index, tblName, desc, optName, default, optional)
assert(not self._pos_opts[index],
"Positional argument " .. index .. " is already in use")
self._pos_opts[index] = {
desc = desc,
tableName = tblName,
optName = optName,
default = default,
optional = optional,
}
end
function group:AssertParse(test, msg)
if(not test) then
io.stdout:write(msg, "\n")
self:DisplayHelp()
error("", 0)
end
end
function group:ProcessCmdLine(cmd_line)
local procs = {}
for option, data in pairs(self._procs) do
procs[option] = data.proc
end
local options = {}
local status, posOpts =
pcall(modTbl.CmdLineOptions, cmd_line, procs, options)
self:AssertParse(status, posOpts)
--Apply positional arguments.
for ix, pos_arg in pairs(self._pos_opts) do
if(posOpts[ix]) then
options[pos_arg.tableName] = posOpts[ix]
elseif(pos_arg.default) then
options[pos_arg.tableName] = default
else
self:AssertParse(pos_arg.optional,
"Missing positional argument " .. pos_arg.optName)
end
end
--Apply defaults.
for option, data in pairs(self._procs) do
if(not options[data.tableName]) then
if(data.default) then
options[data.tableName] = data.default
else
self:AssertParse(data.optional,
"Option " .. option .. " was not specified.")
end
end
end
return options, posOpts
end
function group:DisplayHelp()
local hFile = io.stdout
local function MaxVal(tbl)
local maxval = 0
for ix, val in pairs(tbl) do
if(ix > maxval) then
maxval = ix
end
end
return maxval
end
--Write the command-line, including positional arguments.
hFile:write("Command Line:")
local maxPosArg = MaxVal(self._pos_opts)
for i = 1, maxPosArg do
if(self._pos_opts[i]) then
hFile:write(" <", self._pos_opts[i].optName, ">")
else
hFile:write(" <something>")
end
end
hFile:write(" <options>\n")
--Write each option.
hFile:write("Options:\n")
for _, option in ipairs(self._doc_order) do
local data = self._procs[option]
hFile:write("-", option, ":\n")
local docs = data:document()
for _, str in ipairs(docs) do
hFile:write("\t", str, "\n")
end
end
end
function modTbl.CreateOptionGroup()
local optGroup = {}
for key, func in pairs(group) do
optGroup[key] = func
end
optGroup._procs = {}
optGroup._pos_opts = {}
optGroup._doc_order = {}
return optGroup
end
return modTbl
local common = {}
--Iterates over all requested extensions
--Calls Extension(hFile, extName, spec, options)
local extensions =
{ type="group",
{ type="ext-iter",
{ type="write", name="Extension(hFile, extName, spec, options)", },
},
}
function common.Extensions() return extensions end
--Iterates over every enumerator, in order:
-- Requested extension enums.
-- For each version:
-- Core extension enumerators from version X
-- Core enumerators from version X
-- Calls Enumerator(hFile, enum, enumTable, spec, options, enumSeen)
-- Optional small headers
local enumerators =
{ type="group",
{ type="enum-seen",
{ type="ext-iter",
{type="enum-iter",
{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true, optional=true},
{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options, enumSeen)", },
{ type="blank", last=true },
},
},
{ type="version-iter",
{type="enum-iter",
{ type="write", name="SmallHeader(hFile, value, options)", value="Version: %version", first=true, optional=true},
{ type="write", name="Enumerator(hFile, enum, enumTable, spec, options, enumSeen)", },
{ type="blank", last=true },
},
},
},
}
function common.Enumerators() return enumerators end
--Iterates over each function, in order:
-- Requested extension functions.
-- For each version:
-- Core extensions from for version X
-- Core functions from version X
-- Calls Function(hFile, func, spec, options, funcSeen)
-- Optional small headers.
-- Can provide an optional ending table, that will be placed within
-- the "func-seen" block.
function common.Functions(ending)
ending = ending or { type="group" }
return
{ type="func-seen",
{ type="ext-iter",
{type="func-iter",
{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %extName", first=true, optional=true},
{ type="write", name="Function(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
{ type="version-iter",
{type="func-iter",
{ type="write", name="SmallHeader(hFile, value, options)", value="Extension: %version", first=true, optional=true},
{ type="write", name="Function(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
ending,
}
end
return common
--[[Useful style utility functions. This file will contain commonly useful strings and functions that generate useful data.]]
local util = require "util"
local struct = require "Structure"
local common = {}
--Creates a tabbed file.
function common.CreateFile(filename, indent)
return util.CreateFile(filename, indent)
end
--Retrieves the common typedefs used by OpenGL 1.1.
function common.GetStdTypedefs()
return dofile(util.GetDataFilePath() .. "style_commontypedefs.lua")
end
--Writes passthru data from the specData, with proper indentation.
function common.WritePassthruData(hFile, strArray)
for _, str in ipairs(strArray) do
--unindent after #endif
if(str:match("^#endif") or str:match("^#elif")) then
hFile:dec()
end
hFile:write(str, "\n")
--Indent after #if.
if(str:match("^#if") or str:match("^#elif")) then
hFile:inc()
end
end
end
function common.WriteExternCStart(hFile)
hFile:write("#ifdef __cplusplus\n")
hFile:write('extern "C" {\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("\n")
end
--Determines the value of the enumeration.
local function ResolveEnumValue(enum, enumTable)
if(enum.copy) then
return common.ResolveEnumValue(enumTable[enum.value], enumTable),
enum.value;
else
return enum.value;
end
end
common.ResolveEnumValue = ResolveEnumValue
function common.GetCppEnumName(enum)
--Note: some enumerators start with characters C++ forbids as initial
--identifiers. If we detect such an enum, prefix it with `_`.
local enumName = enum.name
if(not enumName:match("^[a-zA-Z_]")) then
enumName = "_" .. enumName
end
--Also, certain identifiers can need it because they conflict.
local badIdent = {"TRUE", "FALSE", "NO_ERROR", "WAIT_FAILED", "DOMAIN"}
for _, ident in ipairs(badIdent) do
if(enumName == ident) then
enumName = enumName .. "_"
break
end
end
return enumName
end
function common.GetNameLengthPadding(name, length)
local numSpaces = length - #name
if(numSpaces < 1) then
numSpaces = 1
end
return string.rep(" ", numSpaces)
end
--Gets the return type for a function.
function common.GetFuncReturnType(func)
return func["return_ctype"]
end
function common.DoesFuncReturnSomething(func)
local returnType = func["return_ctype"]
return (returnType == "void") or (returnType == "GLvoid")
end
local bIsKindPtr ={
value = false,
array = true,
reference = true,
};
--Important due to name conflicts. Some names have to re-mapped to others.
--Won't really affect things.
local paramNameRemap = {
near = "ren_near",
far = "ren_far",
array = "ren_array",
};
--Returns the parameter list as a string.
--Parameter list does not include parenthesis.
function common.GetFuncParamList(func, bWriteVarNames)
local paramList = {}
for i, param in ipairs(func.parameters) do
local paramType = param.ctype;
if(bWriteVarNames) then
local paramName = param.name
if(paramNameRemap[paramName]) then paramName = paramNameRemap[paramName]end
paramList[#paramList + 1] = string.format("%s %s", paramType, paramName)
else
paramList[#paramList + 1] = paramType
end
end
return table.concat(paramList, ", ");
end
--Get the list of parameter names, as a string ready to be put into ().
function common.GetFuncParamCallList(func)
local paramList = {}
for i, param in ipairs(func.parameters) do
local paramName = param.name
if(paramNameRemap[paramName]) then
paramName = paramNameRemap[paramName]
end
paramList[#paramList + 1] = paramName
end
return table.concat(paramList, ", ");
end
--Retrieves the name of the function according to OpenGL.
function common.GetOpenGLFuncName(func, spec)
return spec.FuncNamePrefix() .. func.name
end
function common.GetProcAddressName(spec)
return spec.GetPtrLoaderFuncName()
end
function common.FixupIndexedList(specData, indexed)
assert(indexed)
for _, func in ipairs(specData.funcData.functions) do
if(indexed[1] == func.name) then
indexed[1] = func
end
if(indexed[3] == func.name) then
indexed[3] = func
end
end
for _, enum in ipairs(specData.enumerators) do
if(indexed[2] == enum.name) then
indexed[2] = enum
end
if(indexed[4] == enum.name) then
indexed[4] = enum
end
end
end
function common.GetProcExtsFromExtListFunc(hFile, specData, spec, options,
indexed, GetFuncPtrName, GetEnumName)
return [[
static void ProcExtsFromExtList()
{
GLint iLoop;
GLint iNumExtensions = 0;
]] .. GetFuncPtrName(indexed[1], spec, options)
.. [[(]] .. GetEnumName(indexed[2], spec, options)
.. [[, &iNumExtensions);
for(iLoop = 0; iLoop < iNumExtensions; iLoop++)
{
const char *strExtensionName = (const char *)]] ..
GetFuncPtrName(indexed[3], spec, options) ..
[[(]] .. GetEnumName(indexed[4], spec, options) .. [[, iLoop);
LoadExtByName(strExtensionName);
}
}
]]
end
--You give it a function that takes a const char*.
function common.GetProcessExtsFromStringFunc(funcFormat, arguments)
return [[
static void ProcExtsFromExtString(const char *strExtList]] .. (arguments or "") .. [[)
{
size_t iExtListLen = strlen(strExtList);
const char *strExtListEnd = strExtList + iExtListLen;
const char *strCurrPos = strExtList;
char strWorkBuff[256];
while(*strCurrPos)
{
/*Get the extension at our position.*/
int iStrLen = 0;
const char *strEndStr = strchr(strCurrPos, ' ');
int iStop = 0;
if(strEndStr == NULL)
{
strEndStr = strExtListEnd;
iStop = 1;
}
iStrLen = (int)((ptrdiff_t)strEndStr - (ptrdiff_t)strCurrPos);
if(iStrLen > 255)
return;
strncpy(strWorkBuff, strCurrPos, iStrLen);
strWorkBuff[iStrLen] = '\0';
]] .. funcFormat:format("strWorkBuff") ..[[;
strCurrPos = strEndStr + 1;
if(iStop) break;
}
}
]]
end
function common.WriteProcessExtsFromStringFunc(hFile, ...)
hFile:writeblock(common.GetProcessExtsFromStringFunc(...))
end
function common.GetParseVersionFromString()
return [[
static void ParseVersionFromString(int *pOutMajor, int *pOutMinor, const char *strVersion)
{
const char *strDotPos = NULL;
int iLength = 0;
char strWorkBuff[10];
*pOutMinor = 0;
*pOutMajor = 0;
strDotPos = strchr(strVersion, '.');
if(!strDotPos)
return;
iLength = (int)((ptrdiff_t)strDotPos - (ptrdiff_t)strVersion);
strncpy(strWorkBuff, strVersion, iLength);
strWorkBuff[iLength] = '\0';
*pOutMajor = atoi(strWorkBuff);
strDotPos = strchr(strVersion + iLength + 1, ' ');
if(!strDotPos)
{
/*No extra data. Take the whole rest of the string.*/
strcpy(strWorkBuff, strVersion + iLength + 1);
}
else
{
/*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);
strWorkBuff[iLengthMinor] = '\0';
}
*pOutMinor = atoi(strWorkBuff);
}
]]
end
local function DeepCopyTable(tbl)
local ret = {}
for key, value in pairs(tbl) do
if(type(value) == "table") then
ret[key] = DeepCopyTable(value)
else
ret[key] = value
end
end
return ret
end
function common.WriteCMappingTable(hFile, specData, spec,
options, structName, varName, GetExtVariableName, GetExtLoaderFuncName)
--Write the struct for the mapping table.
hFile:write("typedef int (*PFN_LOADFUNCPOINTERS)();\n")
hFile:fmt("typedef struct %s%sStrToExtMap_s\n",
options.prefix, spec.DeclPrefix())
hFile:write("{\n")
hFile:inc()
hFile:write("char *extensionName;\n")
hFile:write("int *extensionVariable;\n")
hFile:write("PFN_LOADFUNCPOINTERS LoadExtension;\n")
hFile:dec()
hFile:fmt("} %s;\n", structName)
hFile:write "\n"
--Write the mapping table itself.
local arrayLength = #options.extensions
if(arrayLength == 0) then arrayLength = 1 end
hFile:fmt("static %s %s[%i] = {\n",
structName,
varName,
arrayLength)
hFile:inc()
for _, extName in ipairs(options.extensions) do
if(#specData.extdefs[extName].funcs > 0) then
hFile:fmt('{"%s", &%s, %s},\n',
spec.ExtNamePrefix() .. extName,
GetExtVariableName(extName, spec, options),
GetExtLoaderFuncName(extName, spec, options))
else
hFile:fmt('{"%s", &%s, NULL},\n',
spec.ExtNamePrefix() .. extName,
GetExtVariableName(extName, spec, options))
end
end
--Because C is stupid, write bogus entry.
if(#options.extensions == 0) then
hFile:fmt('{"", NULL, NULL},\n')
end
hFile:dec()
hFile:write("};\n")
hFile:write "\n"
hFile:fmt("static int g_extensionMapSize = %i;\n", #options.extensions);
end
function common.WriteCFindExtEntryFunc(hFile, specData, spec,
options, structName, varName, sizeName)
hFile:fmt("static %s *FindExtEntry(const char *extensionName)\n",
structName)
hFile:write("{\n")
hFile:inc()
hFile:write("int loop;\n")
hFile:fmt("%s *currLoc = %s;\n",
structName,
varName)
hFile:writeblock([[
for(loop = 0; loop < g_extensionMapSize; ++loop, ++currLoc)
{
if(strcmp(extensionName, currLoc->extensionName) == 0)
return currLoc;
}
return NULL;
]])
hFile:dec()
hFile:write("}\n")
end
function common.WriteCClearExtensionVarsFunc(hFile, specData, spec,
options, GetExtVariableName, clearValue)
hFile:fmt("static void ClearExtensionVars()\n")
hFile:write("{\n")
hFile:inc()
for _, extName in ipairs(options.extensions) do
hFile:fmt('%s = %s;\n',
GetExtVariableName(extName, spec, options),
clearValue)
end
hFile:dec()
hFile:write("}\n")
hFile:write "\n"
end
--Write a function that loads an extension by name. It is called when
--processing, so it should also set the extension variable based on the load.
function common.WriteCLoadExtByNameFunc(hFile, specData, spec,
options, structName, successValue)
hFile:writeblock([[
static void LoadExtByName(const char *extensionName)
{
]] .. structName .. [[ *entry = NULL;
entry = FindExtEntry(extensionName);
if(entry)
{
if(entry->LoadExtension)
{
int numFailed = entry->LoadExtension();
if(numFailed == 0)
{
*(entry->extensionVariable) = ]] ..
successValue ..
[[;
}
else
{
*(entry->extensionVariable) = ]] ..
successValue ..
[[ + numFailed;
}
}
else
{
*(entry->extensionVariable) = ]] ..
successValue ..
[[;
}
}
}
]])
end
function common.WriteNamespaceBegin(hFile, namespace)
hFile:fmt("namespace %s\n", namespace)
hFile:write("{\n")
hFile:inc()
end
function common.WriteNamespaceEnd(hFile)
hFile:dec()
hFile:write("}\n")
end
common.DeepCopyTable = DeepCopyTable
local my_struct =
{
{ type="file", style="header", name="GetFilename",
{ type="write", name="FilePreamble", optional=true} ,
{ 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="blank"},
{ type="block", name="Decl(hFile, spec, options)",
{ type="block", name="ExtVarDecl(hFile, spec, options)",
{ type="ext-iter",
{ type="write", name="ExtVariableDecl(hFile, extName, specData, spec, options)" },
{ type="blank", last=true },
},
},
{ type="block", name="EnumDecl(hFile, spec, options)",
{ type="enum-seen",
{ type="ext-iter",
{type="enum-iter",
{ type="write", name="EnumDecl(hFile, enum, enumTable, spec, options, enumSeen)", },
{ type="blank", last=true },
},
},
{ type="version-iter",
{type="enum-iter",
{ type="write", name="EnumDecl(hFile, enum, enumTable, spec, options, enumSeen)", },
{ type="blank", last=true },
},
},
},
},
{ type="block", name="FuncDecl(hFile, spec, options)",
{ type="func-seen",
{ type="ext-iter",
{ type="block", name="ExtFuncDecl(hFile, extName, spec, options)", cond="func-iter",
{type="func-iter",
{ type="write", name="FuncDecl(hFile, func, spec, options, funcSeen)", },
},
},
{ type="blank"},
},
{ type="version-iter",
{type="func-iter",
{ type="write", name="FuncDecl(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
},
},
{ type="block", name="SysDecl(hFile, spec, options)",
{ type="write", name="UtilityDecls(hFile, spec, options)",},
{ type="blank" },
{ type="write", name="MainLoaderFuncDecl(hFile, spec, options)",},
{ type="blank" },
{ type="write", name="VersioningFuncDecls(hFile, spec, options)",},
{ type="blank" },
},
},
},
},
{ type="file", style="source", name="GetFilename",
{ type="write", name="FilePreamble", optional=true} ,
{ 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="write", name="ExtVariableDef(hFile, extName, specData, spec, options)",},
{ type="blank", last=true},
},
},
{ type="func-seen",
{ type="ext-iter",
{ type="block", name="ExtFuncDef(hFile, extName, spec, options)", cond="func-iter",
{ type="func-iter",
{ type="write", name="FuncDef(hFile, func, spec, options, funcSeen)", },
},
{ type="blank"},
{ type="block", name="ExtLoader(hFile, extName, spec, options)",
{ type="func-iter",
{ type="write", name="ExtFuncLoader(hFile, func, spec, options)", }
}
},
{ type="blank"},
},
},
{ type="block", name="CoreFuncDef(hFile, spec, options)",
cond="core-funcs",
{ type="version-iter",
{type="func-iter",
{ type="write", name="FuncDef(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
{ type="block", name="CoreLoader(hFile, spec, options)",
{ type="version-iter",
{type="func-iter",
{ type="write", name="CoreFuncLoader(hFile, func, spec, options)", },
},
},
},
{ 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)",},
{ type="blank" },
{ type="write", name="MainLoaderFunc(hFile, specData, spec, options)",},
{ type="blank" },
{ type="write", name="VersioningFuncs(hFile, specData, spec, options)", cond="version-iter"},
{ type="blank", cond="version-iter" },
},
},
},
}
my_struct = struct.BuildStructure(my_struct)
function common.GetStandardStructure()
return my_struct
end
return common
local struct = require "Structure"
local common = require "CommonStruct"
local my_struct =
{
{ type="file", style="header", name="GetFilename",
{ type="write", name="FilePreamble", optional=true} ,
{ 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="blank"},
{ type="block", name="Decl(hFile, spec, options)",
{ type="block", name="ExtVarDecl(hFile, spec, options)",
{ type="ext-iter",
{ type="write", name="ExtVariableDecl(hFile, extName, specData, spec, options)" },
{ type="blank", last=true },
},
},
{ type="block", name="EnumDecl(hFile, spec, options)",
{ type="enum-seen",
{ type="ext-iter",
{type="enum-iter",
{ type="write", name="EnumDecl(hFile, enum, enumTable, spec, options, enumSeen)", },
{ type="blank", last=true },
},
},
{ type="version-iter",
{type="enum-iter",
{ type="write", name="EnumDecl(hFile, enum, enumTable, spec, options, enumSeen)", },
{ type="blank", last=true },
},
},
},
},
{ type="blank"},
{ type="block", name="FuncPtrDecl(hFile, spec, options)",
{ type="func-seen",
{ type="ext-iter",
{ type="block", name="ExtFuncPtrDecl(hFile, extName, spec, options)", cond="func-iter",
{type="func-iter",
{ type="write", name="FuncPtrDecl(hFile, func, spec, options, funcSeen)", },
},
},
{ type="blank"},
},
{ type="version-iter",
{type="func-iter",
{ type="write", name="FuncPtrDecl(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
},
},
{ type="blank"},
{ type="block", name="FuncDecl(hFile, spec, options)",
{ type="func-seen",
{ type="ext-iter",
{ type="block", name="ExtFuncDecl(hFile, extName, spec, options)", cond="func-iter",
{type="func-iter",
{ type="write", name="FuncDecl(hFile, func, spec, options, funcSeen)", },
},
},
{ type="blank"},
},
{ type="version-iter",
{type="func-iter",
{ type="write", name="FuncDecl(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
},
},
{ type="blank"},
{ type="block", name="SysDecl(hFile, spec, options)",
{ type="write", name="UtilityDecls(hFile, spec, options)",},
{ type="blank" },
{ type="write", name="MainLoaderFuncDecl(hFile, spec, options)",},
{ type="blank" },
{ type="write", name="VersioningFuncDecls(hFile, spec, options)",},
{ type="blank" },
},
},
},
},
{ type="file", style="source", name="GetFilename",
{ type="write", name="FilePreamble", optional=true} ,
{ 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="write", name="ExtVariableDef(hFile, extName, specData, spec, options)",},
{ type="blank", last=true},
},
},
{ type="blank"},
{ type="block", name="PtrDefs(hFile, spec, options)",
{ type="func-seen",
{ type="ext-iter",
{ type="block", name="ExtFuncPtrDef(hFile, extName, spec, options)", cond="func-iter",
{ type="func-iter",
{ type="write", name="FuncPtrDef(hFile, func, spec, options, funcSeen)", },
},
{ type="blank"},
{ type="block", name="ExtLoader(hFile, extName, spec, options)",
{ type="func-iter",
{ type="write", name="ExtFuncLoader(hFile, func, spec, options)", }
}
},
{ type="blank"},
},
},
{ type="block", name="CoreFuncPtrDef(hFile, spec, options)",
cond="core-funcs",
{ type="version-iter",
{type="func-iter",
{ type="write", name="FuncPtrDef(hFile, func, spec, options, funcSeen)", },
{ type="blank", last=true },
},
},
{ type="block", name="CoreLoader(hFile, spec, options)",
{ type="version-iter",
{type="func-iter",
{ type="write", name="CoreFuncLoader(hFile, func, spec, options)", },
},
},
},
{ type="blank"},
},
{ type="write", name="ExtStringFuncDef(hFile, specData, spec, options, funcSeen)"},
},
},
{ type="blank"},
{ type="block", name="SysDef(hFile, spec, options)",
{ type="write", name="UtilityDefs(hFile, specData, spec, options)",},
{ type="blank" },
{ type="write", name="MainLoaderFunc(hFile, specData, spec, options)",},
{ type="blank" },
{ type="write", name="VersioningFuncs(hFile, specData, spec, options)", cond="version-iter"},
{ type="blank", cond="version-iter" },
},
},
},
}
my_struct = struct.BuildStructure(my_struct)
return my_struct
此差异已折叠。
此差异已折叠。
此差异已折叠。
local struct = require "Structure"
local common = require "CommonStruct"
local sys_functions =
{ type="block", name="System(hFile, spec, options)",
{type="write", name="SetupFunction(hFile, specData, spec, options)", },
{type="blank", cond="version-iter" },
{type="write", name="VersionFunctions(hFile, specData, spec, options)", cond="version-iter"},
}
local my_struct =
{
{ type="file", style="hdr", name="GetFilename(basename, spec, options)",
{ type="write", name="FilePreamble", optional=true} ,
{ type="block", name="IncludeGuard",
{ type="blank"},
{ type="write", name="Guards(hFile, spec, options)",},
{ type="blank"},
{ type="write", name="Typedefs(hFile, specData, spec, options)",},
{ type="blank"},
{ type="block", name="ExternC(hFile, spec, options)",
{ type="write", name="LargeHeader(hFile, value, options)", value="Extension Variables", },
{ type="blank"},
{ type="block", name="ExtVariables(hFile, spec, options)",
common.Extensions(),
},
{ type="blank"},
{ type="block", name="Enumerators(hFile, spec, options)",
common.Enumerators(),
},
{ type="blank"},
common.Functions(),
sys_functions,
},
},
},
{ type="file", style="src", name="GetFilename(basename, spec, options)",
{ type="write", name="Includes(hFile, basename, spec, options)", },
{ type="blank"},
{ type="write", name="LoaderFunc(hFile, spec, options)", },
{ type="blank"},
{ type="block", name="ExtVariables(hFile, spec, options)",
common.Extensions(),
},
{ type="blank"},
{ type="group", style="typedefs",
common.Functions(),
},
{ type="blank"},
{ type="group", style="defs",
common.Functions(),
},
{ type="blank"},
{ type="group", style="switch",
common.Functions(),
},
{ type="blank"},
sys_functions,
},
}
my_struct = struct.BuildStructure(my_struct)
return my_struct
此差异已折叠。
local struct = require "Structure"
local common = require "CommonStruct"
local sys_functions =
{ type="block", name="System(hFile, spec, options)",
{type="write", name="SetupFunction(hFile, specData, spec, options)", },
{type="blank", cond="version-iter" },
{type="write", name="VersionFunctions(hFile, specData, spec, options)", cond="version-iter"},
}
local my_struct =
{
{ type="file", style="hdr", name="GetFilename(basename, spec, options)",
{ type="write", name="FilePreamble", optional=true} ,
{ type="block", name="IncludeGuard",
{ type="blank"},
{ type="write", name="Guards(hFile, spec, options)",},
{ type="blank"},
{ type="write", name="Typedefs(hFile, specData, spec, options)",},
{ type="blank"},
{ type="block", name="MainNamespace(hFile, spec, options)",
{ type="write", name="LargeHeader(hFile, value, options)", value="Extension Variables", },
{ type="block", name="ExtVariables(hFile, spec, options)",
common.Extensions(),
},
{ type="blank"},
{ type="block", name="Enumerators(hFile, spec, options)",
common.Enumerators(),
},
{ type="blank"},
common.Functions(),
sys_functions,
},
},
},
{ type="file", style="src", name="GetFilename(basename, spec, options)",
{ type="write", name="Includes(hFile, basename, spec, options)", },
{ type="blank"},
{ type="write", name="LoaderFunc(hFile, spec, options)", },
{ type="blank"},
{ type="block", name="MainNamespace(hFile, spec, options)",
{ type="block", name="ExtVariables(hFile, spec, options)",
common.Extensions(),
},
{ type="blank"},
{ type="group", style="typedefs",
common.Functions(),
},
{ type="blank"},
{ type="group", style="defs",
common.Functions(),
},
{ type="blank"},
{ type="group", style="switch",
common.Functions(),
},
{ type="blank"},
{ type="block", name="Struct(hFile, spec, options)", style="init",
common.Functions(),
},
{ type="blank"},
sys_functions,
},
},
}
my_struct = struct.BuildStructure(my_struct)
return my_struct
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册