[GB.OPENGL.GLSL]

* NEW: Add support for Gl.GetUniformLocation and Gl.UniformMatrix**** methods


git-svn-id: svn://localhost/gambas/trunk@2598 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Laurent Carlier 2010-01-03 23:42:48 +00:00
parent 4650ed69c3
commit 61a84a8483
3 changed files with 275 additions and 0 deletions

View file

@ -54,6 +54,7 @@ GB_DESC Cgl[] =
GB_STATIC_METHOD("UseProgram", NULL, GLUSEPROGRAM, "(Program)i"),
GB_STATIC_METHOD("ValidateProgram", NULL, GLVALIDATEPROGRAM, "(Program)i"),
/* GLuniform.c */
GB_STATIC_METHOD("GetUniformLocation", NULL, GLGETUNIFORMLOCATION, "(Program)i(Name)s"),
GB_STATIC_METHOD("Uniform1f", NULL, GLUNIFORM1F, "(Location)i(V0)f"),
GB_STATIC_METHOD("Uniform2f", NULL, GLUNIFORM2F, "(Location)i(V0)f(V1)f"),
GB_STATIC_METHOD("Uniform3f", NULL, GLUNIFORM3F, "(Location)i(V0)f(V1)f(V2)f"),
@ -70,6 +71,15 @@ GB_DESC Cgl[] =
GB_STATIC_METHOD("Uniform2iv", NULL, GLUNIFORM2IV, "(Location)i(Values)Integer[]"),
GB_STATIC_METHOD("Uniform3iv", NULL, GLUNIFORM3IV, "(Location)i(Values)Integer[]"),
GB_STATIC_METHOD("Uniform4iv", NULL, GLUNIFORM4IV, "(Location)i(Values)Integer[]"),
GB_STATIC_METHOD("UniformMatrix2fv", NULL, GLUNIFORMMATRIX2FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix3fv", NULL, GLUNIFORMMATRIX3FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix4fv", NULL, GLUNIFORMMATRIX4FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix2x3fv", NULL, GLUNIFORMMATRIX2X3FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix3x2fv", NULL, GLUNIFORMMATRIX3X2FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix2x4fv", NULL, GLUNIFORMMATRIX2X4FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix4x2fv", NULL, GLUNIFORMMATRIX4X2FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix3x4fv", NULL, GLUNIFORMMATRIX3X4FV, "(Location)i(Transpose)b(Values)Float[]"),
GB_STATIC_METHOD("UniformMatrix4x3fv", NULL, GLUNIFORMMATRIX4X3FV, "(Location)i(Transpose)b(Values)Float[]"),
/* Contants */
GB_CONSTANT("GL_ACTIVE_ATTRIBUTES", "i", GL_ACTIVE_ATTRIBUTES),

View file

@ -24,6 +24,18 @@
#include "GL.h"
BEGIN_METHOD(GLGETUNIFORMLOCATION, GB_INTEGER program; GB_STRING name)
if (!LENGTH(name))
{
GB.ReturnInteger(0);
return;
}
GB.ReturnInteger(glGetUniformLocation(VARG(program), GB.ToZeroString(ARG(name))));
END_METHOD
BEGIN_METHOD(GLUNIFORM1F, GB_INTEGER location; GB_FLOAT v0)
glUniform1f(VARG(location), VARG(v0));
@ -261,3 +273,246 @@ BEGIN_METHOD(GLUNIFORM4IV, GB_INTEGER location; GB_OBJECT array)
glUniform4iv(VARG(location), count, values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX2FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%4 ? (4-(count%4)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/4)+fill;
glUniformMatrix2fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX3FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%9 ? (9-(count%9)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/9)+fill;
glUniformMatrix3fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX4FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%16 ? (16-(count%16)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/16)+fill;
glUniformMatrix4fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX2X3FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%6 ? (6-(count%6)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/6)+fill;
glUniformMatrix2x3fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX3X2FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%6 ? (6-(count%6)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/6)+fill;
glUniformMatrix3x2fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX2X4FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%8 ? (8-(count%8)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/8)+fill;
glUniformMatrix2x4fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX4X2FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%8 ? (8-(count%8)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/8)+fill;
glUniformMatrix4x2fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX3X4FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%12 ? (12-(count%12)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/12)+fill;
glUniformMatrix3x4fv(VARG(location), count, VARG(transpose), values);
END_METHOD
BEGIN_METHOD(GLUNIFORMMATRIX4X3FV, GB_INTEGER location; GB_BOOLEAN transpose; GB_OBJECT array)
GB_ARRAY fArray = VARG(array);
int count = GB.Array.Count(fArray);
int fill = count%12 ? (12-(count%12)) : 0;
if (!count)
return;
GLfloat values[count+fill];
int i;
for (i=0; i<count; i++)
values[i] = *((GLfloat *)GB.Array.Get(fArray, i));
if (fill)
{
for (i=1; i<=fill; i++)
values[count+i] = 0;
fill = 1;
}
count = (count/12)+fill;
glUniformMatrix4x3fv(VARG(location), count, VARG(transpose), values);
END_METHOD

View file

@ -25,6 +25,7 @@
#include "main.h"
DECLARE_METHOD(GLGETUNIFORMLOCATION);
DECLARE_METHOD(GLUNIFORM1F);
DECLARE_METHOD(GLUNIFORM2F);
DECLARE_METHOD(GLUNIFORM3F);
@ -41,5 +42,14 @@ DECLARE_METHOD(GLUNIFORM1IV);
DECLARE_METHOD(GLUNIFORM2IV);
DECLARE_METHOD(GLUNIFORM3IV);
DECLARE_METHOD(GLUNIFORM4IV);
DECLARE_METHOD(GLUNIFORMMATRIX2FV);
DECLARE_METHOD(GLUNIFORMMATRIX3FV);
DECLARE_METHOD(GLUNIFORMMATRIX4FV);
DECLARE_METHOD(GLUNIFORMMATRIX2X3FV);
DECLARE_METHOD(GLUNIFORMMATRIX3X2FV);
DECLARE_METHOD(GLUNIFORMMATRIX2X4FV);
DECLARE_METHOD(GLUNIFORMMATRIX4X2FV);
DECLARE_METHOD(GLUNIFORMMATRIX3X4FV);
DECLARE_METHOD(GLUNIFORMMATRIX4X3FV);
#endif /* __GLUNIFORM_H */