namespace gl
{
void ActiveTexture(GLenum texture)
{
Log("ActiveTexture");
glActiveTexture(texture);
}
}
Simplified, but it should get the basic idea across. A similar problem comes up in generating mocks for unit testing purposes. Anybody know how I can pull this off mechanically? I need something like SWIG, except it needs to circle around and generate C(++) code again. Something designed to unit test C would probably do the trick as well. Google yields entirely C# and C++ results, unfortunately.
How to create a wrapper around a C interface?
#1 Moderators - Reputation: 2487
Posted 23 November 2011 - 08:30 PM
#2 Senior Moderators - Reputation: 4739
Posted 23 November 2011 - 08:57 PM
In the case of OpenGL, wouldn't it be easier to generate the wrapper directly from the .spec file?
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#3 Members - Reputation: 360
Posted 23 November 2011 - 09:37 PM
I wouldn't mock any more than maybe 20 functions per executable, including functions you don't use on classes that are instantiated.
#4 Moderators - Reputation: 2487
Posted 23 November 2011 - 09:57 PM
Meh? SWIG and other tools seem to manage it okay.This strikes me as exceedingly hard tricky to do in the general case. Given C's syntactical quirks, extracting the function signatures from the source code may need darn near the entire front half of a C compiler.
And how does one do that, exactly?In the case of OpenGL, wouldn't it be easier to generate the wrapper directly from the .spec file?
#5 Moderators - Reputation: 2487
Posted 23 November 2011 - 10:36 PM
#include "OpenGLProxy.h"
#include <OpenGLES/ES2/gl.h>
namespace gl
{
#define LOG(x) LogCall(#x),x
void LogCall(const char* name)
{
}
void ActiveTexture (GLenum texture)
{
LOG(glActiveTexture)(texture);
}
void AttachShader (GLuint program, GLuint shader) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glAttachShader)(program, shader);
}
void BindAttribLocation (GLuint program, GLuint index, const GLchar* name) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBindAttribLocation)(program, index, name);
}
void BindBuffer (GLenum target, GLuint buffer)
{
LOG(glBindBuffer)(target, buffer);
}
void BindFramebuffer (GLenum target, GLuint framebuffer) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBindFramebuffer)(target, framebuffer);
}
void BindRenderbuffer (GLenum target, GLuint renderbuffer) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBindRenderbuffer)(target, renderbuffer);
}
void BindTexture (GLenum target, GLuint texture)
{
LOG(glBindTexture)(target, texture);
}
void BlendColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBlendColor)(red, green, blue, alpha);
}
void BlendEquation ( GLenum mode ) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBlendEquation)(mode);
}
void BlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBlendEquationSeparate)(modeRGB, modeAlpha);
}
void BlendFunc (GLenum sfactor, GLenum dfactor)
{
LOG(glBlendFunc)(sfactor, dfactor);
}
void BlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glBlendFuncSeparate)(srcRGB, dstRGB, srcAlpha, dstAlpha);
}
void BufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
{
LOG(glBufferData)(target, size, data, usage);
}
void BufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data)
{
LOG(glBufferSubData)(target, offset, size, data);
}
GLenum CheckFramebufferStatus (GLenum target) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glCheckFramebufferStatus)(target);
}
void Clear (GLbitfield mask)
{
LOG(glClear)(mask);
}
void ClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
{
LOG(glClearColor)(red, green, blue, alpha);
}
void ClearDepthf (GLclampf depth)
{
LOG(glClearDepthf)(depth);
}
void ClearStencil (GLint s)
{
LOG(glClearStencil)(s);
}
void ColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
{
LOG(glColorMask)(red, green, blue, alpha);
}
void CompileShader (GLuint shader) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glCompileShader)(shader);
}
void CompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data)
{
LOG(glCompressedTexImage2D)(target, level, internalformat, width, height, border, imageSize, data);
}
void CompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data)
{
LOG(glCompressedTexSubImage2D)(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
void CopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
LOG(glCopyTexImage2D)(target, level, internalformat, x, y, width, height, border);
}
void CopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
{
LOG(glCopyTexSubImage2D)(target, level, xoffset, yoffset, x, y, width, height);
}
GLuint CreateProgram (void) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glCreateProgram)();
}
GLuint CreateShader (GLenum type) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glCreateShader)(type);
}
void CullFace (GLenum mode)
{
LOG(glCullFace)(mode);
}
void DeleteBuffers (GLsizei n, const GLuint* buffers)
{
LOG(glDeleteBuffers)(n, buffers);
}
void DeleteFramebuffers (GLsizei n, const GLuint* framebuffers) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glDeleteFramebuffers)(n, framebuffers);
}
void DeleteProgram (GLuint program) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glDeleteProgram)(program);
}
void DeleteRenderbuffers (GLsizei n, const GLuint* renderbuffers) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glDeleteRenderbuffers)(n, renderbuffers);
}
void DeleteShader (GLuint shader) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glDeleteShader)(shader);
}
void DeleteTextures (GLsizei n, const GLuint* textures)
{
LOG(glDeleteTextures)(n, textures);
}
void DepthFunc (GLenum func)
{
LOG(glDepthFunc)(func);
}
void DepthMask (GLboolean flag)
{
LOG(glDepthMask)(flag);
}
void DepthRangef (GLclampf zNear, GLclampf zFar)
{
LOG(glDepthRangef)(zNear, zFar);
}
void DetachShader (GLuint program, GLuint shader) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glDetachShader)(program, shader);
}
void Disable (GLenum cap)
{
LOG(glDisable)(cap);
}
void DisableVertexAttribArray (GLuint index) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glDisableVertexAttribArray)(index);
}
void DrawArrays (GLenum mode, GLint first, GLsizei count)
{
LOG(glDrawArrays)(mode, first, count);
}
void DrawElements (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
{
LOG(glDrawElements)(mode, count, type, indices);
}
void Enable (GLenum cap)
{
LOG(glEnable)(cap);
}
void EnableVertexAttribArray (GLuint index) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glEnableVertexAttribArray)(index);
}
void Finish (void)
{
LOG(glFinish)();
}
void Flush (void)
{
LOG(glFlush)();
}
void FramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glFramebufferRenderbuffer)(target, attachment, renderbuffertarget, renderbuffer);
}
void FramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glFramebufferTexture2D)(target, attachment, textarget, texture, level);
}
void FrontFace (GLenum mode)
{
LOG(glFrontFace)(mode);
}
void GenBuffers (GLsizei n, GLuint* buffers)
{
LOG(glGenBuffers)(n, buffers);
}
void GenerateMipmap (GLenum target) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGenerateMipmap)(target);
}
void GenFramebuffers (GLsizei n, GLuint* framebuffers) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGenFramebuffers)(n, framebuffers);
}
void GenRenderbuffers (GLsizei n, GLuint* renderbuffers) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGenRenderbuffers)(n, renderbuffers);
}
void GenTextures (GLsizei n, GLuint* textures)
{
LOG(glGenTextures)(n, textures);
}
void GetActiveAttrib (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetActiveAttrib)(program, index, bufsize, length, size, type, name);
}
void GetActiveUniform (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetActiveUniform)(program, index, bufsize, length, size, type, name);
}
void GetAttachedShaders (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetAttachedShaders)(program, maxcount, count, shaders);
}
int GetAttribLocation (GLuint program, const GLchar* name) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glGetAttribLocation)(program, name);
}
void GetBooleanv (GLenum pname, GLboolean* params)
{
LOG(glGetBooleanv)(pname, params);
}
void GetBufferParameteriv (GLenum target, GLenum pname, GLint* params)
{
LOG(glGetBufferParameteriv)(target, pname, params);
}
GLenum GetError (void)
{
return LOG(glGetError)();
}
void GetFloatv (GLenum pname, GLfloat* params)
{
LOG(glGetFloatv)(pname, params);
}
void GetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetFramebufferAttachmentParameteriv)(target, attachment, pname, params);
}
void GetIntegerv (GLenum pname, GLint* params)
{
LOG(glGetIntegerv)(pname, params);
}
void GetProgramiv (GLuint program, GLenum pname, GLint* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetProgramiv)(program, pname, params);
}
void GetProgramInfoLog (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetProgramInfoLog)(program, bufsize, length, infolog);
}
void GetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetRenderbufferParameteriv)(target, pname, params);
}
void GetShaderiv (GLuint shader, GLenum pname, GLint* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetShaderiv)(shader, pname, params);
}
void GetShaderInfoLog (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetShaderInfoLog)(shader, bufsize, length, infolog);
}
void GetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetShaderPrecisionFormat)(shadertype, precisiontype, range, precision);
}
void GetShaderSource (GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetShaderSource)(shader, bufsize, length, source);
}
const GLubyte* GetString (GLenum name)
{
return LOG(glGetString)(name);
}
void GetTexParameterfv (GLenum target, GLenum pname, GLfloat* params)
{
GetTexParameterfv(target, pname, params);
}
void GetTexParameteriv (GLenum target, GLenum pname, GLint* params)
{
LOG(glGetTexParameteriv)(target, pname, params);
}
void GetUniformfv (GLuint program, GLint location, GLfloat* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetUniformfv)(program, location, params);
}
void GetUniformiv (GLuint program, GLint location, GLint* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetUniformiv)(program, location, params);
}
int GetUniformLocation (GLuint program, const GLchar* name) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glGetUniformLocation)(program, name);
}
void GetVertexAttribfv (GLuint index, GLenum pname, GLfloat* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetVertexAttribfv)(index, pname, params);
}
void GetVertexAttribiv (GLuint index, GLenum pname, GLint* params) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetVertexAttribiv)(index, pname, params);
}
void GetVertexAttribPointerv (GLuint index, GLenum pname, GLvoid** pointer) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glGetVertexAttribPointerv)(index, pname, pointer);
}
void Hint (GLenum target, GLenum mode)
{
LOG(glHint)(target, mode);
}
GLboolean IsBuffer (GLuint buffer)
{
return LOG(glIsBuffer)(buffer);
}
GLboolean IsEnabled (GLenum cap)
{
return LOG(glIsEnabled)(cap);
}
GLboolean IsFramebuffer (GLuint framebuffer) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glIsFramebuffer)(framebuffer);
}
GLboolean IsProgram (GLuint program)
{
return LOG(glIsProgram)(program);
}
GLboolean IsRenderbuffer (GLuint renderbuffer) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glIsRenderbuffer)(renderbuffer);
}
GLboolean IsShader (GLuint shader) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
return LOG(glIsShader)(shader);
}
GLboolean IsTexture (GLuint texture)
{
return LOG(glIsTexture)(texture);
}
void LineWidth (GLfloat width)
{
LOG(glLineWidth)(width);
}
void LinkProgram (GLuint program) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glLinkProgram)(program);
}
void PixelStorei (GLenum pname, GLint param)
{
LOG(glPixelStorei)(pname, param);
}
void PolygonOffset (GLfloat factor, GLfloat units)
{
LOG(glPolygonOffset)(factor, units);
}
void ReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)
{
LOG(glReadPixels)(x, y, width, height, format, type, pixels);
}
void ReleaseShaderCompiler (void) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glReleaseShaderCompiler)();
}
void RenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glRenderbufferStorage)(target, internalformat, width, height);
}
void SampleCoverage (GLclampf value, GLboolean invert)
{
LOG(glSampleCoverage)(value, invert);
}
void Scissor (GLint x, GLint y, GLsizei width, GLsizei height)
{
LOG(glScissor)(x, y, width, height);
}
void ShaderBinary (GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glShaderBinary)(n, shaders, binaryformat, binary, length);
}
void ShaderSource (GLuint shader, GLsizei count, const GLchar** string, const GLint* length) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glShaderSource)(shader, count, string, length);
}
void StencilFunc (GLenum func, GLint ref, GLuint mask)
{
LOG(glStencilFunc)(func, ref, mask);
}
void StencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glStencilFuncSeparate)(face, func, ref, mask);
}
void StencilMask (GLuint mask)
{
LOG(glStencilMask)(mask);
}
void StencilMaskSeparate (GLenum face, GLuint mask) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glStencilMaskSeparate)(face, mask);
}
void StencilOp (GLenum fail, GLenum zfail, GLenum zpass)
{
LOG(glStencilOp)(fail, zfail, zpass);
}
void StencilOpSeparate (GLenum face, GLenum fail, GLenum zfail, GLenum zpass) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glStencilOpSeparate)(face, fail, zfail, zpass);
}
void TexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
{
LOG(glTexImage2D)(target, level, internalformat, width, height, border, format, type, pixels);
}
void TexParameterf (GLenum target, GLenum pname, GLfloat param)
{
LOG(glTexParameterf)(target, pname, param);
}
void TexParameterfv (GLenum target, GLenum pname, const GLfloat* params)
{
LOG(glTexParameterfv)(target, pname, params);
}
void TexParameteri (GLenum target, GLenum pname, GLint param)
{
LOG(glTexParameteri)(target, pname, param);
}
void TexParameteriv (GLenum target, GLenum pname, const GLint* params)
{
LOG(glTexParameteriv)(target, pname, params);
}
void TexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels)
{
LOG(glTexSubImage2D)(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
void Uniform1f (GLint location, GLfloat x) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform1f)(location, x);
}
void Uniform1fv (GLint location, GLsizei count, const GLfloat* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform1fv)(location, count, v);
}
void Uniform1i (GLint location, GLint x) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform1i)(location, x);
}
void Uniform1iv (GLint location, GLsizei count, const GLint* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform1iv)(location, count, v);
}
void Uniform2f (GLint location, GLfloat x, GLfloat y) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform2f)(location, x, y);
}
void Uniform2fv (GLint location, GLsizei count, const GLfloat* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform2fv)(location, count, v);
}
void Uniform2i (GLint location, GLint x, GLint y) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform2i)(location, x, y);
}
void Uniform2iv (GLint location, GLsizei count, const GLint* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform2iv)(location, count, v);
}
void Uniform3f (GLint location, GLfloat x, GLfloat y, GLfloat z) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform3f)(location, x, y, z);
}
void Uniform3fv (GLint location, GLsizei count, const GLfloat* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform3fv)(location, count, v);
}
void Uniform3i (GLint location, GLint x, GLint y, GLint z) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform3i)(location, x, y, z);
}
void Uniform3iv (GLint location, GLsizei count, const GLint* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform3iv)(location, count, v);
}
void Uniform4f (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform4f)(location, x, y, z, w);
}
void Uniform4fv (GLint location, GLsizei count, const GLfloat* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform4fv)(location, count, v);
}
void Uniform4i (GLint location, GLint x, GLint y, GLint z, GLint w) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform4i)(location, x, y, z, w);
}
void Uniform4iv (GLint location, GLsizei count, const GLint* v) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniform4iv)(location, count, v);
}
void UniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniformMatrix2fv)(location, count, transpose, value);
}
void UniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniformMatrix3fv)(location, count, transpose, value);
}
void UniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUniformMatrix4fv)(location, count, transpose, value);
}
void UseProgram (GLuint program) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glUseProgram)(program);
}
void ValidateProgram (GLuint program) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glValidateProgram)(program);
}
void VertexAttrib1f (GLuint indx, GLfloat x) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib1f)(indx, x);
}
void VertexAttrib1fv (GLuint indx, const GLfloat* values) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib1fv)(indx, values);
}
void VertexAttrib2f (GLuint indx, GLfloat x, GLfloat y) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib2f)(indx, x, y);
}
void VertexAttrib2fv (GLuint indx, const GLfloat* values) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib2fv)(indx, values);
}
void VertexAttrib3f (GLuint indx, GLfloat x, GLfloat y, GLfloat z) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib3f)(indx, x, y, z);
}
void VertexAttrib3fv (GLuint indx, const GLfloat* values) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib3fv)(indx, values);
}
void VertexAttrib4f (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib4f)(indx, x, y, z, w);
}
void VertexAttrib4fv (GLuint indx, const GLfloat* values) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttrib4fv)(indx, values);
}
void VertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr) __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)
{
LOG(glVertexAttribPointer)(indx, size, type, normalized, stride, ptr);
}
void Viewport (GLint x, GLint y, GLsizei width, GLsizei height)
{
LOG(glViewport)(x, y, width, height);
}
}
#6 Senior Moderators - Reputation: 4739
Posted 23 November 2011 - 10:53 PM
Not really. From the SWIG documentation:Meh? SWIG and other tools seem to manage it okay.
"It is important to know that SWIG is a fairly complete C++ compiler with support for nearly every language feature. This includes preprocessing, pointers, classes, inheritance, and even C++ templates."
GLEW does it with a perl script.And how does one do that, exactly?In the case of OpenGL, wouldn't it be easier to generate the wrapper directly from the .spec file?
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#8 Members - Reputation: 3827
Posted 24 November 2011 - 04:15 AM
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.
#9 Members - Reputation: 1956
Posted 24 November 2011 - 04:37 AM
GLEW does it with a perl script.And how does one do that, exactly?In the case of OpenGL, wouldn't it be easier to generate the wrapper directly from the .spec file?
I'm using a PHP script for that, because GLEW does not do exactly what I want, and personally I find Perl repulsive (but hey, anyone else is free to have the same opinion on PHP!), so modifying the already existing script was no option for me.
Do not underestimate the trouble of getting information out of the spec file, it is nowhere as trivial as it may seem at first glance. Mostly, that's because the left hand doesn't know what the right hand is doing, i.e. the spec file is not entirely consistent in all places (plus, it is not bug-free).
In hindsight, you really really really need a very good reason not to just use GLEW, even if it does not do exactly what you want. Even if you think that it doesn't do what you want at all, still think twice before doing this yourself. I feel stupid for having wasted weeks of my time rather than just coping with a third party library that isn't perfect, but nevertheless kind-of-works out of the box.
About the logging and GLIntercept, +1 for mhagain.
#10 Members - Reputation: 1264
Posted 24 November 2011 - 05:13 AM
It's not moot at all, as I'd still love to do this for other C (and C++ for that matter) APIs that I work with...
http://www.gccxml.org/HTML/Index.html ?
#11 Senior Moderators - Reputation: 4739
Posted 24 November 2011 - 08:44 AM
Gnat, meet sledgehammer.
However, it does nicely solve the whole 'writing a front end to compiler' issue. And as auto-magic wrapper creation goes, Pyste (which uses GCC-XML under the hood), is quite an interesting beast.
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#12 Moderators - Reputation: 2487
Posted 24 November 2011 - 10:22 AM
GCC-XML is a absolutely a sledgehammer, but I'd forgotten it exists and in the general case that may be what it takes for these sorts of problems. Combined with a scripting language that can read XML and do text generation nicely (I'm thinking Python?) I can probably bend it to my whims. Of course for an API the size of ES, it took me all of half an hour to simply write the API by hand so I guess sometimes there's just no substitute for doing the work. And just a little boost wackiness later:
glBindFramebuffer(36160, 2) glClearColor(0, 0, 0, 0) glClearDepthf(1) glViewport(0, 0, 320, 480) glClear(16640) glDepthMask(GL_TRUE) glEnable(2929) glUseProgram(6) glGetUniformLocation(6, "u_world") glUniformMatrix4fv(0, 1, GL_FALSE, 0x2fdfe950) glGetUniformLocation(6, "u_worldViewProj") glUniformMatrix4fv(4, 1, GL_FALSE, 0x2fdfe850) glEnableVertexAttribArray(0) glEnableVertexAttribArray(1) glEnableVertexAttribArray(2) glBindBuffer(34962, 5) glBindBuffer(34963, 6) glVertexAttrib4f(3, 1, 1, 1, 1) glVertexAttribPointer(0, 3, 5126, GL_FALSE, 60, 0) glVertexAttribPointer(1, 3, 5126, GL_FALSE, 60, 0x14) glVertexAttribPointer(2, 2, 5126, GL_FALSE, 60, 0xc) glGetUniformLocation(6, "u_materialAmbient") glGetUniformLocation(6, "u_materialDiffuse") glGetUniformLocation(6, "u_diffuseTexture") glGetUniformLocation(6, "u_hasDiffuseMap") glUniform4f(-1, 0, 0, 0, 1) glUniform4f(-1, 1, 1, 1, 1) glActiveTexture(33984) glBindTexture(3553, 5) glUniform1i(-1, 1) glUniform1i(-1, 0) glDrawElements(4, 27606, 5123, 0) glActiveTexture(33984) glBindTexture(3553, 0) glDisableVertexAttribArray(0) glDisableVertexAttribArray(1) glDisableVertexAttribArray(2) glBindBuffer(34962, 0) glBindBuffer(34963, 0)Still need to stringify the constants, kind of wish I had a tool just for that, but not a bad start.
#13 Senior Moderators - Reputation: 4739
Posted 24 November 2011 - 08:59 PM
Python script to operate on the enum spec. Actually, it might be simpler to run a script over the gl.h/glext.h header files, pulling up any defines that assigna hexadecimal value.Still need to stringify the constants, kind of wish I had a tool just for that, but not a bad start.
Either way is a bit sledgehammer-ish, but it would get the job done - and there are enough enum values that you probably don't want to hand-code the lookup table.
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]
#14 Moderators - Reputation: 2487
Posted 24 November 2011 - 10:49 PM
#15 Senior Moderators - Reputation: 4739
Posted 24 November 2011 - 10:59 PM
I sometimes do thatYou're thinking too hard. Funny what you can do with a carefully constructed macro and a regex Find/Replace.
I'm looking at the header again, and it seems to me that there are enums with overlapping values, also, bitmasks. It looks like you may need to do a little in your wrapper to separate out composite bitmasks and to determine the valid set of enums to a given function - assuming that level of detail is actually required.
Tristam MacDonald - SDE @ Amazon - swiftcoding [Need to sync your files via the cloud? | Need affordable web hosting?]






