2010-12-04 22:51:40 +01:00
|
|
|
|
#region License
|
|
|
|
|
//
|
|
|
|
|
// The Open Toolkit Library License
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Bind.Structures;
|
|
|
|
|
|
|
|
|
|
namespace Bind
|
|
|
|
|
{
|
|
|
|
|
using Delegate = Bind.Structures.Delegate;
|
|
|
|
|
using Enum = Bind.Structures.Enum;
|
|
|
|
|
using Type = Bind.Structures.Type;
|
|
|
|
|
|
|
|
|
|
sealed class CppSpecWriter : ISpecWriter
|
|
|
|
|
{
|
|
|
|
|
readonly char[] numbers = "0123456789".ToCharArray();
|
2010-12-05 10:51:36 +01:00
|
|
|
|
const string AllowDeprecated = "ALLOW_DEPRECATED_GL";
|
2010-12-06 10:52:05 +01:00
|
|
|
|
const string DigitPrefix = "T"; // Prefix for identifiers that start with a digit
|
2011-09-26 13:18:57 +02:00
|
|
|
|
const string OutputFileHeader = "gl++.h";
|
|
|
|
|
|
|
|
|
|
#region Verbatim parts of output file
|
|
|
|
|
|
|
|
|
|
const string GetAddressDefinition = @"
|
|
|
|
|
|
|
|
|
|
namespace Internals
|
|
|
|
|
{
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
extern ""C""
|
|
|
|
|
{
|
|
|
|
|
typedef int (*PROC)();
|
|
|
|
|
extern void* __stdcall wglGetCurrentContext();
|
|
|
|
|
extern PROC __stdcall wglGetProcAddress(const char *procname);
|
|
|
|
|
}
|
|
|
|
|
#elif !defined(__APPLE__)
|
|
|
|
|
extern ""C""
|
|
|
|
|
{
|
|
|
|
|
#define APIENTRY
|
|
|
|
|
extern void* glXGetCurrentContext();
|
|
|
|
|
extern void (*glXGetProcAddress(const char *procname))();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
|
#define APIENTRY
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
|
|
|
|
|
|
#define APIENTRY
|
|
|
|
|
extern ""C"" void* CGLGetCurrentContext();
|
|
|
|
|
|
|
|
|
|
#ifdef MAC_OS_X_VERSION_10_3
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
inline void* NSGLGetProcAddress(const char *name)
|
|
|
|
|
{
|
|
|
|
|
static void* image = NULL;
|
|
|
|
|
if (NULL == image)
|
|
|
|
|
{
|
|
|
|
|
image = dlopen(""/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"", RTLD_LAZY);
|
|
|
|
|
}
|
|
|
|
|
return image ? dlsym(image, (const char*)name) : NULL;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
|
inline void* NSGLGetProcAddress(const char *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;
|
|
|
|
|
symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
|
|
|
|
|
free(symbolName);
|
|
|
|
|
return symbol ? NSAddressOfSymbol(symbol) : NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif /* MAC_OS_X_VERSION_10_3 */
|
|
|
|
|
#endif /* __APPLE__ */
|
|
|
|
|
|
|
|
|
|
#if defined(__sgi) || defined (__sun)
|
|
|
|
|
#define APIENTRY
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
inline void* LoadSymbol(const char *name)
|
|
|
|
|
{
|
|
|
|
|
// dlopen what?
|
|
|
|
|
if ((void *h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
|
|
|
|
|
return dlsym(h, ""glXGetProcAddress"");
|
|
|
|
|
}
|
|
|
|
|
inline void* dlGetProcAddress(const char *name)
|
|
|
|
|
{
|
|
|
|
|
static void* gpa = LoadSymbol(""glXGetProcAddress"");
|
|
|
|
|
|
|
|
|
|
if (gpa != NULL)
|
|
|
|
|
return ((void*(*)(const char*))gpa)(name);
|
|
|
|
|
else
|
|
|
|
|
return dlsym(h, (const char*)name);
|
|
|
|
|
}
|
|
|
|
|
inline void* dlGetCurrentContext()
|
|
|
|
|
{
|
|
|
|
|
static void* gpa = LoadSymbol(""glXGetProcAddress"");
|
|
|
|
|
|
|
|
|
|
if (gpa != NULL)
|
|
|
|
|
return ((void*(*)())gpa)();
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif /* __sgi || __sun */
|
|
|
|
|
|
|
|
|
|
inline void* GetAddress(const char* name)
|
|
|
|
|
{
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
return (void*)wglGetProcAddress(name);
|
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
return (void*)NSGLGetProcAddress(name);
|
|
|
|
|
#elif defined(__sgi) || defined(__sun)
|
|
|
|
|
return (void*)dlGetProcAddress(name);
|
|
|
|
|
#else
|
|
|
|
|
return (void*)glXGetProcAddress((const char*)name);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void* GetCurrentContext()
|
|
|
|
|
{
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
return wglGetCurrentContext();
|
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
return CGLGetCurrentContext();
|
|
|
|
|
#elif defined(__sgi) || defined(__sun)
|
|
|
|
|
return dlGetCurrentContext();
|
|
|
|
|
#else
|
|
|
|
|
return glXGetCurrentContext();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
const string TypeDefinitions = @"
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct Enumeration
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
int value;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
inline Enumeration(int value)
|
|
|
|
|
{
|
|
|
|
|
this->value = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline operator int() const
|
|
|
|
|
{
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef unsigned int GLenum;
|
|
|
|
|
typedef unsigned int GLbitfield;
|
|
|
|
|
typedef int GLsizei; // size_t
|
|
|
|
|
typedef bool GLboolean;
|
|
|
|
|
typedef signed char GLbyte;
|
|
|
|
|
typedef unsigned char GLubyte;
|
|
|
|
|
typedef short GLshort;
|
|
|
|
|
typedef unsigned short GLushort;
|
|
|
|
|
typedef int GLint;
|
|
|
|
|
typedef unsigned int GLuint;
|
|
|
|
|
typedef long GLlong;
|
|
|
|
|
typedef unsigned long GLulong;
|
|
|
|
|
typedef float GLfloat;
|
|
|
|
|
typedef float GLclampf;
|
|
|
|
|
typedef double GLdouble;
|
|
|
|
|
typedef double GLclampd;
|
|
|
|
|
typedef void GLvoid;
|
|
|
|
|
typedef const char* GLstring;
|
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1400
|
|
|
|
|
typedef __int64 GLint64EXT;
|
|
|
|
|
typedef unsigned __int64 GLuint64EXT;
|
|
|
|
|
#else
|
|
|
|
|
typedef signed long long GLint64EXT;
|
|
|
|
|
typedef unsigned long long GLuint64EXT;
|
|
|
|
|
#endif
|
|
|
|
|
typedef GLint64EXT GLint64;
|
|
|
|
|
typedef GLuint64EXT GLuint64;
|
|
|
|
|
typedef struct __GLsync { } *GLsync;
|
|
|
|
|
|
|
|
|
|
typedef char GLchar;
|
|
|
|
|
typedef void (*GLDEBUGPROCAMD)(GLuint id,
|
|
|
|
|
GLenum category, GLenum severity, GLsizei length,
|
|
|
|
|
const GLchar* message, GLvoid* userParam);
|
|
|
|
|
|
|
|
|
|
/* For ARB_debug_output */
|
|
|
|
|
|
|
|
|
|
typedef void (*GLDEBUGPROCARB)(GLenum source,
|
|
|
|
|
GLenum type, GLuint id, GLenum severity,
|
|
|
|
|
GLsizei length, const GLchar* message, GLvoid* userParam);
|
|
|
|
|
|
|
|
|
|
/* For GL_ARB_cl_event */
|
|
|
|
|
|
|
|
|
|
typedef struct _cl_context *cl_context;
|
|
|
|
|
typedef struct _cl_event *cl_event;
|
|
|
|
|
|
|
|
|
|
//typedef GLsizei IntPtr;
|
|
|
|
|
typedef void* IntPtr;
|
|
|
|
|
typedef GLbyte SByte;
|
|
|
|
|
typedef GLubyte Byte;
|
|
|
|
|
typedef GLshort Int16;
|
|
|
|
|
typedef GLushort UInt16;
|
|
|
|
|
typedef GLint Int32;
|
|
|
|
|
typedef GLuint UInt32;
|
|
|
|
|
typedef GLlong Int64;
|
|
|
|
|
typedef GLulong UInt64;
|
|
|
|
|
typedef GLfloat Single;
|
|
|
|
|
typedef GLdouble Double;
|
|
|
|
|
typedef GLstring String;
|
|
|
|
|
typedef char* StringBuilder;
|
|
|
|
|
typedef GLDEBUGPROCAMD DebugProcAmd;
|
|
|
|
|
typedef GLDEBUGPROCARB DebugProcArb;
|
|
|
|
|
|
|
|
|
|
struct Half
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
UInt16 value;
|
|
|
|
|
public:
|
|
|
|
|
};
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
#endregion
|
2010-12-06 23:32:47 +01:00
|
|
|
|
|
|
|
|
|
BindStreamWriter sw_h = new BindStreamWriter(Path.GetTempFileName());
|
2010-12-04 22:51:40 +01:00
|
|
|
|
|
|
|
|
|
#region WriteBindings
|
|
|
|
|
|
|
|
|
|
public void WriteBindings(IBind generator)
|
|
|
|
|
{
|
|
|
|
|
WriteBindings(generator.Delegates, generator.Wrappers, generator.Enums);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
void WriteBindings(DelegateCollection delegates, FunctionCollection wrappers, EnumCollection enums)
|
2010-12-04 22:51:40 +01:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Writing bindings to {0}", Settings.OutputPath);
|
|
|
|
|
if (!Directory.Exists(Settings.OutputPath))
|
|
|
|
|
Directory.CreateDirectory(Settings.OutputPath);
|
|
|
|
|
|
2010-12-05 12:32:49 +01:00
|
|
|
|
// Hack: Fix 3dfx extension category so it doesn't start with a digit
|
|
|
|
|
if (wrappers.ContainsKey("3dfx"))
|
|
|
|
|
{
|
|
|
|
|
var three_dee_fx = wrappers["3dfx"];
|
|
|
|
|
wrappers.Remove("3dfx");
|
2010-12-06 10:52:05 +01:00
|
|
|
|
wrappers.Add(DigitPrefix + "3dfx", three_dee_fx);
|
2010-12-05 12:32:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-05 03:20:18 +01:00
|
|
|
|
Settings.DefaultOutputNamespace = "OpenTK";
|
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
using (var sw = sw_h)
|
2010-12-06 23:32:47 +01:00
|
|
|
|
{
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("#pragma once");
|
|
|
|
|
sw.WriteLine("#ifndef GLPP_H");
|
|
|
|
|
sw.WriteLine("#define GLPP_H");
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
|
|
|
|
|
WriteLicense(sw);
|
|
|
|
|
|
|
|
|
|
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
|
|
|
|
|
|
|
|
|
WriteGetAddress(sw);
|
|
|
|
|
WriteTypes(sw);
|
2010-12-06 23:32:47 +01:00
|
|
|
|
WriteEnums(sw, enums);
|
2011-09-26 13:18:57 +02:00
|
|
|
|
WriteDefinitions(sw, enums, wrappers, Type.CSTypes); // Core definitions
|
2010-12-04 22:51:40 +01:00
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("}");
|
2010-12-06 01:50:36 +01:00
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("#endif");
|
2010-12-04 22:51:40 +01:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
sw.Flush();
|
|
|
|
|
sw.Close();
|
|
|
|
|
}
|
2010-12-04 22:51:40 +01:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
string output_header = Path.Combine(Settings.OutputPath, OutputFileHeader);
|
|
|
|
|
Move(sw_h.File, output_header);
|
|
|
|
|
}
|
2010-12-04 22:51:40 +01:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
void Move(string file, string dest)
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(dest))
|
|
|
|
|
File.Delete(dest);
|
|
|
|
|
File.Move(file, dest);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
static Delegate WriteWrapper(Delegate last_delegate, Function f, BindStreamWriter sw)
|
|
|
|
|
{
|
|
|
|
|
if (last_delegate == f.WrappedDelegate)
|
|
|
|
|
return last_delegate; // Multiple wrappers for the same delegate are not necessary in C++
|
|
|
|
|
last_delegate = f.WrappedDelegate;
|
|
|
|
|
|
|
|
|
|
var parameters = f.WrappedDelegate.Parameters.ToString()
|
|
|
|
|
.Replace("String[]", "String*")
|
|
|
|
|
.Replace("[OutAttribute]", String.Empty);
|
|
|
|
|
sw.WriteLine("inline {0} {1}{2}", f.WrappedDelegate.ReturnType,
|
|
|
|
|
f.TrimmedName, parameters);
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
|
|
|
|
WriteMethodBody(sw, f);
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("}");
|
|
|
|
|
return last_delegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Delegate WriteInitDelegate(Delegate last_delegate, BindStreamWriter sw, Function f)
|
|
|
|
|
{
|
|
|
|
|
if (last_delegate != f.WrappedDelegate)
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("Delegates::{0}() = (Delegates::p{0})OpenTK::Internals::GetAddress(\"gl{0}\");", f.WrappedDelegate.Name);
|
|
|
|
|
last_delegate = f.WrappedDelegate;
|
|
|
|
|
}
|
|
|
|
|
return last_delegate;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region WriteDefinitions
|
2010-12-06 01:50:36 +01:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
void WriteDefinitions(BindStreamWriter sw,
|
|
|
|
|
EnumCollection enums, FunctionCollection wrappers,
|
2011-09-26 13:18:57 +02:00
|
|
|
|
Dictionary<string, string> CSTypes)
|
2010-12-06 23:32:47 +01:00
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("namespace {0}", Settings.GLClass);
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
2010-12-04 22:51:40 +01:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
foreach (string extension in wrappers.Keys)
|
2010-12-05 10:08:57 +01:00
|
|
|
|
{
|
2010-12-06 23:32:47 +01:00
|
|
|
|
if (extension != "Core")
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("namespace {0}", extension);
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
|
|
|
|
}
|
2010-12-05 10:08:57 +01:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
// Avoid multiple definitions of the same function
|
|
|
|
|
Delegate last_delegate = null;
|
|
|
|
|
|
|
|
|
|
// Write delegates
|
|
|
|
|
sw.WriteLine("namespace Delegates");
|
2010-12-05 10:08:57 +01:00
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
2011-09-26 13:18:57 +02:00
|
|
|
|
var functions = wrappers[extension];
|
2010-12-06 23:32:47 +01:00
|
|
|
|
last_delegate = null;
|
2011-09-26 13:18:57 +02:00
|
|
|
|
foreach (var f in functions.Where(f => !f.Deprecated))
|
2010-12-06 23:32:47 +01:00
|
|
|
|
{
|
|
|
|
|
WriteDelegate(sw, f.WrappedDelegate, ref last_delegate);
|
|
|
|
|
}
|
2011-09-26 13:18:57 +02:00
|
|
|
|
last_delegate = null;
|
|
|
|
|
sw.WriteLine("#if defined({0})", AllowDeprecated);
|
|
|
|
|
foreach (var f in functions.Where(f => f.Deprecated))
|
|
|
|
|
{
|
|
|
|
|
WriteDelegate(sw, f.WrappedDelegate, ref last_delegate);
|
|
|
|
|
}
|
|
|
|
|
sw.WriteLine("#endif");
|
2010-12-05 10:08:57 +01:00
|
|
|
|
|
|
|
|
|
sw.Unindent();
|
2010-12-06 23:32:47 +01:00
|
|
|
|
sw.WriteLine("};");
|
|
|
|
|
|
|
|
|
|
// Write wrappers
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("inline void Init()");
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
2010-12-06 23:32:47 +01:00
|
|
|
|
last_delegate = null;
|
2011-09-26 13:18:57 +02:00
|
|
|
|
foreach (var f in functions.Where(f => !f.Deprecated))
|
2010-12-06 23:32:47 +01:00
|
|
|
|
{
|
2011-09-26 13:18:57 +02:00
|
|
|
|
last_delegate = WriteInitDelegate(last_delegate, sw, f);
|
|
|
|
|
}
|
|
|
|
|
last_delegate = null;
|
|
|
|
|
sw.WriteLine("#if defined({0})", AllowDeprecated);
|
|
|
|
|
foreach (var f in functions.Where(f => f.Deprecated))
|
|
|
|
|
{
|
|
|
|
|
last_delegate = WriteInitDelegate(last_delegate, sw, f);
|
|
|
|
|
}
|
|
|
|
|
sw.WriteLine("#endif");
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("}");
|
|
|
|
|
last_delegate = null;
|
|
|
|
|
foreach (var f in functions.Where(f => !f.Deprecated))
|
|
|
|
|
{
|
|
|
|
|
last_delegate = WriteWrapper(last_delegate, f, sw);
|
|
|
|
|
}
|
|
|
|
|
sw.WriteLine("#if defined({0})", AllowDeprecated);
|
|
|
|
|
foreach (var f in functions.Where(f => f.Deprecated))
|
|
|
|
|
{
|
|
|
|
|
last_delegate = WriteWrapper(last_delegate, f, sw);
|
2010-12-06 23:32:47 +01:00
|
|
|
|
}
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("#endif");
|
2010-12-06 23:32:47 +01:00
|
|
|
|
|
|
|
|
|
if (extension != "Core")
|
|
|
|
|
{
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("};");
|
|
|
|
|
}
|
2010-12-05 10:08:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("};");
|
|
|
|
|
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("}");
|
2010-12-04 22:51:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2010-12-06 10:52:05 +01:00
|
|
|
|
static string GetNamespace(string ext)
|
|
|
|
|
{
|
|
|
|
|
if (ext == "Core")
|
|
|
|
|
return Settings.GLClass;
|
|
|
|
|
else
|
|
|
|
|
return String.Format("{0}::{1}", Settings.GLClass, Char.IsDigit(ext[0]) ? DigitPrefix + ext : ext);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
#region WriteEnums
|
|
|
|
|
|
|
|
|
|
public void WriteEnums(BindStreamWriter sw, EnumCollection enums)
|
|
|
|
|
{
|
|
|
|
|
foreach (Enum @enum in enums.Values)
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("struct {0} : Enumeration<{0}>", @enum.Name);
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
|
|
|
|
sw.WriteLine("inline {0}(int value) : Enumeration<{0}>(value) {{ }}", @enum.Name);
|
|
|
|
|
sw.WriteLine("enum");
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
|
|
|
|
foreach (var c in @enum.ConstantCollection.Values)
|
|
|
|
|
{
|
|
|
|
|
// C++ doesn't have the concept of "unchecked", so remove this.
|
|
|
|
|
if (!c.Unchecked)
|
|
|
|
|
sw.WriteLine("{0},", c);
|
|
|
|
|
else
|
|
|
|
|
sw.WriteLine("{0},", c.ToString().Replace("unchecked", String.Empty));
|
|
|
|
|
}
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("};");
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("};");
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region WriteTypes
|
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
void WriteTypes(BindStreamWriter sw)
|
2010-12-06 23:32:47 +01:00
|
|
|
|
{
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine(TypeDefinitions);
|
2010-12-06 23:32:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
#region WriteGetAddress
|
2010-12-05 10:08:57 +01:00
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
void WriteGetAddress(BindStreamWriter sw)
|
2010-12-05 10:08:57 +01:00
|
|
|
|
{
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine(GetAddressDefinition);
|
2010-12-05 11:47:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-26 13:18:57 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region WriteDelegate
|
|
|
|
|
|
2010-12-05 11:47:06 +01:00
|
|
|
|
static void WriteDelegate(BindStreamWriter sw, Delegate d, ref Delegate last_delegate)
|
|
|
|
|
{
|
|
|
|
|
// Avoid multiple definitions of the same function
|
|
|
|
|
if (d != last_delegate)
|
|
|
|
|
{
|
|
|
|
|
last_delegate = d;
|
2010-12-05 16:33:09 +01:00
|
|
|
|
var parameters = d.Parameters.ToString()
|
2010-12-05 17:03:42 +01:00
|
|
|
|
.Replace("String[]", "String*")
|
2010-12-05 16:33:09 +01:00
|
|
|
|
.Replace("[OutAttribute]", String.Empty);
|
2010-12-07 02:26:11 +01:00
|
|
|
|
sw.WriteLine("typedef {0} (APIENTRY *p{1}){2};", d.ReturnType, d.Name, parameters);
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("inline p{0}& {0}()", d.Name);
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.Indent();
|
|
|
|
|
sw.WriteLine("static p{0} address = 0;", d.Name);
|
|
|
|
|
sw.WriteLine("return address;");
|
|
|
|
|
sw.Unindent();
|
|
|
|
|
sw.WriteLine("}");
|
2010-12-05 11:47:06 +01:00
|
|
|
|
}
|
2010-12-05 10:08:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2010-12-04 22:51:40 +01:00
|
|
|
|
#region WriteWrappers
|
|
|
|
|
|
2010-12-05 16:26:54 +01:00
|
|
|
|
static void WriteMethodBody(BindStreamWriter sw, Function f)
|
|
|
|
|
{
|
2011-09-26 13:18:57 +02:00
|
|
|
|
|
2010-12-06 23:32:47 +01:00
|
|
|
|
var callstring = f.Parameters.CallString()
|
2010-12-05 17:03:42 +01:00
|
|
|
|
.Replace("String[]", "String*");
|
2010-12-05 16:33:09 +01:00
|
|
|
|
if (f.ReturnType != null && !f.ReturnType.ToString().ToLower().Contains("void"))
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("return Delegates::{0}(){1};", f.WrappedDelegate.Name, callstring);
|
2010-12-05 16:26:54 +01:00
|
|
|
|
else
|
2011-09-26 13:18:57 +02:00
|
|
|
|
sw.WriteLine("Delegates::{0}(){1};", f.WrappedDelegate.Name, callstring);
|
2010-12-05 16:26:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-04 22:51:40 +01:00
|
|
|
|
static DocProcessor processor = new DocProcessor(Path.Combine(Settings.DocPath, Settings.DocFile));
|
|
|
|
|
static Dictionary<string, string> docfiles;
|
|
|
|
|
void WriteDocumentation(BindStreamWriter sw, Function f)
|
|
|
|
|
{
|
|
|
|
|
if (docfiles == null)
|
|
|
|
|
{
|
|
|
|
|
docfiles = new Dictionary<string, string>();
|
|
|
|
|
foreach (string file in Directory.GetFiles(Settings.DocPath))
|
|
|
|
|
{
|
|
|
|
|
docfiles.Add(Path.GetFileName(file), file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string docfile = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
docfile = Settings.FunctionPrefix + f.WrappedDelegate.Name + ".xml";
|
|
|
|
|
if (!docfiles.ContainsKey(docfile))
|
|
|
|
|
docfile = Settings.FunctionPrefix + f.TrimmedName + ".xml";
|
|
|
|
|
if (!docfiles.ContainsKey(docfile))
|
|
|
|
|
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
|
|
|
|
|
|
|
|
|
string doc = null;
|
|
|
|
|
if (docfiles.ContainsKey(docfile))
|
|
|
|
|
{
|
|
|
|
|
doc = processor.ProcessFile(docfiles[docfile]);
|
|
|
|
|
}
|
|
|
|
|
if (doc == null)
|
|
|
|
|
{
|
|
|
|
|
doc = "/// <summary></summary>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int summary_start = doc.IndexOf("<summary>") + "<summary>".Length;
|
|
|
|
|
string warning = "[deprecated: v{0}]";
|
|
|
|
|
string category = "[requires: {0}]";
|
|
|
|
|
if (f.Deprecated)
|
|
|
|
|
{
|
|
|
|
|
warning = String.Format(warning, f.DeprecatedVersion);
|
|
|
|
|
doc = doc.Insert(summary_start, warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
|
|
|
|
{
|
|
|
|
|
category = String.Format(category, f.Category);
|
|
|
|
|
doc = doc.Insert(summary_start, category);
|
|
|
|
|
}
|
|
|
|
|
else if (!String.IsNullOrEmpty(f.Version))
|
|
|
|
|
{
|
|
|
|
|
if (f.Category.StartsWith("VERSION"))
|
|
|
|
|
category = String.Format(category, "v" + f.Version);
|
|
|
|
|
else
|
|
|
|
|
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
|
|
|
|
doc = doc.Insert(summary_start, category);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sw.WriteLine(doc);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("[Warning] Error processing file {0}: {1}", docfile, e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region WriteLicense
|
|
|
|
|
|
|
|
|
|
public void WriteLicense(BindStreamWriter sw)
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine(File.ReadAllText(Path.Combine(Settings.InputPath, Settings.LicenseFile)));
|
|
|
|
|
sw.WriteLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|