More GLSL code.
- general constructors allowed; - implement noise functions (from Stefan Gustavson - thanks!) - cosmetic stuff.
This commit is contained in:
parent
e94be8d5c0
commit
3654193a4d
|
@ -30,6 +30,7 @@ PROGS = \
|
|||
geartrain \
|
||||
glinfo \
|
||||
gloss \
|
||||
glslnoise.c \
|
||||
gltestperf \
|
||||
glutfx \
|
||||
isosurf \
|
||||
|
|
|
@ -3,16 +3,28 @@
|
|||
* simple per-pixel lighting.
|
||||
*
|
||||
* Michal Krol
|
||||
* 14 February 2006
|
||||
* 17 February 2006
|
||||
*
|
||||
* Based on the original demo by:
|
||||
* Brian Paul
|
||||
* 17 April 2003
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define GETPROCADDRESS wglGetProcAddress
|
||||
#else
|
||||
#define GETPROCADDRESS glutGetProcAddress
|
||||
#endif
|
||||
|
||||
static GLfloat diffuse[4] = { 0.5f, 0.5f, 1.0f, 1.0f };
|
||||
static GLfloat specular[4] = { 0.8f, 0.8f, 0.8f, 1.0f };
|
||||
|
@ -178,23 +190,15 @@ static void Init (void)
|
|||
|
||||
/* XXX source from uniform diffuse */
|
||||
" vec4 diffuse;\n"
|
||||
" diffuse.xy = vec2 (0.5);\n"
|
||||
" diffuse.zw = vec2 (1.0);\n"
|
||||
" diffuse = vec4 (0.5, 0.5, 1.0, 1.0);\n"
|
||||
|
||||
/* XXX source from uniform specular */
|
||||
" vec4 specular;\n"
|
||||
" specular.xyz = vec3 (0.8);\n"
|
||||
" specular.w = 1.0;\n"
|
||||
" specular = vec4 (0.8, 0.8, 0.8, 1.0);\n"
|
||||
|
||||
" // Compute normalized light direction\n"
|
||||
" vec4 lightDir;\n"
|
||||
" lightDir = lightPos / length (lightPos);\n"
|
||||
" // Compute normalized normal\n"
|
||||
" vec4 normal;\n"
|
||||
" normal = gl_TexCoord[0] / length (gl_TexCoord[0]);\n"
|
||||
" // Compute dot product of light direction and normal vector\n"
|
||||
" float dotProd;\n"
|
||||
" dotProd = clamp (dot (lightDir.xyz, normal.xyz), 0.0, 1.0);\n"
|
||||
" dotProd = clamp (dot (normalize (lightPos).xyz, normalize (gl_TexCoord[0]).xyz), 0.0, 1.0);\n"
|
||||
" // Compute diffuse and specular contributions\n"
|
||||
" gl_FragColor = diffuse * dotProd + specular * pow (dotProd, 20.0);\n"
|
||||
"}\n"
|
||||
|
@ -202,8 +206,7 @@ static void Init (void)
|
|||
static const char *vertShaderText =
|
||||
"void main () {\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" gl_TexCoord[0].xyz = gl_NormalMatrix * gl_Normal;\n"
|
||||
" gl_TexCoord[0].w = 1.0;\n"
|
||||
" gl_TexCoord[0] = vec4 (gl_NormalMatrix * gl_Normal, 1.0);\n"
|
||||
|
||||
/* XXX source from uniform lightPos */
|
||||
" gl_TexCoord[1] = gl_MultiTexCoord0;\n"
|
||||
|
@ -231,13 +234,13 @@ static void Init (void)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) glutGetProcAddress ("glCreateShaderObjectARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) glutGetProcAddress ("glShaderSourceARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) glutGetProcAddress ("glCompileShaderARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) glutGetProcAddress ("glCreateProgramObjectARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) glutGetProcAddress ("glAttachObjectARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) glutGetProcAddress ("glLinkProgramARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) glutGetProcAddress ("glUseProgramObjectARB");
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GETPROCADDRESS ("glCreateShaderObjectARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GETPROCADDRESS ("glShaderSourceARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GETPROCADDRESS ("glCompileShaderARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glCreateProgramObjectARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GETPROCADDRESS ("glAttachObjectARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GETPROCADDRESS ("glLinkProgramARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GETPROCADDRESS ("glUseProgramObjectARB");
|
||||
|
||||
fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
|
||||
glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* GLSL noise demo.
|
||||
*
|
||||
* Michal Krol
|
||||
* 17 February 2006
|
||||
*
|
||||
* Based on the original demo by:
|
||||
* Stefan Gustavson (stegu@itn.liu.se) 2004, 2005
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glut.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#define GETPROCADDRESS wglGetProcAddress
|
||||
#else
|
||||
#define GETPROCADDRESS glutGetProcAddress
|
||||
#endif
|
||||
|
||||
static GLhandleARB fragShader;
|
||||
static GLhandleARB vertShader;
|
||||
static GLhandleARB program;
|
||||
|
||||
static GLfloat u_time = 0.0f;
|
||||
|
||||
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
|
||||
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
|
||||
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
|
||||
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
|
||||
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
|
||||
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
|
||||
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
|
||||
|
||||
static void Redisplay (void)
|
||||
{
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/* XXX source from uniform time */
|
||||
glTexCoord1f (u_time);
|
||||
|
||||
glPushMatrix ();
|
||||
glutSolidSphere (2.0, 20, 10);
|
||||
glPopMatrix ();
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
static void Idle (void)
|
||||
{
|
||||
u_time += 0.1f;
|
||||
glutPostRedisplay ();
|
||||
}
|
||||
|
||||
static void Reshape (int width, int height)
|
||||
{
|
||||
glViewport (0, 0, width, height);
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
glFrustum (-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity ();
|
||||
glTranslatef (0.0f, 0.0f, -15.0f);
|
||||
}
|
||||
|
||||
static void Key (unsigned char key, int x, int y)
|
||||
{
|
||||
(void) x;
|
||||
(void) y;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 27:
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
glutPostRedisplay ();
|
||||
}
|
||||
|
||||
static void Init (void)
|
||||
{
|
||||
static const char *fragShaderText =
|
||||
"void main () {\n"
|
||||
|
||||
/* XXX source from uniform time */
|
||||
" float time;\n"
|
||||
" time = gl_TexCoord[1].x;\n"
|
||||
|
||||
" vec4 v;\n"
|
||||
" v = vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time);\n"
|
||||
" gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (v))), 1.0);\n"
|
||||
"}\n"
|
||||
;
|
||||
static const char *vertShaderText =
|
||||
"void main () {\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" gl_TexCoord[0] = gl_Vertex;\n"
|
||||
" gl_FrontColor = gl_Color;\n"
|
||||
|
||||
/* XXX source from uniform time */
|
||||
" gl_TexCoord[1] = gl_MultiTexCoord0;\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
if (!glutExtensionSupported ("GL_ARB_fragment_shader"))
|
||||
{
|
||||
printf ("Sorry, this demo requires GL_ARB_fragment_shader\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!glutExtensionSupported ("GL_ARB_shader_objects"))
|
||||
{
|
||||
printf ("Sorry, this demo requires GL_ARB_shader_objects\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!glutExtensionSupported ("GL_ARB_shading_language_100"))
|
||||
{
|
||||
printf ("Sorry, this demo requires GL_ARB_shading_language_100\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!glutExtensionSupported ("GL_ARB_vertex_shader"))
|
||||
{
|
||||
printf ("Sorry, this demo requires GL_ARB_vertex_shader\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) wglGetProcAddress ("glCreateShaderObjectARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) wglGetProcAddress ("glShaderSourceARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) wglGetProcAddress ("glCompileShaderARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glCreateProgramObjectARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) wglGetProcAddress ("glAttachObjectARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) wglGetProcAddress ("glLinkProgramARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) wglGetProcAddress ("glUseProgramObjectARB");
|
||||
|
||||
fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB);
|
||||
glShaderSourceARB (fragShader, 1, &fragShaderText, NULL);
|
||||
glCompileShaderARB (fragShader);
|
||||
|
||||
vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB);
|
||||
glShaderSourceARB (vertShader, 1, &vertShaderText, NULL);
|
||||
glCompileShaderARB (vertShader);
|
||||
|
||||
program = glCreateProgramObjectARB ();
|
||||
glAttachObjectARB (program, fragShader);
|
||||
glAttachObjectARB (program, vertShader);
|
||||
glLinkProgramARB (program);
|
||||
glUseProgramObjectARB (program);
|
||||
|
||||
glClearColor (0.0f, 0.1f, 0.3f, 1.0f);
|
||||
glEnable (GL_CULL_FACE);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
|
||||
printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER));
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
glutInit (&argc, argv);
|
||||
glutInitWindowPosition ( 0, 0);
|
||||
glutInitWindowSize (200, 200);
|
||||
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutCreateWindow (argv[0]);
|
||||
glutReshapeFunc (Reshape);
|
||||
glutKeyboardFunc (Key);
|
||||
glutDisplayFunc (Redisplay);
|
||||
glutIdleFunc (Idle);
|
||||
Init ();
|
||||
glutMainLoop ();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1086,13 +1086,13 @@ static int fetch_mem (struct gl2_vertex_shader_intf **vs, const char *name, GLvo
|
|||
{
|
||||
GLubyte *data;
|
||||
|
||||
data = get_address_of (vs, name) + index * size;
|
||||
data = get_address_of (vs, name);
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
if (write)
|
||||
_mesa_memcpy (data, val, size);
|
||||
_mesa_memcpy (data + index * size, val, size);
|
||||
else
|
||||
_mesa_memcpy (val, data, size);
|
||||
_mesa_memcpy (val, data + index * size, size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1101,13 +1101,13 @@ static int fetch_mem_f (struct gl2_fragment_shader_intf **fs, const char *name,
|
|||
{
|
||||
GLubyte *data;
|
||||
|
||||
data = get_address_of_f (fs, name) + index * size;
|
||||
data = get_address_of_f (fs, name);
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
if (write)
|
||||
_mesa_memcpy (data, val, size);
|
||||
_mesa_memcpy (data + index * size, val, size);
|
||||
else
|
||||
_mesa_memcpy (val, data, size);
|
||||
_mesa_memcpy (val, data + index * size, size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1174,28 +1174,24 @@ void exec_vertex_shader (struct gl2_vertex_shader_intf **vs)
|
|||
slang_function *f;
|
||||
slang_assembly_file_restore_point point;
|
||||
slang_machine mach;
|
||||
slang_assembly_local_info info;
|
||||
slang_assembly_name_space space;
|
||||
slang_assemble_ctx A;
|
||||
|
||||
f = &unit->functions.functions[i];
|
||||
slang_assembly_file_restore_point_save (unit->assembly, &point);
|
||||
mach = *unit->machine;
|
||||
mach.ip = unit->assembly->count;
|
||||
info.ret_size = 0;
|
||||
info.addr_tmp = 0;
|
||||
info.swizzle_tmp = 4;
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
|
||||
space.funcs = &unit->functions;
|
||||
space.structs = &unit->structs;
|
||||
space.vars = &unit->globals;
|
||||
|
||||
A.file = unit->assembly;
|
||||
A.mach = unit->machine;
|
||||
A.atoms = unit->atom_pool;
|
||||
A.space = space;
|
||||
A.space.funcs = &unit->functions;
|
||||
A.space.structs = &unit->structs;
|
||||
A.space.vars = &unit->globals;
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
|
||||
_slang_assemble_function_call (&A, f, NULL, 0, GL_FALSE);
|
||||
slang_assembly_file_push (unit->assembly, slang_asm_exit);
|
||||
|
||||
_slang_execute2 (unit->assembly, &mach);
|
||||
slang_assembly_file_restore_point_load (unit->assembly, &point);
|
||||
_mesa_memcpy (unit->machine->mem, mach.mem, SLANG_MACHINE_MEMORY_SIZE * sizeof (slang_machine_slot));
|
||||
|
@ -1220,8 +1216,6 @@ void exec_fragment_shader (struct gl2_fragment_shader_intf **fs)
|
|||
slang_function *f;
|
||||
slang_assembly_file_restore_point point;
|
||||
slang_machine mach;
|
||||
slang_assembly_local_info info;
|
||||
slang_assembly_name_space space;
|
||||
slang_assemble_ctx A;
|
||||
|
||||
f = &unit->functions.functions[i];
|
||||
|
@ -1229,20 +1223,18 @@ void exec_fragment_shader (struct gl2_fragment_shader_intf **fs)
|
|||
mach = *unit->machine;
|
||||
mach.ip = unit->assembly->count;
|
||||
mach.kill = 0;
|
||||
info.ret_size = 0;
|
||||
info.addr_tmp = 0;
|
||||
info.swizzle_tmp = 4;
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
|
||||
space.funcs = &unit->functions;
|
||||
space.structs = &unit->structs;
|
||||
space.vars = &unit->globals;
|
||||
|
||||
A.file = unit->assembly;
|
||||
A.mach = unit->machine;
|
||||
A.atoms = unit->atom_pool;
|
||||
A.space = space;
|
||||
A.space.funcs = &unit->functions;
|
||||
A.space.structs = &unit->structs;
|
||||
A.space.vars = &unit->globals;
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
|
||||
slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
|
||||
_slang_assemble_function_call (&A, f, NULL, 0, GL_FALSE);
|
||||
slang_assembly_file_push (unit->assembly, slang_asm_exit);
|
||||
|
||||
_slang_execute2 (unit->assembly, &mach);
|
||||
slang_assembly_file_restore_point_load (unit->assembly, &point);
|
||||
_mesa_memcpy (unit->machine->mem, mach.mem, SLANG_MACHINE_MEMORY_SIZE * sizeof (slang_machine_slot));
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// TODO:
|
||||
// - implement texture1D, texture2D, texture3D, textureCube,
|
||||
// - implement shadow1D, shadow2D,
|
||||
// - implement noise1, noise2, noise3, noise4,
|
||||
//
|
||||
|
||||
//
|
||||
|
@ -1514,84 +1513,126 @@ vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
|
|||
//
|
||||
// 8.9 Noise Functions
|
||||
//
|
||||
// AUTHOR: Stefan Gustavson (stegu@itn.liu.se), Nov 26, 2005
|
||||
//
|
||||
|
||||
float noise1 (float x) {
|
||||
// XXX:
|
||||
return 0.0;
|
||||
float a;
|
||||
__asm float_noise1 a, x;
|
||||
return a;
|
||||
}
|
||||
|
||||
float noise1 (vec2 x) {
|
||||
// XXX:
|
||||
return 0.0;
|
||||
float a;
|
||||
__asm float_noise2 a, x;
|
||||
return a;
|
||||
}
|
||||
|
||||
float noise1 (vec3 x) {
|
||||
// XXX:
|
||||
return 0.0;
|
||||
float a;
|
||||
__asm float_noise3 a, x;
|
||||
return a;
|
||||
}
|
||||
|
||||
float noise1 (vec4 x) {
|
||||
// XXX:
|
||||
return 0.0;
|
||||
float a;
|
||||
__asm float_noise4 a, x;
|
||||
return a;
|
||||
}
|
||||
|
||||
vec2 noise2 (float x) {
|
||||
// XXX:
|
||||
return vec2 (0.0);
|
||||
vec2 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + 19.34);
|
||||
return u;
|
||||
}
|
||||
|
||||
vec2 noise2 (vec2 x) {
|
||||
// XXX:
|
||||
return vec2 (0.0);
|
||||
vec2 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec2 (19.34, 7.66));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec2 noise2 (vec3 x) {
|
||||
// XXX:
|
||||
return vec2 (0.0);
|
||||
vec2 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec2 noise2 (vec4 x) {
|
||||
// XXX:
|
||||
return vec2 (0.0);
|
||||
vec2 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec3 noise3 (float x) {
|
||||
// XXX:
|
||||
return vec3 (0.0);
|
||||
vec3 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + 19.34);
|
||||
u.z = noise1 (x + 5.47);
|
||||
return u;
|
||||
}
|
||||
|
||||
vec3 noise3 (vec2 x) {
|
||||
// XXX:
|
||||
return vec3 (0.0);
|
||||
vec3 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec2 (19.34, 7.66));
|
||||
u.z = noise1 (x + vec2 (5.47, 17.85));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec3 noise3 (vec3 x) {
|
||||
// XXX:
|
||||
return vec3 (0.0);
|
||||
vec3 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));
|
||||
u.z = noise1 (x + vec3 (5.47, 17.85, 11.04));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec3 noise3 (vec4 x) {
|
||||
// XXX:
|
||||
return vec3 (0.0);
|
||||
vec3 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));
|
||||
u.z = noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec4 noise4 (float x) {
|
||||
// XXX:
|
||||
return vec4 (0.0);
|
||||
vec4 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + 19.34);
|
||||
u.z = noise1 (x + 5.47);
|
||||
u.w = noise1 (x + 23.54);
|
||||
return u;
|
||||
}
|
||||
|
||||
vec4 noise4 (vec2 x) {
|
||||
// XXX:
|
||||
return vec4 (0.0);
|
||||
vec4 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec2 (19.34, 7.66));
|
||||
u.z = noise1 (x + vec2 (5.47, 17.85));
|
||||
u.w = noise1 (x + vec2 (23.54, 29.11));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec4 noise4 (vec3 x) {
|
||||
// XXX:
|
||||
return vec4 (0.0);
|
||||
vec4 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));
|
||||
u.z = noise1 (x + vec3 (5.47, 17.85, 11.04));
|
||||
u.w = noise1 (x + vec3 (23.54, 29.11, 31.91));
|
||||
return u;
|
||||
}
|
||||
|
||||
vec4 noise4 (vec4 x) {
|
||||
// XXX:
|
||||
return vec4 (0.0);
|
||||
vec4 u;
|
||||
u.x = noise1 (x);
|
||||
u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));
|
||||
u.z = noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19));
|
||||
u.w = noise1 (x + vec4 (23.54, 29.11, 31.91, 37.48));
|
||||
return u;
|
||||
}
|
||||
|
||||
|
|
|
@ -661,19 +661,63 @@
|
|||
111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,20,0,9,18,117,0,59,116,0,18,99,111,111,
|
||||
114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0,49,20,0,9,18,117,0,59,112,0,18,99,111,111,114,
|
||||
100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,20,0,8,58,115,104,97,100,111,119,50,68,0,18,115,
|
||||
97,109,112,108,101,114,0,0,18,117,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,8,
|
||||
17,48,0,48,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,
|
||||
9,0,110,111,105,115,101,49,0,1,0,0,11,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,9,0,110,111,105,115,101,
|
||||
49,0,1,0,0,12,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,9,120,0,0,0,
|
||||
1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,10,120,0,0,0,
|
||||
1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,
|
||||
1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,12,120,0,0,0,
|
||||
1,8,58,118,101,99,50,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,9,120,0,0,0,
|
||||
1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,
|
||||
1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,11,120,0,0,0,
|
||||
1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,12,120,0,0,0,
|
||||
1,8,58,118,101,99,51,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,
|
||||
1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,10,120,0,0,0,
|
||||
1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,11,120,0,0,0,
|
||||
1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,12,120,0,0,0,
|
||||
1,8,58,118,101,99,52,0,17,48,0,48,0,0,0,0,0,0,0
|
||||
97,109,112,108,101,114,0,0,18,117,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,3,
|
||||
2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,49,0,18,97,0,0,18,120,0,0,0,8,18,97,0,
|
||||
0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,
|
||||
95,110,111,105,115,101,50,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,
|
||||
1,0,0,11,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,51,0,18,97,0,0,
|
||||
18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,12,120,0,0,0,1,3,2,0,9,1,97,0,0,
|
||||
0,4,102,108,111,97,116,95,110,111,105,115,101,52,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,10,0,
|
||||
110,111,105,115,101,50,0,1,0,0,9,120,0,0,0,1,3,2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,
|
||||
105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,
|
||||
57,0,51,52,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,10,120,0,0,0,1,3,
|
||||
2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,
|
||||
121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,
|
||||
0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,1,3,2,0,10,
|
||||
1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,
|
||||
58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,
|
||||
17,51,0,50,51,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,12,120,0,
|
||||
0,0,1,3,2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,
|
||||
117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,
|
||||
55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,
|
||||
111,105,115,101,51,0,1,0,0,9,120,0,0,0,1,3,2,0,11,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,
|
||||
115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,
|
||||
51,52,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,
|
||||
46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,1,3,2,0,11,1,117,0,
|
||||
0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,
|
||||
111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,
|
||||
0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,53,0,52,55,0,
|
||||
0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,11,
|
||||
120,0,0,0,1,3,2,0,11,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,
|
||||
9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,
|
||||
17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,
|
||||
49,0,18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,
|
||||
0,46,0,0,20,0,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,12,120,0,0,0,1,3,2,0,11,1,117,
|
||||
0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,
|
||||
111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,
|
||||
0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,
|
||||
120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,
|
||||
51,0,49,57,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,
|
||||
1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,
|
||||
0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,20,0,9,18,117,0,59,122,
|
||||
0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0,0,20,0,9,18,117,0,59,119,0,58,110,
|
||||
111,105,115,101,49,0,18,120,0,17,50,51,0,53,52,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,111,105,
|
||||
115,101,52,0,1,0,0,10,120,0,0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,
|
||||
49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,
|
||||
17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,
|
||||
101,49,0,18,120,0,58,118,101,99,50,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,20,0,9,18,
|
||||
117,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,50,51,0,53,52,0,0,0,17,
|
||||
50,57,0,49,49,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,11,120,0,
|
||||
0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,
|
||||
117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,
|
||||
55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,
|
||||
18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,
|
||||
0,0,20,0,9,18,117,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,50,51,0,53,
|
||||
52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,1,0,12,0,110,
|
||||
111,105,115,101,52,0,1,0,0,12,120,0,0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,
|
||||
115,101,49,0,18,120,0,0,0,20,0,9,18,117,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,
|
||||
99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,
|
||||
0,20,0,9,18,117,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,
|
||||
0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,20,0,9,18,117,0,
|
||||
59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,50,51,0,53,52,0,0,0,17,50,57,0,
|
||||
49,49,0,0,0,17,51,49,0,57,49,0,0,0,17,51,55,0,52,56,0,0,0,0,46,0,0,20,0,8,18,117,0,0,0,0
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -54,6 +54,10 @@ typedef enum slang_assembly_type_
|
|||
slang_asm_float_log2,
|
||||
slang_asm_float_floor,
|
||||
slang_asm_float_ceil,
|
||||
slang_asm_float_noise1,
|
||||
slang_asm_float_noise2,
|
||||
slang_asm_float_noise3,
|
||||
slang_asm_float_noise4,
|
||||
slang_asm_int_copy,
|
||||
slang_asm_int_move,
|
||||
slang_asm_int_push,
|
||||
|
@ -97,64 +101,59 @@ typedef struct slang_assembly_
|
|||
typedef struct slang_assembly_file_
|
||||
{
|
||||
slang_assembly *code;
|
||||
unsigned int count;
|
||||
unsigned int capacity;
|
||||
GLuint count;
|
||||
GLuint capacity;
|
||||
} slang_assembly_file;
|
||||
|
||||
int slang_assembly_file_construct (slang_assembly_file *);
|
||||
void slang_assembly_file_destruct (slang_assembly_file *);
|
||||
int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
|
||||
int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
|
||||
int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
|
||||
int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
|
||||
GLboolean slang_assembly_file_construct (slang_assembly_file *);
|
||||
GLvoid slang_assembly_file_destruct (slang_assembly_file *);
|
||||
GLboolean slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
|
||||
GLboolean slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
|
||||
GLboolean slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
|
||||
GLboolean slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
|
||||
|
||||
typedef struct slang_assembly_file_restore_point_
|
||||
{
|
||||
unsigned int count;
|
||||
GLuint count;
|
||||
} slang_assembly_file_restore_point;
|
||||
|
||||
int slang_assembly_file_restore_point_save (slang_assembly_file *,
|
||||
GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *,
|
||||
slang_assembly_file_restore_point *);
|
||||
int slang_assembly_file_restore_point_load (slang_assembly_file *,
|
||||
GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *,
|
||||
slang_assembly_file_restore_point *);
|
||||
|
||||
typedef struct slang_assembly_flow_control_
|
||||
{
|
||||
unsigned int loop_start; /* for "continue" statement */
|
||||
unsigned int loop_end; /* for "break" statement */
|
||||
unsigned int function_end; /* for "return" statement */
|
||||
GLuint loop_start; /* for "continue" statement */
|
||||
GLuint loop_end; /* for "break" statement */
|
||||
GLuint function_end; /* for "return" statement */
|
||||
} slang_assembly_flow_control;
|
||||
|
||||
typedef struct slang_assembly_local_info_
|
||||
{
|
||||
unsigned int ret_size;
|
||||
unsigned int addr_tmp;
|
||||
unsigned int swizzle_tmp;
|
||||
GLuint ret_size;
|
||||
GLuint addr_tmp;
|
||||
GLuint swizzle_tmp;
|
||||
} slang_assembly_local_info;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
slang_ref_force,
|
||||
slang_ref_forbid,
|
||||
slang_ref_freelance
|
||||
slang_ref_forbid/*,
|
||||
slang_ref_freelance*/
|
||||
} slang_ref_type;
|
||||
|
||||
/*
|
||||
holds a complete information about vector swizzle - the <swizzle> array contains
|
||||
vector component sources indices, where 0 is "x", 1 is "y", ...
|
||||
example: "xwz" --> { 3, { 0, 3, 2, n/u } }
|
||||
* Holds a complete information about vector swizzle - the <swizzle> array contains
|
||||
* vector component source indices, where 0 is "x", 1 is "y", 2 is "z" and 3 is "w".
|
||||
* Example: "xwz" --> { 3, { 0, 3, 2, not used } }.
|
||||
*/
|
||||
typedef struct slang_swizzle_
|
||||
{
|
||||
unsigned int num_components;
|
||||
unsigned int swizzle[4];
|
||||
GLuint num_components;
|
||||
GLuint swizzle[4];
|
||||
} slang_swizzle;
|
||||
|
||||
typedef struct slang_assembly_stack_info_
|
||||
{
|
||||
slang_swizzle swizzle;
|
||||
} slang_assembly_stack_info;
|
||||
|
||||
typedef struct slang_assembly_name_space_
|
||||
{
|
||||
struct slang_function_scope_ *funcs;
|
||||
|
@ -171,32 +170,26 @@ typedef struct slang_assemble_ctx_
|
|||
slang_assembly_flow_control flow;
|
||||
slang_assembly_local_info local;
|
||||
slang_ref_type ref;
|
||||
slang_assembly_stack_info swz;
|
||||
slang_swizzle swz;
|
||||
} slang_assemble_ctx;
|
||||
|
||||
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,
|
||||
slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,
|
||||
slang_operation *params, GLuint num_params, slang_assembly_name_space *space,
|
||||
slang_atom_pool *);
|
||||
|
||||
int _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);
|
||||
GLboolean _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);
|
||||
|
||||
int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,
|
||||
slang_assembly_name_space *, struct slang_machine_ *, slang_atom_pool *);
|
||||
int _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);
|
||||
GLboolean _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_dereference (slang_assembly_file *, slang_operation *, slang_assembly_name_space *,
|
||||
slang_assembly_local_info *, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_dereference (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_function_call (slang_assemble_ctx *, slang_function *,
|
||||
slang_operation *, GLuint, GLboolean);
|
||||
GLboolean _slang_assemble_function_call (slang_assemble_ctx *, slang_function *, slang_operation *,
|
||||
GLuint, GLboolean);
|
||||
|
||||
int _slang_assemble_function_call_name (slang_assemble_ctx *, const char *,
|
||||
slang_operation *, GLuint, GLboolean);
|
||||
GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *, const char *, slang_operation *,
|
||||
GLuint, GLboolean);
|
||||
|
||||
int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,
|
||||
slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,
|
||||
slang_assembly_stack_info *, struct slang_machine_ *, slang_atom_pool *);
|
||||
int _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);
|
||||
GLboolean _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -36,57 +36,56 @@
|
|||
#include "slang_execute.h"
|
||||
|
||||
/*
|
||||
_slang_assemble_assignment()
|
||||
|
||||
copies values on the stack (<component 0> to <component N-1>) to a memory
|
||||
location pointed by <addr of variable>;
|
||||
|
||||
in:
|
||||
+------------------+
|
||||
| addr of variable |
|
||||
+------------------+
|
||||
| component N-1 |
|
||||
| ... |
|
||||
| component 0 |
|
||||
+------------------+
|
||||
|
||||
out:
|
||||
+------------------+
|
||||
| addr of variable |
|
||||
+------------------+
|
||||
* _slang_assemble_assignment()
|
||||
*
|
||||
* Copies values on the stack (<component 0> to <component N-1>) to a memory
|
||||
* location pointed by <addr of variable>.
|
||||
*
|
||||
* in:
|
||||
* +------------------+
|
||||
* | addr of variable |
|
||||
* +------------------+
|
||||
* | component N-1 |
|
||||
* | ... |
|
||||
* | component 0 |
|
||||
* +------------------+
|
||||
*
|
||||
* out:
|
||||
* +------------------+
|
||||
* | addr of variable |
|
||||
* +------------------+
|
||||
*/
|
||||
|
||||
static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,
|
||||
unsigned int *index, unsigned int size, slang_assembly_local_info *info,
|
||||
slang_assembly_stack_info *stk)
|
||||
static GLboolean assign_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,
|
||||
GLuint *index, GLuint size)
|
||||
{
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
for (i = 0; i < agg->count; i++)
|
||||
{
|
||||
const slang_storage_array *arr = &agg->arrays[i];
|
||||
unsigned int j;
|
||||
GLuint j;
|
||||
|
||||
for (j = 0; j < arr->length; j++)
|
||||
{
|
||||
if (arr->type == slang_stor_aggregate)
|
||||
{
|
||||
if (!assign_aggregate (file, arr->aggregate, index, size, info, stk))
|
||||
return 0;
|
||||
if (!assign_aggregate (A, arr->aggregate, index, size))
|
||||
return GL_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int dst_addr_loc, dst_offset;
|
||||
GLuint dst_addr_loc, dst_offset;
|
||||
slang_assembly_type ty;
|
||||
|
||||
/* calculate the distance from top of the stack to the destination address */
|
||||
dst_addr_loc = size - *index;
|
||||
|
||||
/* calculate the offset within destination variable to write */
|
||||
if (stk->swizzle.num_components != 0)
|
||||
if (A->swz.num_components != 0)
|
||||
{
|
||||
/* swizzle the index to get the actual offset */
|
||||
dst_offset = stk->swizzle.swizzle[*index / 4] * 4;
|
||||
dst_offset = A->swz.swizzle[*index / 4] * 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -106,101 +105,93 @@ static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggr
|
|||
ty = slang_asm_float_copy;
|
||||
break;
|
||||
default:
|
||||
_mesa_problem(NULL, "Unexpected arr->type in assign_aggregate");
|
||||
ty = slang_asm_none;
|
||||
break;
|
||||
}
|
||||
if (!slang_assembly_file_push_label2 (file, ty, dst_addr_loc, dst_offset))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label2 (A->file, ty, dst_addr_loc, dst_offset))
|
||||
return GL_FALSE;
|
||||
|
||||
*index += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
int _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)
|
||||
GLboolean _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
slang_assembly_typeinfo ti;
|
||||
int result;
|
||||
GLboolean result = GL_FALSE;
|
||||
slang_storage_aggregate agg;
|
||||
unsigned int index, size;
|
||||
GLuint index, size;
|
||||
|
||||
if (!slang_assembly_typeinfo_construct (&ti))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&ti);
|
||||
return 0;
|
||||
}
|
||||
goto end1;
|
||||
|
||||
if (!slang_storage_aggregate_construct (&agg))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&ti);
|
||||
return 0;
|
||||
}
|
||||
goto end1;
|
||||
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
|
||||
A->space.vars, A->mach, A->file, A->atoms))
|
||||
{
|
||||
slang_storage_aggregate_destruct (&agg);
|
||||
slang_assembly_typeinfo_destruct (&ti);
|
||||
return 0;
|
||||
}
|
||||
goto end;
|
||||
|
||||
index = 0;
|
||||
size = _slang_sizeof_aggregate (&agg);
|
||||
result = assign_aggregate (A->file, &agg, &index, size, &A->local, &A->swz);
|
||||
result = assign_aggregate (A, &agg, &index, size);
|
||||
|
||||
end1:
|
||||
slang_storage_aggregate_destruct (&agg);
|
||||
end:
|
||||
slang_assembly_typeinfo_destruct (&ti);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
_slang_assemble_assign()
|
||||
|
||||
performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
|
||||
children
|
||||
* _slang_assemble_assign()
|
||||
*
|
||||
* Performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
|
||||
* children.
|
||||
*/
|
||||
|
||||
int _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,
|
||||
GLboolean _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,
|
||||
slang_ref_type ref)
|
||||
{
|
||||
slang_assembly_stack_info stk;
|
||||
slang_swizzle swz;
|
||||
|
||||
if (ref == slang_ref_forbid)
|
||||
{
|
||||
if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (slang_string_compare ("=", oper) == 0)
|
||||
{
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_force))
|
||||
return 0;
|
||||
stk = A->swz;
|
||||
return GL_FALSE;
|
||||
swz = A->swz;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
|
||||
return 0;
|
||||
A->swz = stk;
|
||||
return GL_FALSE;
|
||||
A->swz = swz;
|
||||
if (!_slang_assemble_assignment (A, op->children))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_slang_assemble_function_call_name (A, oper, op->children, op->num_children, GL_TRUE))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (ref == slang_ref_forbid)
|
||||
{
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_addr_copy))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))
|
||||
return 0;
|
||||
if (!_slang_dereference (A->file, op->children, &A->space, &A->local, A->mach, A->atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!_slang_dereference (A, op->children))
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int _slang_assemble_assignment (slang_assemble_ctx *, slang_operation *);
|
||||
GLboolean _slang_assemble_assignment (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_assign (slang_assemble_ctx *, slang_operation *, const char *, slang_ref_type);
|
||||
GLboolean _slang_assemble_assign (slang_assemble_ctx *, slang_operation *, const char *,
|
||||
slang_ref_type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -34,453 +34,417 @@
|
|||
#include "slang_assemble.h"
|
||||
#include "slang_execute.h"
|
||||
|
||||
/* _slang_assemble_logicaland() */
|
||||
|
||||
int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
and:
|
||||
<left-expression>
|
||||
jumpz zero
|
||||
<right-expression>
|
||||
jump end
|
||||
zero:
|
||||
push 0
|
||||
end:
|
||||
* _slang_assemble_logicaland()
|
||||
*
|
||||
* and:
|
||||
* <left-expression>
|
||||
* jumpz zero
|
||||
* <right-expression>
|
||||
* jump end
|
||||
* zero:
|
||||
* push 0
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int zero_jump, end_jump;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_logicaland (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint zero_jump, end_jump;
|
||||
|
||||
/* evaluate left expression */
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to pushing 0 if not true */
|
||||
zero_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
zero_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* evaluate right expression */
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the end of the expression */
|
||||
end_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
end_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* push 0 on stack */
|
||||
file->code[zero_jump].param[0] = file->count;
|
||||
if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 0))
|
||||
return 0;
|
||||
A->file->code[zero_jump].param[0] = A->file->count;
|
||||
if (!slang_assembly_file_push_literal (A->file, slang_asm_bool_push, (GLfloat) 0))
|
||||
return GL_FALSE;
|
||||
|
||||
/* the end of the expression */
|
||||
file->code[end_jump].param[0] = file->count;
|
||||
A->file->code[end_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_assemble_logicalor() */
|
||||
|
||||
int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
or:
|
||||
<left-expression>
|
||||
jumpz right
|
||||
push 1
|
||||
jump end
|
||||
right:
|
||||
<right-expression>
|
||||
end:
|
||||
* _slang_assemble_logicalor()
|
||||
*
|
||||
* or:
|
||||
* <left-expression>
|
||||
* jumpz right
|
||||
* push 1
|
||||
* jump end
|
||||
* right:
|
||||
* <right-expression>
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int right_jump, end_jump;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_logicalor (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint right_jump, end_jump;
|
||||
|
||||
/* evaluate left expression */
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to evaluation of right expression if not true */
|
||||
right_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
right_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* push 1 on stack */
|
||||
if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 1))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_literal (A->file, slang_asm_bool_push, (GLfloat) 1))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the end of the expression */
|
||||
end_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
end_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* evaluate right expression */
|
||||
file->code[right_jump].param[0] = file->count;
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
A->file->code[right_jump].param[0] = A->file->count;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* the end of the expression */
|
||||
file->code[end_jump].param[0] = file->count;
|
||||
A->file->code[end_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_assemble_select() */
|
||||
|
||||
int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
select:
|
||||
<condition-expression>
|
||||
jumpz false
|
||||
<true-expression>
|
||||
jump end
|
||||
false:
|
||||
<false-expression>
|
||||
end:
|
||||
* _slang_assemble_select()
|
||||
*
|
||||
* select:
|
||||
* <condition-expression>
|
||||
* jumpz false
|
||||
* <true-expression>
|
||||
* jump end
|
||||
* false:
|
||||
* <false-expression>
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int cond_jump, end_jump;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_select (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint cond_jump, end_jump;
|
||||
|
||||
/* execute condition expression */
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to false expression if not true */
|
||||
cond_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
cond_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* execute true expression */
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the end of the expression */
|
||||
end_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
end_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve false point */
|
||||
file->code[cond_jump].param[0] = file->count;
|
||||
A->file->code[cond_jump].param[0] = A->file->count;
|
||||
|
||||
/* execute false expression */
|
||||
if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the end of the expression */
|
||||
file->code[end_jump].param[0] = file->count;
|
||||
A->file->code[end_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_assemble_for() */
|
||||
|
||||
int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
for:
|
||||
<init-statement>
|
||||
jump start
|
||||
break:
|
||||
jump end
|
||||
continue:
|
||||
<loop-increment>
|
||||
start:
|
||||
<condition-statement>
|
||||
jumpz end
|
||||
<loop-body>
|
||||
jump continue
|
||||
end:
|
||||
* _slang_assemble_for()
|
||||
*
|
||||
* for:
|
||||
* <init-statement>
|
||||
* jump start
|
||||
* break:
|
||||
* jump end
|
||||
* continue:
|
||||
* <loop-increment>
|
||||
* start:
|
||||
* <condition-statement>
|
||||
* jumpz end
|
||||
* <loop-body>
|
||||
* jump continue
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int start_jump, end_jump, cond_jump;
|
||||
unsigned int break_label, cont_label;
|
||||
slang_assembly_flow_control loop_flow = *flow;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_for (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint start_jump, end_jump, cond_jump;
|
||||
GLuint break_label, cont_label;
|
||||
slang_assembly_flow_control save_flow = A->flow;
|
||||
|
||||
/* execute initialization statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))
|
||||
return 0;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[0]))
|
||||
return GL_FALSE;
|
||||
|
||||
/* skip the "go to the end of the loop" and loop-increment statements */
|
||||
start_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
start_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* go to the end of the loop - break statements are directed here */
|
||||
break_label = file->count;
|
||||
end_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
break_label = A->file->count;
|
||||
end_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the beginning of the loop - continue statements are directed here */
|
||||
cont_label = file->count;
|
||||
cont_label = A->file->count;
|
||||
|
||||
/* execute loop-increment statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))
|
||||
return 0;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[2]))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the condition point */
|
||||
file->code[start_jump].param[0] = file->count;
|
||||
A->file->code[start_jump].param[0] = A->file->count;
|
||||
|
||||
/* execute condition statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: inspect stk */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the end of the loop if not true */
|
||||
cond_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
cond_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* execute loop body */
|
||||
loop_flow.loop_start = cont_label;
|
||||
loop_flow.loop_end = break_label;
|
||||
if (!_slang_assemble_operation (file, &op->children[3], 0, &loop_flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[3], 0, space, mach, atoms))
|
||||
return 0;
|
||||
A->flow.loop_start = cont_label;
|
||||
A->flow.loop_end = break_label;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[3], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[3]))
|
||||
return GL_FALSE;
|
||||
A->flow = save_flow;
|
||||
|
||||
/* go to the beginning of the loop */
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_jump, cont_label))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_jump, cont_label))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the end of the loop */
|
||||
file->code[end_jump].param[0] = file->count;
|
||||
file->code[cond_jump].param[0] = file->count;
|
||||
A->file->code[end_jump].param[0] = A->file->count;
|
||||
A->file->code[cond_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_assemble_do() */
|
||||
|
||||
int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
do:
|
||||
jump start
|
||||
break:
|
||||
jump end
|
||||
continue:
|
||||
jump condition
|
||||
start:
|
||||
<loop-body>
|
||||
condition:
|
||||
<condition-statement>
|
||||
jumpz end
|
||||
jump start
|
||||
end:
|
||||
* _slang_assemble_do()
|
||||
*
|
||||
* do:
|
||||
* jump start
|
||||
* break:
|
||||
* jump end
|
||||
* continue:
|
||||
* jump condition
|
||||
* start:
|
||||
* <loop-body>
|
||||
* condition:
|
||||
* <condition-statement>
|
||||
* jumpz end
|
||||
* jump start
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int skip_jump, end_jump, cont_jump, cond_jump;
|
||||
unsigned int break_label, cont_label;
|
||||
slang_assembly_flow_control loop_flow = *flow;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_do (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint skip_jump, end_jump, cont_jump, cond_jump;
|
||||
GLuint break_label, cont_label;
|
||||
slang_assembly_flow_control save_flow = A->flow;
|
||||
|
||||
/* skip the "go to the end of the loop" and "go to condition" statements */
|
||||
skip_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
skip_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* go to the end of the loop - break statements are directed here */
|
||||
break_label = file->count;
|
||||
end_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
break_label = A->file->count;
|
||||
end_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* go to condition - continue statements are directed here */
|
||||
cont_label = file->count;
|
||||
cont_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
cont_label = A->file->count;
|
||||
cont_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the beginning of the loop */
|
||||
file->code[skip_jump].param[0] = file->count;
|
||||
A->file->code[skip_jump].param[0] = A->file->count;
|
||||
|
||||
/* execute loop body */
|
||||
loop_flow.loop_start = cont_label;
|
||||
loop_flow.loop_end = break_label;
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, &loop_flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))
|
||||
return 0;
|
||||
A->flow.loop_start = cont_label;
|
||||
A->flow.loop_end = break_label;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[0]))
|
||||
return GL_FALSE;
|
||||
A->flow = save_flow;
|
||||
|
||||
/* resolve condition point */
|
||||
file->code[cont_jump].param[0] = file->count;
|
||||
A->file->code[cont_jump].param[0] = A->file->count;
|
||||
|
||||
/* execute condition statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the end of the loop if not true */
|
||||
cond_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
cond_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the beginning of the loop */
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_jump, file->code[skip_jump].param[0]))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_jump, A->file->code[skip_jump].param[0]))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the end of the loop */
|
||||
file->code[end_jump].param[0] = file->count;
|
||||
file->code[cond_jump].param[0] = file->count;
|
||||
A->file->code[end_jump].param[0] = A->file->count;
|
||||
A->file->code[cond_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_assemble_while() */
|
||||
|
||||
int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
while:
|
||||
jump continue
|
||||
break:
|
||||
jump end
|
||||
continue:
|
||||
<condition-statement>
|
||||
jumpz end
|
||||
<loop-body>
|
||||
jump continue
|
||||
end:
|
||||
* _slang_assemble_while()
|
||||
*
|
||||
* while:
|
||||
* jump continue
|
||||
* break:
|
||||
* jump end
|
||||
* continue:
|
||||
* <condition-statement>
|
||||
* jumpz end
|
||||
* <loop-body>
|
||||
* jump continue
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int skip_jump, end_jump, cond_jump;
|
||||
unsigned int break_label;
|
||||
slang_assembly_flow_control loop_flow = *flow;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_while (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint skip_jump, end_jump, cond_jump;
|
||||
GLuint break_label;
|
||||
slang_assembly_flow_control save_flow = A->flow;
|
||||
|
||||
/* skip the "go to the end of the loop" statement */
|
||||
skip_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
skip_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* go to the end of the loop - break statements are directed here */
|
||||
break_label = file->count;
|
||||
end_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
break_label = A->file->count;
|
||||
end_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the beginning of the loop - continue statements are directed here */
|
||||
file->code[skip_jump].param[0] = file->count;
|
||||
A->file->code[skip_jump].param[0] = A->file->count;
|
||||
|
||||
/* execute condition statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to the end of the loop if not true */
|
||||
cond_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
cond_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* execute loop body */
|
||||
loop_flow.loop_start = file->code[skip_jump].param[0];
|
||||
loop_flow.loop_end = break_label;
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, &loop_flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))
|
||||
return 0;
|
||||
A->flow.loop_start = A->file->code[skip_jump].param[0];
|
||||
A->flow.loop_end = break_label;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[1]))
|
||||
return GL_FALSE;
|
||||
A->flow = save_flow;
|
||||
|
||||
/* jump to the beginning of the loop */
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_jump, file->code[skip_jump].param[0]))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_jump, A->file->code[skip_jump].param[0]))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve the end of the loop */
|
||||
file->code[end_jump].param[0] = file->count;
|
||||
file->code[cond_jump].param[0] = file->count;
|
||||
A->file->code[end_jump].param[0] = A->file->count;
|
||||
A->file->code[cond_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_assemble_if() */
|
||||
|
||||
int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
|
||||
{
|
||||
/*
|
||||
if:
|
||||
<condition-statement>
|
||||
jumpz else
|
||||
<true-statement>
|
||||
jump end
|
||||
else:
|
||||
<false-statement>
|
||||
end:
|
||||
* _slang_assemble_if()
|
||||
*
|
||||
* if:
|
||||
* <condition-statement>
|
||||
* jumpz else
|
||||
* <true-statement>
|
||||
* jump end
|
||||
* else:
|
||||
* <false-statement>
|
||||
* end:
|
||||
*/
|
||||
|
||||
unsigned int cond_jump, else_jump;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean _slang_assemble_if (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
GLuint cond_jump, else_jump;
|
||||
|
||||
/* execute condition statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
|
||||
/* jump to false-statement if not true */
|
||||
cond_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
|
||||
return 0;
|
||||
cond_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
|
||||
return GL_FALSE;
|
||||
|
||||
/* execute true-statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))
|
||||
return 0;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[1]))
|
||||
return GL_FALSE;
|
||||
|
||||
/* skip if-false statement */
|
||||
else_jump = file->count;
|
||||
if (!slang_assembly_file_push (file, slang_asm_jump))
|
||||
return 0;
|
||||
else_jump = A->file->count;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_jump))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve start of false-statement */
|
||||
file->code[cond_jump].param[0] = file->count;
|
||||
A->file->code[cond_jump].param[0] = A->file->count;
|
||||
|
||||
/* execute false-statement */
|
||||
if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
|
||||
return 0;
|
||||
/* TODO: pass-in stk to cleanup */
|
||||
if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))
|
||||
return 0;
|
||||
if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid/*slang_ref_freelance*/))
|
||||
return GL_FALSE;
|
||||
if (!_slang_cleanup_stack_ (A, &op->children[2]))
|
||||
return GL_FALSE;
|
||||
|
||||
/* resolve end of if-false statement */
|
||||
file->code[else_jump].param[0] = file->count;
|
||||
A->file->code[else_jump].param[0] = A->file->count;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,33 +31,19 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_logicaland (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_logicalor (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_select (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_for (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_do (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_while (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
|
||||
GLboolean _slang_assemble_if (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -36,15 +36,15 @@
|
|||
|
||||
/* _slang_is_swizzle() */
|
||||
|
||||
int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
|
||||
GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz)
|
||||
{
|
||||
unsigned int i;
|
||||
int xyzw = 0, rgba = 0, stpq = 0;
|
||||
GLuint i;
|
||||
GLboolean xyzw = GL_FALSE, rgba = GL_FALSE, stpq = GL_FALSE;
|
||||
|
||||
/* the swizzle can be at most 4-component long */
|
||||
swz->num_components = slang_string_length (field);
|
||||
if (swz->num_components > 4)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
for (i = 0; i < swz->num_components; i++)
|
||||
{
|
||||
|
@ -55,22 +55,22 @@ int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
|
|||
case 'y':
|
||||
case 'z':
|
||||
case 'w':
|
||||
xyzw = 1;
|
||||
xyzw = GL_TRUE;
|
||||
break;
|
||||
case 'r':
|
||||
case 'g':
|
||||
case 'b':
|
||||
case 'a':
|
||||
rgba = 1;
|
||||
rgba = GL_TRUE;
|
||||
break;
|
||||
case 's':
|
||||
case 't':
|
||||
case 'p':
|
||||
case 'q':
|
||||
stpq = 1;
|
||||
stpq = GL_TRUE;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
/* collect swizzle component */
|
||||
|
@ -100,42 +100,43 @@ int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
|
|||
|
||||
/* check if the component is valid for given vector's row count */
|
||||
if (rows <= swz->swizzle[i])
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
/* only one swizzle group can be used */
|
||||
if ((xyzw && rgba) || (xyzw && stpq) || (rgba && stpq))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_is_swizzle_mask() */
|
||||
|
||||
int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows)
|
||||
GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows)
|
||||
{
|
||||
unsigned int i, c = 0;
|
||||
GLuint i, c = 0;
|
||||
|
||||
/* the swizzle may not be longer than the vector dim */
|
||||
if (swz->num_components > rows)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* the swizzle components cannot be duplicated */
|
||||
for (i = 0; i < swz->num_components; i++)
|
||||
{
|
||||
if ((c & (1 << swz->swizzle[i])) != 0)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
c |= 1 << swz->swizzle[i];
|
||||
}
|
||||
return 1;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_multiply_swizzles() */
|
||||
|
||||
void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
|
||||
GLvoid _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
|
||||
const slang_swizzle *right)
|
||||
{
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
dst->num_components = right->num_components;
|
||||
for (i = 0; i < right->num_components; i++)
|
||||
|
@ -143,37 +144,38 @@ void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
|
|||
}
|
||||
|
||||
/* _slang_assemble_constructor() */
|
||||
#if 0
|
||||
static int constructor_aggregate (slang_assembly_file *file, const slang_storage_aggregate *flat,
|
||||
unsigned int *index, slang_operation *op, unsigned int size, slang_assembly_flow_control *flow,
|
||||
slang_assembly_name_space *space, slang_assembly_local_info *info)
|
||||
|
||||
static GLboolean constructor_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *flat,
|
||||
GLuint *index, slang_operation *op, GLuint size)
|
||||
{
|
||||
slang_assembly_typeinfo ti;
|
||||
int result;
|
||||
GLboolean result = GL_FALSE;
|
||||
slang_storage_aggregate agg, flat_agg;
|
||||
slang_assembly_stack_info stk;
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
slang_assembly_typeinfo_construct (&ti);
|
||||
if (!(result = _slang_typeof_operation (op, space, &ti)))
|
||||
if (!slang_assembly_typeinfo_construct (&ti))
|
||||
return GL_FALSE;
|
||||
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
|
||||
goto end1;
|
||||
|
||||
slang_storage_aggregate_construct (&agg);
|
||||
if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
|
||||
space->vars)))
|
||||
if (!slang_storage_aggregate_construct (&agg))
|
||||
goto end1;
|
||||
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
|
||||
A->space.vars, A->mach, A->file, A->atoms))
|
||||
goto end2;
|
||||
|
||||
slang_storage_aggregate_construct (&flat_agg);
|
||||
if (!(result = _slang_flatten_aggregate (&flat_agg, &agg)))
|
||||
if (!slang_storage_aggregate_construct (&flat_agg))
|
||||
goto end2;
|
||||
if (!_slang_flatten_aggregate (&flat_agg, &agg))
|
||||
goto end;
|
||||
|
||||
if (!(result = _slang_assemble_operation (file, op, 0, flow, space, info, &stk)))
|
||||
if (!_slang_assemble_operation_ (A, op, slang_ref_forbid))
|
||||
goto end;
|
||||
|
||||
for (i = 0; i < flat_agg.count; i++)
|
||||
{
|
||||
const slang_storage_array *arr1 = flat_agg.arrays + i;
|
||||
const slang_storage_array *arr2 = flat->arrays + *index;
|
||||
const slang_storage_array *arr1 = &flat_agg.arrays[i];
|
||||
const slang_storage_array *arr2 = &flat->arrays[*index];
|
||||
|
||||
if (arr1->type != arr2->type)
|
||||
{
|
||||
|
@ -183,7 +185,7 @@ static int constructor_aggregate (slang_assembly_file *file, const slang_storage
|
|||
/* TODO: watch the index, if it reaches the size, pop off the stack subsequent values */
|
||||
}
|
||||
|
||||
result = 1;
|
||||
result = GL_TRUE;
|
||||
end:
|
||||
slang_storage_aggregate_destruct (&flat_agg);
|
||||
end2:
|
||||
|
@ -192,48 +194,49 @@ end1:
|
|||
slang_assembly_typeinfo_destruct (&ti);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* XXX: general swizzle! */
|
||||
|
||||
#if 0
|
||||
int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *pmach)
|
||||
GLboolean _slang_assemble_constructor (slang_assemble_ctx *A, slang_operation *op)
|
||||
{
|
||||
slang_assembly_typeinfo ti;
|
||||
int result;
|
||||
GLboolean result = GL_FALSE;
|
||||
slang_storage_aggregate agg, flat;
|
||||
unsigned int size, index, i;
|
||||
GLuint size, index, i;
|
||||
|
||||
/* get typeinfo of the constructor (the result of constructor expression) */
|
||||
if (!slang_assembly_typeinfo_construct (&ti))
|
||||
return 0;
|
||||
if (!(result = _slang_typeof_operation (op, space, &ti)))
|
||||
return GL_FALSE;
|
||||
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
|
||||
goto end1;
|
||||
|
||||
if (!(result = slang_storage_aggregate_construct (&agg)))
|
||||
/* create an aggregate of the constructor */
|
||||
if (!slang_storage_aggregate_construct (&agg))
|
||||
goto end1;
|
||||
if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
|
||||
space->vars, pmach, file)))
|
||||
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
|
||||
A->space.vars, A->mach, A->file, A->atoms))
|
||||
goto end2;
|
||||
|
||||
/* calculate size of the constructor */
|
||||
size = _slang_sizeof_aggregate (&agg);
|
||||
|
||||
if (!(result = slang_storage_aggregate_construct (&flat)))
|
||||
/* flatten the constructor */
|
||||
if (!slang_storage_aggregate_construct (&flat))
|
||||
goto end2;
|
||||
if (!(result = _slang_flatten_aggregate (&flat, &agg)))
|
||||
if (!_slang_flatten_aggregate (&flat, &agg))
|
||||
goto end;
|
||||
|
||||
/* XXX: The children operations are traversed in a reversed order, so it poses a
|
||||
* problem when there is more data than the constructor needs. We must fix it! */
|
||||
|
||||
/* traverse the children that form the constructor expression */
|
||||
index = 0;
|
||||
for (i = 0; i < op->num_children; i++)
|
||||
for (i = op->num_children; i > 0; i--)
|
||||
{
|
||||
if (!(result = constructor_aggregate (file, &flat, &index, op->children + i, size, flow,
|
||||
space, info)))
|
||||
if (!constructor_aggregate (A, &flat, &index, &op->children[i - 1], size))
|
||||
goto end;
|
||||
/* TODO: watch the index, if it reaches the size, raise an error */
|
||||
}
|
||||
|
||||
result = 1;
|
||||
result = GL_TRUE;
|
||||
end:
|
||||
slang_storage_aggregate_destruct (&flat);
|
||||
end2:
|
||||
|
@ -242,14 +245,13 @@ end1:
|
|||
slang_assembly_typeinfo_destruct (&ti);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* _slang_assemble_constructor_from_swizzle() */
|
||||
|
||||
int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,
|
||||
slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info)
|
||||
GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *A, const slang_swizzle *swz,
|
||||
slang_type_specifier *spec, slang_type_specifier *master_spec)
|
||||
{
|
||||
unsigned int master_rows, i;
|
||||
GLuint master_rows, i;
|
||||
|
||||
master_rows = _slang_type_dim (master_spec->type);
|
||||
for (i = 0; i < master_rows; i++)
|
||||
|
@ -257,54 +259,55 @@ int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const s
|
|||
switch (_slang_type_base (master_spec->type))
|
||||
{
|
||||
case slang_spec_bool:
|
||||
if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy,
|
||||
if (!slang_assembly_file_push_label2 (A->file, slang_asm_bool_copy,
|
||||
(master_rows - i) * 4, i * 4))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_spec_int:
|
||||
if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy,
|
||||
if (!slang_assembly_file_push_label2 (A->file, slang_asm_int_copy,
|
||||
(master_rows - i) * 4, i * 4))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_spec_float:
|
||||
if (!slang_assembly_file_push_label2 (file, slang_asm_float_copy,
|
||||
if (!slang_assembly_file_push_label2 (A->file, slang_asm_float_copy,
|
||||
(master_rows - i) * 4, i * 4))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))
|
||||
return GL_FALSE;
|
||||
for (i = swz->num_components; i > 0; i--)
|
||||
{
|
||||
unsigned int n = i - 1;
|
||||
GLuint n = i - 1;
|
||||
|
||||
if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_addr_push, swz->swizzle[n] * 4))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push (file, slang_asm_addr_add))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_addr_push, swz->swizzle[n] * 4))
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_addr_add))
|
||||
return GL_FALSE;
|
||||
switch (_slang_type_base (master_spec->type))
|
||||
{
|
||||
case slang_spec_bool:
|
||||
if (!slang_assembly_file_push (file, slang_asm_bool_deref))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_bool_deref))
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_spec_int:
|
||||
if (!slang_assembly_file_push (file, slang_asm_int_deref))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_int_deref))
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_spec_float:
|
||||
if (!slang_assembly_file_push (file, slang_asm_float_deref))
|
||||
return 0;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_float_deref))
|
||||
return GL_FALSE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,33 +33,31 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/*
|
||||
checks if a field selector is a general swizzle (an r-value swizzle with replicated
|
||||
components or an l-value swizzle mask) for a vector
|
||||
returns 1 if this is the case, <swz> is filled with swizzle information
|
||||
returns 0 otherwise
|
||||
* Checks if a field selector is a general swizzle (an r-value swizzle with replicated
|
||||
* components or an l-value swizzle mask) for a vector.
|
||||
* Returns GL_TRUE if this is the case, <swz> is filled with swizzle information.
|
||||
* Returns GL_FALSE otherwise.
|
||||
*/
|
||||
int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz);
|
||||
GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz);
|
||||
|
||||
/*
|
||||
checks if a general swizzle is an l-value swizzle - these swizzles do not have
|
||||
duplicated fields and they are specified in order
|
||||
returns 1 if this is a swizzle mask
|
||||
returns 0 otherwise
|
||||
* Checks if a general swizzle is an l-value swizzle - these swizzles do not have
|
||||
* duplicated fields.
|
||||
* Returns GL_TRUE if this is a swizzle mask.
|
||||
* Returns GL_FALSE otherwise
|
||||
*/
|
||||
int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows);
|
||||
GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows);
|
||||
|
||||
/*
|
||||
combines two swizzles to form single swizzle
|
||||
example: "wzyx.yx" --> "zw"
|
||||
* Combines (multiplies) two swizzles to form single swizzle.
|
||||
* Example: "vec.wzyx.yx" --> "vec.zw".
|
||||
*/
|
||||
void _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const slang_swizzle *);
|
||||
GLvoid _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const slang_swizzle *);
|
||||
|
||||
int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
|
||||
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
|
||||
slang_assembly_local_info *info, struct slang_machine_ *);
|
||||
GLboolean _slang_assemble_constructor (slang_assemble_ctx *, slang_operation *);
|
||||
|
||||
int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,
|
||||
slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info);
|
||||
GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *, const slang_swizzle *,
|
||||
slang_type_specifier *, slang_type_specifier *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -34,15 +34,15 @@
|
|||
|
||||
/* slang_assembly_typeinfo */
|
||||
|
||||
int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
|
||||
GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
|
||||
{
|
||||
if (!slang_type_specifier_construct (&ti->spec))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
ti->array_size = NULL;
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
|
||||
GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
|
||||
{
|
||||
slang_type_specifier_destruct (&ti->spec);
|
||||
/* do not free ti->array_size */
|
||||
|
@ -50,24 +50,24 @@ void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
|
|||
|
||||
/* _slang_typeof_operation() */
|
||||
|
||||
static int typeof_existing_function (const char *name, slang_operation *params,
|
||||
unsigned int num_params, slang_assembly_name_space *space, slang_type_specifier *spec,
|
||||
static GLboolean typeof_existing_function (const char *name, slang_operation *params,
|
||||
GLuint num_params, slang_assembly_name_space *space, slang_type_specifier *spec,
|
||||
slang_atom_pool *atoms)
|
||||
{
|
||||
slang_atom atom;
|
||||
int exists;
|
||||
GLboolean exists;
|
||||
|
||||
atom = slang_atom_pool_atom (atoms, name);
|
||||
if (!_slang_typeof_function (atom, params, num_params, space, spec, &exists, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
return exists;
|
||||
}
|
||||
|
||||
int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,
|
||||
GLboolean _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,
|
||||
slang_assembly_typeinfo *ti, slang_atom_pool *atoms)
|
||||
{
|
||||
ti->can_be_referenced = 0;
|
||||
ti->is_swizzled = 0;
|
||||
ti->can_be_referenced = GL_FALSE;
|
||||
ti->is_swizzled = GL_FALSE;
|
||||
|
||||
switch (op->type)
|
||||
{
|
||||
|
@ -120,21 +120,21 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
{
|
||||
slang_variable *var;
|
||||
|
||||
var = _slang_locate_variable (op->locals, op->a_id, 1);
|
||||
var = _slang_locate_variable (op->locals, op->a_id, GL_TRUE);
|
||||
if (var == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_type_specifier_copy (&ti->spec, &var->type.specifier))
|
||||
return 0;
|
||||
ti->can_be_referenced = 1;
|
||||
return GL_FALSE;
|
||||
ti->can_be_referenced = GL_TRUE;
|
||||
ti->array_size = var->array_size;
|
||||
}
|
||||
break;
|
||||
case slang_oper_sequence:
|
||||
/* TODO: check [0] and [1] if they match */
|
||||
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
|
||||
return 0;
|
||||
ti->can_be_referenced = 0;
|
||||
ti->is_swizzled = 0;
|
||||
return GL_FALSE;
|
||||
ti->can_be_referenced = GL_FALSE;
|
||||
ti->is_swizzled = GL_FALSE;
|
||||
break;
|
||||
/*case slang_oper_modassign:*/
|
||||
/*case slang_oper_lshassign:*/
|
||||
|
@ -145,9 +145,9 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
case slang_oper_select:
|
||||
/* TODO: check [1] and [2] if they match */
|
||||
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
|
||||
return 0;
|
||||
ti->can_be_referenced = 0;
|
||||
ti->is_swizzled = 0;
|
||||
return GL_FALSE;
|
||||
ti->can_be_referenced = GL_FALSE;
|
||||
ti->is_swizzled = GL_FALSE;
|
||||
break;
|
||||
/*case slang_oper_bitor:*/
|
||||
/*case slang_oper_bitxor:*/
|
||||
|
@ -156,30 +156,30 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
/*case slang_oper_rshift:*/
|
||||
case slang_oper_add:
|
||||
if (!typeof_existing_function ("+", op->children, 2, space, &ti->spec, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_oper_subtract:
|
||||
if (!typeof_existing_function ("-", op->children, 2, space, &ti->spec, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_oper_multiply:
|
||||
if (!typeof_existing_function ("*", op->children, 2, space, &ti->spec, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
case slang_oper_divide:
|
||||
if (!typeof_existing_function ("/", op->children, 2, space, &ti->spec, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
/*case slang_oper_modulus:*/
|
||||
case slang_oper_plus:
|
||||
if (!_slang_typeof_operation (op->children, space, ti, atoms))
|
||||
return 0;
|
||||
ti->can_be_referenced = 0;
|
||||
ti->is_swizzled = 0;
|
||||
return GL_FALSE;
|
||||
ti->can_be_referenced = GL_FALSE;
|
||||
ti->is_swizzled = GL_FALSE;
|
||||
break;
|
||||
case slang_oper_minus:
|
||||
if (!typeof_existing_function ("-", op->children, 1, space, &ti->spec, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
break;
|
||||
/*case slang_oper_complement:*/
|
||||
case slang_oper_subscript:
|
||||
|
@ -187,11 +187,11 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
slang_assembly_typeinfo _ti;
|
||||
|
||||
if (!slang_assembly_typeinfo_construct (&_ti))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
ti->can_be_referenced = _ti.can_be_referenced;
|
||||
if (_ti.spec.type == slang_spec_array)
|
||||
|
@ -199,7 +199,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
if (!slang_type_specifier_copy (&ti->spec, _ti.spec._array))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -207,7 +207,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
if (!_slang_type_is_vector (_ti.spec.type) && !_slang_type_is_matrix (_ti.spec.type))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
ti->spec.type = _slang_type_base (_ti.spec.type);
|
||||
}
|
||||
|
@ -216,38 +216,38 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
break;
|
||||
case slang_oper_call:
|
||||
{
|
||||
int exists;
|
||||
GLboolean exists;
|
||||
|
||||
if (!_slang_typeof_function (op->a_id, op->children, op->num_children, space, &ti->spec,
|
||||
&exists, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!exists)
|
||||
{
|
||||
/* slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);
|
||||
slang_struct *s = slang_struct_scope_find (space->structs, op->a_id, GL_TRUE);
|
||||
if (s != NULL)
|
||||
{
|
||||
ti->spec.type = slang_spec_struct;
|
||||
ti->spec._struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
|
||||
if (ti->spec._struct == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_struct_construct (ti->spec._struct))
|
||||
{
|
||||
slang_alloc_free (ti->spec._struct);
|
||||
ti->spec._struct = NULL;
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
if (!slang_struct_copy (ti->spec._struct, s))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
else
|
||||
*/ {
|
||||
{
|
||||
const char *name;
|
||||
slang_type_specifier_type type;
|
||||
|
||||
name = slang_atom_pool_id (atoms, op->a_id);
|
||||
type = slang_type_specifier_type_from_string (name);
|
||||
if (type == slang_spec_void)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
ti->spec.type = type;
|
||||
}
|
||||
}
|
||||
|
@ -258,32 +258,32 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
slang_assembly_typeinfo _ti;
|
||||
|
||||
if (!slang_assembly_typeinfo_construct (&_ti))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
if (_ti.spec.type == slang_spec_struct)
|
||||
{
|
||||
slang_variable *field;
|
||||
|
||||
field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, 0);
|
||||
field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, GL_FALSE);
|
||||
if (field == NULL)
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
if (!slang_type_specifier_copy (&ti->spec, &field->type.specifier))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
ti->can_be_referenced = _ti.can_be_referenced;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int rows;
|
||||
GLuint rows;
|
||||
const char *swizzle;
|
||||
slang_type_specifier_type base;
|
||||
|
||||
|
@ -291,16 +291,16 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
if (!_slang_type_is_vector (_ti.spec.type))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
rows = _slang_type_dim (_ti.spec.type);
|
||||
swizzle = slang_atom_pool_id (atoms, op->a_id);
|
||||
if (!_slang_is_swizzle (swizzle, rows, &ti->swz))
|
||||
{
|
||||
slang_assembly_typeinfo_destruct (&_ti);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
ti->is_swizzled = 1;
|
||||
ti->is_swizzled = GL_TRUE;
|
||||
ti->can_be_referenced = _ti.can_be_referenced && _slang_is_swizzle_mask (&ti->swz,
|
||||
rows);
|
||||
if (_ti.is_swizzled)
|
||||
|
@ -330,8 +330,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
ti->spec.type = slang_spec_bvec2;
|
||||
break;
|
||||
default:
|
||||
_mesa_problem(NULL, "unexepected base in _slang_typeof_operation");
|
||||
ti->spec.type = slang_spec_void;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
|
@ -347,8 +346,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
ti->spec.type = slang_spec_bvec3;
|
||||
break;
|
||||
default:
|
||||
_mesa_problem(NULL, "unexepected base in _slang_typeof_operation");
|
||||
ti->spec.type = slang_spec_void;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
|
@ -364,8 +362,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
ti->spec.type = slang_spec_bvec4;
|
||||
break;
|
||||
default:
|
||||
_mesa_problem(NULL, "unexepected base in _slang_typeof_operation");
|
||||
ti->spec.type = slang_spec_void;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -378,48 +375,50 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
|
|||
case slang_oper_postincrement:
|
||||
case slang_oper_postdecrement:
|
||||
if (!_slang_typeof_operation (op->children, space, ti, atoms))
|
||||
return 0;
|
||||
ti->can_be_referenced = 0;
|
||||
ti->is_swizzled = 0;
|
||||
return GL_FALSE;
|
||||
ti->can_be_referenced = GL_FALSE;
|
||||
ti->is_swizzled = GL_FALSE;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
return 1;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* _slang_typeof_function() */
|
||||
|
||||
int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
|
||||
slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *atoms)
|
||||
GLboolean _slang_typeof_function (slang_atom a_name, slang_operation *params, GLuint num_params,
|
||||
slang_assembly_name_space *space, slang_type_specifier *spec, GLboolean *exists,
|
||||
slang_atom_pool *atoms)
|
||||
{
|
||||
slang_function *fun;
|
||||
|
||||
fun = _slang_locate_function (space->funcs, a_name, params, num_params, space, atoms);
|
||||
*exists = fun != NULL;
|
||||
if (fun == NULL)
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
return slang_type_specifier_copy (spec, &fun->header.type.specifier);
|
||||
}
|
||||
|
||||
/* _slang_type_is_matrix() */
|
||||
|
||||
int _slang_type_is_matrix (slang_type_specifier_type ty)
|
||||
GLboolean _slang_type_is_matrix (slang_type_specifier_type ty)
|
||||
{
|
||||
switch (ty)
|
||||
{
|
||||
case slang_spec_mat2:
|
||||
case slang_spec_mat3:
|
||||
case slang_spec_mat4:
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
default:
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* _slang_type_is_vector() */
|
||||
|
||||
int _slang_type_is_vector (slang_type_specifier_type ty)
|
||||
GLboolean _slang_type_is_vector (slang_type_specifier_type ty)
|
||||
{
|
||||
switch (ty)
|
||||
{
|
||||
|
@ -432,9 +431,9 @@ int _slang_type_is_vector (slang_type_specifier_type ty)
|
|||
case slang_spec_bvec2:
|
||||
case slang_spec_bvec3:
|
||||
case slang_spec_bvec4:
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
default:
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,7 +471,7 @@ slang_type_specifier_type _slang_type_base (slang_type_specifier_type ty)
|
|||
|
||||
/* _slang_type_dim */
|
||||
|
||||
unsigned int _slang_type_dim (slang_type_specifier_type ty)
|
||||
GLuint _slang_type_dim (slang_type_specifier_type ty)
|
||||
{
|
||||
switch (ty)
|
||||
{
|
||||
|
|
|
@ -34,36 +34,39 @@ extern "C" {
|
|||
|
||||
typedef struct slang_assembly_typeinfo_
|
||||
{
|
||||
int can_be_referenced;
|
||||
int is_swizzled;
|
||||
GLboolean can_be_referenced;
|
||||
GLboolean is_swizzled;
|
||||
slang_swizzle swz;
|
||||
slang_type_specifier spec;
|
||||
slang_operation *array_size;
|
||||
} slang_assembly_typeinfo;
|
||||
|
||||
int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
|
||||
void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
|
||||
GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
|
||||
GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
|
||||
|
||||
/*
|
||||
retrieves type information about an operation
|
||||
returns 1 on success
|
||||
returns 0 otherwise
|
||||
* Retrieves type information about an operation.
|
||||
* Returns GL_TRUE on success.
|
||||
* Returns GL_FALSE otherwise.
|
||||
*/
|
||||
int _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,
|
||||
GLboolean _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,
|
||||
slang_assembly_typeinfo *, slang_atom_pool *);
|
||||
|
||||
/*
|
||||
retrieves type of a function prototype, if one exists
|
||||
returns 1 on success, even if the function was not found
|
||||
returns 0 otherwise
|
||||
* Retrieves type of a function prototype, if one exists.
|
||||
* Returns GL_TRUE on success, even if the function was not found.
|
||||
* Returns GL_FALSE otherwise.
|
||||
*/
|
||||
int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
|
||||
slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *);
|
||||
GLboolean _slang_typeof_function (slang_atom a_name, slang_operation *params, GLuint num_params,
|
||||
slang_assembly_name_space *, slang_type_specifier *spec, GLboolean *exists, slang_atom_pool *);
|
||||
|
||||
GLboolean _slang_type_is_matrix (slang_type_specifier_type);
|
||||
|
||||
GLboolean _slang_type_is_vector (slang_type_specifier_type);
|
||||
|
||||
int _slang_type_is_matrix (slang_type_specifier_type);
|
||||
int _slang_type_is_vector (slang_type_specifier_type);
|
||||
slang_type_specifier_type _slang_type_base (slang_type_specifier_type);
|
||||
unsigned int _slang_type_dim (slang_type_specifier_type);
|
||||
|
||||
GLuint _slang_type_dim (slang_type_specifier_type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@
|
|||
#include "slang_execute.h"
|
||||
|
||||
/*
|
||||
This is a straightforward implementation of the slang front-end compiler.
|
||||
Lots of error-checking functionality is missing but every well-formed shader source should
|
||||
compile successfully and execute as expected. However, some semantically ill-formed shaders
|
||||
may be accepted resulting in undefined behaviour.
|
||||
* This is a straightforward implementation of the slang front-end compiler.
|
||||
* Lots of error-checking functionality is missing but every well-formed shader source should
|
||||
* compile successfully and execute as expected. However, some semantically ill-formed shaders
|
||||
* may be accepted resulting in undefined behaviour.
|
||||
*/
|
||||
|
||||
/* slang_var_pool */
|
||||
|
@ -1489,36 +1489,34 @@ static int parse_function_definition (slang_parse_ctx *C, slang_output_ctx *O, s
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
|
||||
static GLboolean initialize_global (slang_assemble_ctx *A, slang_variable *var)
|
||||
{
|
||||
slang_assembly_file_restore_point point;
|
||||
slang_machine mach;
|
||||
slang_assembly_local_info info;
|
||||
slang_assembly_local_info save_local = A->local;
|
||||
slang_operation op_id, op_assign;
|
||||
int result;
|
||||
slang_assembly_flow_control flow;
|
||||
slang_assembly_stack_info stk;
|
||||
GLboolean result;
|
||||
|
||||
/* save the current assembly */
|
||||
if (!slang_assembly_file_restore_point_save (A->file, &point))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* setup the machine */
|
||||
mach = *A->mach;
|
||||
mach.ip = A->file->count;
|
||||
|
||||
/* allocate local storage for expression */
|
||||
info.ret_size = 0;
|
||||
info.addr_tmp = 0;
|
||||
info.swizzle_tmp = 4;
|
||||
A->local.ret_size = 0;
|
||||
A->local.addr_tmp = 0;
|
||||
A->local.swizzle_tmp = 4;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_local_alloc, 20))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push_label (A->file, slang_asm_enter, 20))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* construct the left side of assignment */
|
||||
if (!slang_operation_construct (&op_id))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
op_id.type = slang_oper_identifier;
|
||||
op_id.a_id = var->a_name;
|
||||
|
||||
|
@ -1527,7 +1525,7 @@ static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
|
|||
if (op_id.locals->variables == NULL)
|
||||
{
|
||||
slang_operation_destruct (&op_id);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
op_id.locals->num_variables = 1;
|
||||
op_id.locals->variables[0] = *var;
|
||||
|
@ -1537,7 +1535,7 @@ static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
|
|||
{
|
||||
op_id.locals->num_variables = 0;
|
||||
slang_operation_destruct (&op_id);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
op_assign.type = slang_oper_assign;
|
||||
op_assign.children = (slang_operation *) slang_alloc_malloc (2 * sizeof (slang_operation));
|
||||
|
@ -1546,14 +1544,14 @@ static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
|
|||
slang_operation_destruct (&op_assign);
|
||||
op_id.locals->num_variables = 0;
|
||||
slang_operation_destruct (&op_id);
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
op_assign.num_children = 2;
|
||||
op_assign.children[0] = op_id;
|
||||
op_assign.children[1] = *var->initializer;
|
||||
|
||||
/* insert the actual expression */
|
||||
result = _slang_assemble_operation (A->file, &op_assign, 0, &flow, &A->space, &info, &stk, A->mach, A->atoms);
|
||||
result = _slang_assemble_operation_ (A, &op_assign, slang_ref_forbid);
|
||||
|
||||
/* carefully destroy the operations */
|
||||
op_assign.num_children = 0;
|
||||
|
@ -1564,23 +1562,24 @@ static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
|
|||
slang_operation_destruct (&op_id);
|
||||
|
||||
if (!result)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push (A->file, slang_asm_exit))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* execute the expression */
|
||||
if (!_slang_execute2 (A->file, &mach))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* restore the old assembly */
|
||||
if (!slang_assembly_file_restore_point_load (A->file, &point))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
A->local = save_local;
|
||||
|
||||
/* now we copy the contents of the initialized variable back to the original machine */
|
||||
_mesa_memcpy ((GLubyte *) A->mach->mem + var->address, (GLubyte *) mach.mem + var->address,
|
||||
var->size);
|
||||
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
/* init declarator list */
|
||||
|
@ -2110,7 +2109,7 @@ int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit
|
|||
{
|
||||
int success;
|
||||
grammar id = 0;
|
||||
// slang_translation_unit builtin_units[BUILTIN_TOTAL];
|
||||
/* slang_translation_unit builtin_units[BUILTIN_TOTAL];*/
|
||||
slang_translation_unit *builtin_units;
|
||||
int compiled[BUILTIN_TOTAL] = { 0 };
|
||||
|
||||
|
|
|
@ -352,9 +352,9 @@ int slang_variable_copy (slang_variable *x, const slang_variable *y)
|
|||
return 1;
|
||||
}
|
||||
|
||||
slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all)
|
||||
slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, GLboolean all)
|
||||
{
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
for (i = 0; i < scope->num_variables; i++)
|
||||
if (a_name == scope->variables[i].a_name)
|
||||
|
|
|
@ -121,7 +121,7 @@ int slang_variable_construct (slang_variable *);
|
|||
void slang_variable_destruct (slang_variable *);
|
||||
int slang_variable_copy (slang_variable *, const slang_variable *);
|
||||
|
||||
slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all);
|
||||
slang_variable *_slang_locate_variable (slang_variable_scope *, slang_atom a_name, GLboolean all);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "slang_assemble.h"
|
||||
#include "slang_storage.h"
|
||||
#include "slang_execute.h"
|
||||
#include "slang_library_noise.h"
|
||||
|
||||
#define DEBUG_SLANG 0
|
||||
|
||||
|
@ -122,6 +123,18 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i)
|
|||
case slang_asm_float_ceil:
|
||||
fprintf (f, "float_ceil");
|
||||
break;
|
||||
case slang_asm_float_noise1:
|
||||
fprintf (f, "float_noise1");
|
||||
break;
|
||||
case slang_asm_float_noise2:
|
||||
fprintf (f, "float_noise2");
|
||||
break;
|
||||
case slang_asm_float_noise3:
|
||||
fprintf (f, "float_noise3");
|
||||
break;
|
||||
case slang_asm_float_noise4:
|
||||
fprintf (f, "float_noise4");
|
||||
break;
|
||||
case slang_asm_int_copy:
|
||||
fprintf (f, "int_copy\t%d, %d", a->param[0], a->param[1]);
|
||||
break;
|
||||
|
@ -365,6 +378,24 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach)
|
|||
case slang_asm_float_ceil:
|
||||
stack[mach->sp]._float = CEILF (stack[mach->sp]._float);
|
||||
break;
|
||||
case slang_asm_float_noise1:
|
||||
stack[mach->sp]._float = _slang_library_noise1 (stack[mach->sp]._float);
|
||||
break;
|
||||
case slang_asm_float_noise2:
|
||||
stack[mach->sp + 1]._float = _slang_library_noise2 (stack[mach->sp]._float,
|
||||
stack[mach->sp + 1]._float);
|
||||
mach->sp++;
|
||||
break;
|
||||
case slang_asm_float_noise3:
|
||||
stack[mach->sp + 2]._float = _slang_library_noise3 (stack[mach->sp]._float,
|
||||
stack[mach->sp + 1]._float, stack[mach->sp + 2]._float);
|
||||
mach->sp += 2;
|
||||
break;
|
||||
case slang_asm_float_noise4:
|
||||
stack[mach->sp + 3]._float = _slang_library_noise4 (stack[mach->sp]._float,
|
||||
stack[mach->sp + 1]._float, stack[mach->sp + 2]._float, stack[mach->sp + 3]._float);
|
||||
mach->sp += 3;
|
||||
break;
|
||||
case slang_asm_int_to_float:
|
||||
break;
|
||||
case slang_asm_int_to_addr:
|
||||
|
@ -442,6 +473,8 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach)
|
|||
case slang_asm_bool_print:
|
||||
_mesa_printf ("slang print: %s\n", (GLint) stack[mach->sp]._float ? "true" : "false");
|
||||
break;
|
||||
default:
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,514 @@
|
|||
/*
|
||||
* Mesa 3-D graphics library
|
||||
* Version: 6.5
|
||||
*
|
||||
* Copyright (C) 2006 Brian Paul All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* BRIAN PAUL 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.
|
||||
*/
|
||||
|
||||
#include "imports.h"
|
||||
|
||||
/*
|
||||
* SimplexNoise1234
|
||||
* Copyright © 2003-2005, Stefan Gustavson
|
||||
*
|
||||
* Contact: stegu@itn.liu.se
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\brief C implementation of Perlin Simplex Noise over 1,2,3, and 4 dimensions.
|
||||
\author Stefan Gustavson (stegu@itn.liu.se)
|
||||
*/
|
||||
|
||||
/*
|
||||
* This implementation is "Simplex Noise" as presented by
|
||||
* Ken Perlin at a relatively obscure and not often cited course
|
||||
* session "Real-Time Shading" at Siggraph 2001 (before real
|
||||
* time shading actually took on), under the title "hardware noise".
|
||||
* The 3D function is numerically equivalent to his Java reference
|
||||
* code available in the PDF course notes, although I re-implemented
|
||||
* it from scratch to get more readable code. The 1D, 2D and 4D cases
|
||||
* were implemented from scratch by me from Ken Perlin's text.
|
||||
*
|
||||
* This file has no dependencies on any other file, not even its own
|
||||
* header file. The header file is made for use by external code only.
|
||||
*/
|
||||
|
||||
|
||||
#define FASTFLOOR(x) ( ((x)>0) ? ((int)x) : (((int)x)-1) )
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------
|
||||
* Static data
|
||||
*/
|
||||
|
||||
/*
|
||||
* Permutation table. This is just a random jumble of all numbers 0-255,
|
||||
* repeated twice to avoid wrapping the index at 255 for each lookup.
|
||||
* This needs to be exactly the same for all instances on all platforms,
|
||||
* so it's easiest to just keep it as static explicit data.
|
||||
* This also removes the need for any initialisation of this class.
|
||||
*
|
||||
* Note that making this an int[] instead of a char[] might make the
|
||||
* code run faster on platforms with a high penalty for unaligned single
|
||||
* byte addressing. Intel x86 is generally single-byte-friendly, but
|
||||
* some other CPUs are faster with 4-aligned reads.
|
||||
* However, a char[] is smaller, which avoids cache trashing, and that
|
||||
* is probably the most important aspect on most architectures.
|
||||
* This array is accessed a *lot* by the noise functions.
|
||||
* A vector-valued noise over 3D accesses it 96 times, and a
|
||||
* float-valued 4D noise 64 times. We want this to fit in the cache!
|
||||
*/
|
||||
unsigned char perm[512] = {151,160,137,91,90,15,
|
||||
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
|
||||
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
|
||||
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
|
||||
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
|
||||
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
|
||||
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
|
||||
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
|
||||
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
|
||||
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
|
||||
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
|
||||
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
|
||||
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
|
||||
151,160,137,91,90,15,
|
||||
131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
|
||||
190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
|
||||
88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
|
||||
77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
|
||||
102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
|
||||
135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
|
||||
5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
|
||||
223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
|
||||
129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
|
||||
251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
|
||||
49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
|
||||
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
|
||||
};
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Helper functions to compute gradients-dot-residualvectors (1D to 4D)
|
||||
* Note that these generate gradients of more than unit length. To make
|
||||
* a close match with the value range of classic Perlin noise, the final
|
||||
* noise values need to be rescaled to fit nicely within [-1,1].
|
||||
* (The simplex noise functions as such also have different scaling.)
|
||||
* Note also that these noise functions are the most practical and useful
|
||||
* signed version of Perlin noise. To return values according to the
|
||||
* RenderMan specification from the SL noise() and pnoise() functions,
|
||||
* the noise values need to be scaled and offset to [0,1], like this:
|
||||
* float SLnoise = (SimplexNoise1234::noise(x,y,z) + 1.0) * 0.5;
|
||||
*/
|
||||
|
||||
static float grad1( int hash, float x ) {
|
||||
int h = hash & 15;
|
||||
float grad = 1.0f + (h & 7); /* Gradient value 1.0, 2.0, ..., 8.0 */
|
||||
if (h&8) grad = -grad; /* Set a random sign for the gradient */
|
||||
return ( grad * x ); /* Multiply the gradient with the distance */
|
||||
}
|
||||
|
||||
static float grad2( int hash, float x, float y ) {
|
||||
int h = hash & 7; /* Convert low 3 bits of hash code */
|
||||
float u = h<4 ? x : y; /* into 8 simple gradient directions, */
|
||||
float v = h<4 ? y : x; /* and compute the dot product with (x,y). */
|
||||
return ((h&1)? -u : u) + ((h&2)? -2.0f*v : 2.0f*v);
|
||||
}
|
||||
|
||||
static float grad3( int hash, float x, float y , float z ) {
|
||||
int h = hash & 15; /* Convert low 4 bits of hash code into 12 simple */
|
||||
float u = h<8 ? x : y; /* gradient directions, and compute dot product. */
|
||||
float v = h<4 ? y : h==12||h==14 ? x : z; /* Fix repeats at h = 12 to 15 */
|
||||
return ((h&1)? -u : u) + ((h&2)? -v : v);
|
||||
}
|
||||
|
||||
static float grad4( int hash, float x, float y, float z, float t ) {
|
||||
int h = hash & 31; /* Convert low 5 bits of hash code into 32 simple */
|
||||
float u = h<24 ? x : y; /* gradient directions, and compute dot product. */
|
||||
float v = h<16 ? y : z;
|
||||
float w = h<8 ? z : t;
|
||||
return ((h&1)? -u : u) + ((h&2)? -v : v) + ((h&4)? -w : w);
|
||||
}
|
||||
|
||||
/* A lookup table to traverse the simplex around a given point in 4D. */
|
||||
/* Details can be found where this table is used, in the 4D noise method. */
|
||||
/* TODO: This should not be required, backport it from Bill's GLSL code! */
|
||||
static unsigned char simplex[64][4] = {
|
||||
{0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
|
||||
{0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
|
||||
{1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
|
||||
{2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}};
|
||||
|
||||
/* 1D simplex noise */
|
||||
GLfloat _slang_library_noise1 (GLfloat x)
|
||||
{
|
||||
int i0 = FASTFLOOR(x);
|
||||
int i1 = i0 + 1;
|
||||
float x0 = x - i0;
|
||||
float x1 = x0 - 1.0f;
|
||||
float t1 = 1.0f - x1*x1;
|
||||
float n0, n1;
|
||||
|
||||
float t0 = 1.0f - x0*x0;
|
||||
/* if(t0 < 0.0f) t0 = 0.0f; // this never happens for the 1D case */
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad1(perm[i0 & 0xff], x0);
|
||||
|
||||
/* if(t1 < 0.0f) t1 = 0.0f; // this never happens for the 1D case */
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * grad1(perm[i1 & 0xff], x1);
|
||||
/* The maximum value of this noise is 8*(3/4)^4 = 2.53125 */
|
||||
/* A factor of 0.395 would scale to fit exactly within [-1,1], but */
|
||||
/* we want to match PRMan's 1D noise, so we scale it down some more. */
|
||||
return 0.25f * (n0 + n1);
|
||||
}
|
||||
|
||||
/* 2D simplex noise */
|
||||
GLfloat _slang_library_noise2 (GLfloat x, GLfloat y)
|
||||
{
|
||||
#define F2 0.366025403f /* F2 = 0.5*(sqrt(3.0)-1.0) */
|
||||
#define G2 0.211324865f /* G2 = (3.0-Math.sqrt(3.0))/6.0 */
|
||||
|
||||
float n0, n1, n2; /* Noise contributions from the three corners */
|
||||
|
||||
/* Skew the input space to determine which simplex cell we're in */
|
||||
float s = (x+y)*F2; /* Hairy factor for 2D */
|
||||
float xs = x + s;
|
||||
float ys = y + s;
|
||||
int i = FASTFLOOR(xs);
|
||||
int j = FASTFLOOR(ys);
|
||||
|
||||
float t = (float)(i+j)*G2;
|
||||
float X0 = i-t; /* Unskew the cell origin back to (x,y) space */
|
||||
float Y0 = j-t;
|
||||
float x0 = x-X0; /* The x,y distances from the cell origin */
|
||||
float y0 = y-Y0;
|
||||
|
||||
float x1, y1, x2, y2;
|
||||
int ii, jj;
|
||||
float t0, t1, t2;
|
||||
|
||||
/* For the 2D case, the simplex shape is an equilateral triangle. */
|
||||
/* Determine which simplex we are in. */
|
||||
int i1, j1; /* Offsets for second (middle) corner of simplex in (i,j) coords */
|
||||
if(x0>y0) {i1=1; j1=0;} /* lower triangle, XY order: (0,0)->(1,0)->(1,1) */
|
||||
else {i1=0; j1=1;} /* upper triangle, YX order: (0,0)->(0,1)->(1,1) */
|
||||
|
||||
/* A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and */
|
||||
/* a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where */
|
||||
/* c = (3-sqrt(3))/6 */
|
||||
|
||||
x1 = x0 - i1 + G2; /* Offsets for middle corner in (x,y) unskewed coords */
|
||||
y1 = y0 - j1 + G2;
|
||||
x2 = x0 - 1.0f + 2.0f * G2; /* Offsets for last corner in (x,y) unskewed coords */
|
||||
y2 = y0 - 1.0f + 2.0f * G2;
|
||||
|
||||
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
|
||||
ii = i % 256;
|
||||
jj = j % 256;
|
||||
|
||||
/* Calculate the contribution from the three corners */
|
||||
t0 = 0.5f - x0*x0-y0*y0;
|
||||
if(t0 < 0.0f) n0 = 0.0f;
|
||||
else {
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad2(perm[ii+perm[jj]], x0, y0);
|
||||
}
|
||||
|
||||
t1 = 0.5f - x1*x1-y1*y1;
|
||||
if(t1 < 0.0f) n1 = 0.0f;
|
||||
else {
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * grad2(perm[ii+i1+perm[jj+j1]], x1, y1);
|
||||
}
|
||||
|
||||
t2 = 0.5f - x2*x2-y2*y2;
|
||||
if(t2 < 0.0f) n2 = 0.0f;
|
||||
else {
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * grad2(perm[ii+1+perm[jj+1]], x2, y2);
|
||||
}
|
||||
|
||||
/* Add contributions from each corner to get the final noise value. */
|
||||
/* The result is scaled to return values in the interval [-1,1]. */
|
||||
return 40.0f * (n0 + n1 + n2); /* TODO: The scale factor is preliminary! */
|
||||
}
|
||||
|
||||
/* 3D simplex noise */
|
||||
GLfloat _slang_library_noise3 (GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
/* Simple skewing factors for the 3D case */
|
||||
#define F3 0.333333333f
|
||||
#define G3 0.166666667f
|
||||
|
||||
float n0, n1, n2, n3; /* Noise contributions from the four corners */
|
||||
|
||||
/* Skew the input space to determine which simplex cell we're in */
|
||||
float s = (x+y+z)*F3; /* Very nice and simple skew factor for 3D */
|
||||
float xs = x+s;
|
||||
float ys = y+s;
|
||||
float zs = z+s;
|
||||
int i = FASTFLOOR(xs);
|
||||
int j = FASTFLOOR(ys);
|
||||
int k = FASTFLOOR(zs);
|
||||
|
||||
float t = (float)(i+j+k)*G3;
|
||||
float X0 = i-t; /* Unskew the cell origin back to (x,y,z) space */
|
||||
float Y0 = j-t;
|
||||
float Z0 = k-t;
|
||||
float x0 = x-X0; /* The x,y,z distances from the cell origin */
|
||||
float y0 = y-Y0;
|
||||
float z0 = z-Z0;
|
||||
|
||||
float x1, y1, z1, x2, y2, z2, x3, y3, z3;
|
||||
int ii, jj, kk;
|
||||
float t0, t1, t2, t3;
|
||||
|
||||
/* For the 3D case, the simplex shape is a slightly irregular tetrahedron. */
|
||||
/* Determine which simplex we are in. */
|
||||
int i1, j1, k1; /* Offsets for second corner of simplex in (i,j,k) coords */
|
||||
int i2, j2, k2; /* Offsets for third corner of simplex in (i,j,k) coords */
|
||||
|
||||
/* This code would benefit from a backport from the GLSL version! */
|
||||
if(x0>=y0) {
|
||||
if(y0>=z0)
|
||||
{ i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } /* X Y Z order */
|
||||
else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } /* X Z Y order */
|
||||
else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } /* Z X Y order */
|
||||
}
|
||||
else { /* x0<y0 */
|
||||
if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } /* Z Y X order */
|
||||
else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } /* Y Z X order */
|
||||
else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } /* Y X Z order */
|
||||
}
|
||||
|
||||
/* A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), */
|
||||
/* a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and */
|
||||
/* a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where */
|
||||
/* c = 1/6. */
|
||||
|
||||
x1 = x0 - i1 + G3; /* Offsets for second corner in (x,y,z) coords */
|
||||
y1 = y0 - j1 + G3;
|
||||
z1 = z0 - k1 + G3;
|
||||
x2 = x0 - i2 + 2.0f*G3; /* Offsets for third corner in (x,y,z) coords */
|
||||
y2 = y0 - j2 + 2.0f*G3;
|
||||
z2 = z0 - k2 + 2.0f*G3;
|
||||
x3 = x0 - 1.0f + 3.0f*G3; /* Offsets for last corner in (x,y,z) coords */
|
||||
y3 = y0 - 1.0f + 3.0f*G3;
|
||||
z3 = z0 - 1.0f + 3.0f*G3;
|
||||
|
||||
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
|
||||
ii = i % 256;
|
||||
jj = j % 256;
|
||||
kk = k % 256;
|
||||
|
||||
/* Calculate the contribution from the four corners */
|
||||
t0 = 0.6f - x0*x0 - y0*y0 - z0*z0;
|
||||
if(t0 < 0.0f) n0 = 0.0f;
|
||||
else {
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad3(perm[ii+perm[jj+perm[kk]]], x0, y0, z0);
|
||||
}
|
||||
|
||||
t1 = 0.6f - x1*x1 - y1*y1 - z1*z1;
|
||||
if(t1 < 0.0f) n1 = 0.0f;
|
||||
else {
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * grad3(perm[ii+i1+perm[jj+j1+perm[kk+k1]]], x1, y1, z1);
|
||||
}
|
||||
|
||||
t2 = 0.6f - x2*x2 - y2*y2 - z2*z2;
|
||||
if(t2 < 0.0f) n2 = 0.0f;
|
||||
else {
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * grad3(perm[ii+i2+perm[jj+j2+perm[kk+k2]]], x2, y2, z2);
|
||||
}
|
||||
|
||||
t3 = 0.6f - x3*x3 - y3*y3 - z3*z3;
|
||||
if(t3<0.0f) n3 = 0.0f;
|
||||
else {
|
||||
t3 *= t3;
|
||||
n3 = t3 * t3 * grad3(perm[ii+1+perm[jj+1+perm[kk+1]]], x3, y3, z3);
|
||||
}
|
||||
|
||||
/* Add contributions from each corner to get the final noise value. */
|
||||
/* The result is scaled to stay just inside [-1,1] */
|
||||
return 32.0f * (n0 + n1 + n2 + n3); /* TODO: The scale factor is preliminary! */
|
||||
}
|
||||
|
||||
/* 4D simplex noise */
|
||||
GLfloat _slang_library_noise4 (GLfloat x, GLfloat y, GLfloat z, GLfloat w)
|
||||
{
|
||||
/* The skewing and unskewing factors are hairy again for the 4D case */
|
||||
#define F4 0.309016994f /* F4 = (Math.sqrt(5.0)-1.0)/4.0 */
|
||||
#define G4 0.138196601f /* G4 = (5.0-Math.sqrt(5.0))/20.0 */
|
||||
|
||||
float n0, n1, n2, n3, n4; /* Noise contributions from the five corners */
|
||||
|
||||
/* Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in */
|
||||
float s = (x + y + z + w) * F4; /* Factor for 4D skewing */
|
||||
float xs = x + s;
|
||||
float ys = y + s;
|
||||
float zs = z + s;
|
||||
float ws = w + s;
|
||||
int i = FASTFLOOR(xs);
|
||||
int j = FASTFLOOR(ys);
|
||||
int k = FASTFLOOR(zs);
|
||||
int l = FASTFLOOR(ws);
|
||||
|
||||
float t = (i + j + k + l) * G4; /* Factor for 4D unskewing */
|
||||
float X0 = i - t; /* Unskew the cell origin back to (x,y,z,w) space */
|
||||
float Y0 = j - t;
|
||||
float Z0 = k - t;
|
||||
float W0 = l - t;
|
||||
|
||||
float x0 = x - X0; /* The x,y,z,w distances from the cell origin */
|
||||
float y0 = y - Y0;
|
||||
float z0 = z - Z0;
|
||||
float w0 = w - W0;
|
||||
|
||||
/* For the 4D case, the simplex is a 4D shape I won't even try to describe. */
|
||||
/* To find out which of the 24 possible simplices we're in, we need to */
|
||||
/* determine the magnitude ordering of x0, y0, z0 and w0. */
|
||||
/* The method below is a good way of finding the ordering of x,y,z,w and */
|
||||
/* then find the correct traversal order for the simplex we’re in. */
|
||||
/* First, six pair-wise comparisons are performed between each possible pair */
|
||||
/* of the four coordinates, and the results are used to add up binary bits */
|
||||
/* for an integer index. */
|
||||
int c1 = (x0 > y0) ? 32 : 0;
|
||||
int c2 = (x0 > z0) ? 16 : 0;
|
||||
int c3 = (y0 > z0) ? 8 : 0;
|
||||
int c4 = (x0 > w0) ? 4 : 0;
|
||||
int c5 = (y0 > w0) ? 2 : 0;
|
||||
int c6 = (z0 > w0) ? 1 : 0;
|
||||
int c = c1 + c2 + c3 + c4 + c5 + c6;
|
||||
|
||||
int i1, j1, k1, l1; /* The integer offsets for the second simplex corner */
|
||||
int i2, j2, k2, l2; /* The integer offsets for the third simplex corner */
|
||||
int i3, j3, k3, l3; /* The integer offsets for the fourth simplex corner */
|
||||
|
||||
float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
|
||||
int ii, jj, kk, ll;
|
||||
float t0, t1, t2, t3, t4;
|
||||
|
||||
/* simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. */
|
||||
/* Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w */
|
||||
/* impossible. Only the 24 indices which have non-zero entries make any sense. */
|
||||
/* We use a thresholding to set the coordinates in turn from the largest magnitude. */
|
||||
/* The number 3 in the "simplex" array is at the position of the largest coordinate. */
|
||||
i1 = simplex[c][0]>=3 ? 1 : 0;
|
||||
j1 = simplex[c][1]>=3 ? 1 : 0;
|
||||
k1 = simplex[c][2]>=3 ? 1 : 0;
|
||||
l1 = simplex[c][3]>=3 ? 1 : 0;
|
||||
/* The number 2 in the "simplex" array is at the second largest coordinate. */
|
||||
i2 = simplex[c][0]>=2 ? 1 : 0;
|
||||
j2 = simplex[c][1]>=2 ? 1 : 0;
|
||||
k2 = simplex[c][2]>=2 ? 1 : 0;
|
||||
l2 = simplex[c][3]>=2 ? 1 : 0;
|
||||
/* The number 1 in the "simplex" array is at the second smallest coordinate. */
|
||||
i3 = simplex[c][0]>=1 ? 1 : 0;
|
||||
j3 = simplex[c][1]>=1 ? 1 : 0;
|
||||
k3 = simplex[c][2]>=1 ? 1 : 0;
|
||||
l3 = simplex[c][3]>=1 ? 1 : 0;
|
||||
/* The fifth corner has all coordinate offsets = 1, so no need to look that up. */
|
||||
|
||||
x1 = x0 - i1 + G4; /* Offsets for second corner in (x,y,z,w) coords */
|
||||
y1 = y0 - j1 + G4;
|
||||
z1 = z0 - k1 + G4;
|
||||
w1 = w0 - l1 + G4;
|
||||
x2 = x0 - i2 + 2.0f*G4; /* Offsets for third corner in (x,y,z,w) coords */
|
||||
y2 = y0 - j2 + 2.0f*G4;
|
||||
z2 = z0 - k2 + 2.0f*G4;
|
||||
w2 = w0 - l2 + 2.0f*G4;
|
||||
x3 = x0 - i3 + 3.0f*G4; /* Offsets for fourth corner in (x,y,z,w) coords */
|
||||
y3 = y0 - j3 + 3.0f*G4;
|
||||
z3 = z0 - k3 + 3.0f*G4;
|
||||
w3 = w0 - l3 + 3.0f*G4;
|
||||
x4 = x0 - 1.0f + 4.0f*G4; /* Offsets for last corner in (x,y,z,w) coords */
|
||||
y4 = y0 - 1.0f + 4.0f*G4;
|
||||
z4 = z0 - 1.0f + 4.0f*G4;
|
||||
w4 = w0 - 1.0f + 4.0f*G4;
|
||||
|
||||
/* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
|
||||
ii = i % 256;
|
||||
jj = j % 256;
|
||||
kk = k % 256;
|
||||
ll = l % 256;
|
||||
|
||||
/* Calculate the contribution from the five corners */
|
||||
t0 = 0.6f - x0*x0 - y0*y0 - z0*z0 - w0*w0;
|
||||
if(t0 < 0.0f) n0 = 0.0f;
|
||||
else {
|
||||
t0 *= t0;
|
||||
n0 = t0 * t0 * grad4(perm[ii+perm[jj+perm[kk+perm[ll]]]], x0, y0, z0, w0);
|
||||
}
|
||||
|
||||
t1 = 0.6f - x1*x1 - y1*y1 - z1*z1 - w1*w1;
|
||||
if(t1 < 0.0f) n1 = 0.0f;
|
||||
else {
|
||||
t1 *= t1;
|
||||
n1 = t1 * t1 * grad4(perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]], x1, y1, z1, w1);
|
||||
}
|
||||
|
||||
t2 = 0.6f - x2*x2 - y2*y2 - z2*z2 - w2*w2;
|
||||
if(t2 < 0.0f) n2 = 0.0f;
|
||||
else {
|
||||
t2 *= t2;
|
||||
n2 = t2 * t2 * grad4(perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]], x2, y2, z2, w2);
|
||||
}
|
||||
|
||||
t3 = 0.6f - x3*x3 - y3*y3 - z3*z3 - w3*w3;
|
||||
if(t3 < 0.0f) n3 = 0.0f;
|
||||
else {
|
||||
t3 *= t3;
|
||||
n3 = t3 * t3 * grad4(perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]], x3, y3, z3, w3);
|
||||
}
|
||||
|
||||
t4 = 0.6f - x4*x4 - y4*y4 - z4*z4 - w4*w4;
|
||||
if(t4 < 0.0f) n4 = 0.0f;
|
||||
else {
|
||||
t4 *= t4;
|
||||
n4 = t4 * t4 * grad4(perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]], x4, y4, z4, w4);
|
||||
}
|
||||
|
||||
/* Sum up and scale the result to cover the range [-1,1] */
|
||||
return 27.0f * (n0 + n1 + n2 + n3 + n4); /* TODO: The scale factor is preliminary! */
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Mesa 3-D graphics library
|
||||
* Version: 6.5
|
||||
*
|
||||
* Copyright (C) 2006 Brian Paul All Rights Reserved.
|
||||
*
|
||||
* 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
|
||||
* BRIAN PAUL 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.
|
||||
*/
|
||||
|
||||
#if !defined SLANG_LIBRARY_NOISE_H
|
||||
#define SLANG_LIBRARY_NOISE_H
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
GLfloat _slang_library_noise1 (GLfloat);
|
||||
GLfloat _slang_library_noise2 (GLfloat, GLfloat);
|
||||
GLfloat _slang_library_noise3 (GLfloat, GLfloat, GLfloat);
|
||||
GLfloat _slang_library_noise4 (GLfloat, GLfloat, GLfloat, GLfloat);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -36,15 +36,15 @@
|
|||
|
||||
/* slang_storage_array */
|
||||
|
||||
int slang_storage_array_construct (slang_storage_array *arr)
|
||||
GLboolean slang_storage_array_construct (slang_storage_array *arr)
|
||||
{
|
||||
arr->type = slang_stor_aggregate;
|
||||
arr->aggregate = NULL;
|
||||
arr->length = 0;
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
void slang_storage_array_destruct (slang_storage_array *arr)
|
||||
GLvoid slang_storage_array_destruct (slang_storage_array *arr)
|
||||
{
|
||||
if (arr->aggregate != NULL)
|
||||
{
|
||||
|
@ -55,16 +55,16 @@ void slang_storage_array_destruct (slang_storage_array *arr)
|
|||
|
||||
/* slang_storage_aggregate */
|
||||
|
||||
int slang_storage_aggregate_construct (slang_storage_aggregate *agg)
|
||||
GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *agg)
|
||||
{
|
||||
agg->arrays = NULL;
|
||||
agg->count = 0;
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
void slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
|
||||
GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
|
||||
{
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
for (i = 0; i < agg->count; i++)
|
||||
slang_storage_array_destruct (agg->arrays + i);
|
||||
|
@ -74,6 +74,7 @@ void slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
|
|||
static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggregate *agg)
|
||||
{
|
||||
slang_storage_array *arr = NULL;
|
||||
|
||||
agg->arrays = (slang_storage_array *) slang_alloc_realloc (agg->arrays, agg->count * sizeof (
|
||||
slang_storage_array), (agg->count + 1) * sizeof (slang_storage_array));
|
||||
if (agg->arrays != NULL)
|
||||
|
@ -88,88 +89,91 @@ static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggr
|
|||
|
||||
/* _slang_aggregate_variable() */
|
||||
|
||||
static int aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type,
|
||||
unsigned int row_count)
|
||||
static GLboolean aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type,
|
||||
GLuint row_count)
|
||||
{
|
||||
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
|
||||
if (arr == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
arr->type = basic_type;
|
||||
arr->length = row_count;
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
|
||||
unsigned int dimension)
|
||||
static GLboolean aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
|
||||
GLuint dimension)
|
||||
{
|
||||
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
|
||||
if (arr == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
arr->type = slang_stor_aggregate;
|
||||
arr->length = dimension;
|
||||
arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (
|
||||
slang_storage_aggregate));
|
||||
arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate));
|
||||
if (arr->aggregate == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_storage_aggregate_construct (arr->aggregate))
|
||||
{
|
||||
slang_alloc_free (arr->aggregate);
|
||||
arr->aggregate = NULL;
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
if (!aggregate_vector (arr->aggregate, basic_type, dimension))
|
||||
return 0;
|
||||
return 1;
|
||||
return GL_FALSE;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
static int aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
|
||||
static GLboolean aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
|
||||
slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals,
|
||||
slang_machine *mach, slang_assembly_file *file, slang_atom_pool *atoms)
|
||||
{
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
for (i = 0; i < vars->num_variables; i++)
|
||||
if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier,
|
||||
vars->variables[i].array_size, funcs, structs, globals, mach, file, atoms))
|
||||
return 0;
|
||||
return 1;
|
||||
return GL_FALSE;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,
|
||||
static GLboolean eval_array_size (slang_assembly_file *file, slang_machine *pmach,
|
||||
slang_assembly_name_space *space, slang_operation *array_size, GLuint *plength,
|
||||
slang_atom_pool *atoms)
|
||||
{
|
||||
slang_assembly_file_restore_point point;
|
||||
slang_assembly_local_info info;
|
||||
slang_assembly_flow_control flow;
|
||||
slang_assembly_stack_info stk;
|
||||
slang_machine mach;
|
||||
slang_assemble_ctx A;
|
||||
|
||||
A.file = file;
|
||||
A.mach = pmach;
|
||||
A.atoms = atoms;
|
||||
A.space = *space;
|
||||
A.local.ret_size = 0;
|
||||
A.local.addr_tmp = 0;
|
||||
A.local.swizzle_tmp = 4;
|
||||
|
||||
/* save the current assembly */
|
||||
if (!slang_assembly_file_restore_point_save (file, &point))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* setup the machine */
|
||||
mach = *pmach;
|
||||
mach.ip = file->count;
|
||||
|
||||
/* allocate local storage for expression */
|
||||
info.ret_size = 0;
|
||||
info.addr_tmp = 0;
|
||||
info.swizzle_tmp = 4;
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_local_alloc, 20))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push_label (file, slang_asm_enter, 20))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* insert the actual expression */
|
||||
if (!_slang_assemble_operation (file, array_size, 0, &flow, space, &info, &stk, pmach, atoms))
|
||||
return 0;
|
||||
if (!_slang_assemble_operation_ (&A, array_size, slang_ref_forbid))
|
||||
return GL_FALSE;
|
||||
if (!slang_assembly_file_push (file, slang_asm_exit))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* execute the expression */
|
||||
if (!_slang_execute2 (file, &mach))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
|
||||
/* the evaluated expression is on top of the stack */
|
||||
*plength = (GLuint) mach.mem[mach.sp + SLANG_MACHINE_GLOBAL_SIZE]._float;
|
||||
|
@ -177,11 +181,12 @@ static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,
|
|||
|
||||
/* restore the old assembly */
|
||||
if (!slang_assembly_file_restore_point_load (file, &point))
|
||||
return 0;
|
||||
return 1;
|
||||
return GL_FALSE;
|
||||
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
|
||||
GLboolean _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
|
||||
slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs,
|
||||
slang_variable_scope *vars, slang_machine *mach, slang_assembly_file *file,
|
||||
slang_atom_pool *atoms)
|
||||
|
@ -235,42 +240,41 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
|
|||
|
||||
arr = slang_storage_aggregate_push_new (agg);
|
||||
if (arr == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
arr->type = slang_stor_aggregate;
|
||||
arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (
|
||||
slang_storage_aggregate));
|
||||
arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate));
|
||||
if (arr->aggregate == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
if (!slang_storage_aggregate_construct (arr->aggregate))
|
||||
{
|
||||
slang_alloc_free (arr->aggregate);
|
||||
arr->aggregate = NULL;
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs,
|
||||
vars, mach, file, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
space.funcs = funcs;
|
||||
space.structs = structs;
|
||||
space.vars = vars;
|
||||
if (!eval_array_size (file, mach, &space, array_size, &arr->length, atoms))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
default:
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* _slang_sizeof_aggregate() */
|
||||
|
||||
unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
|
||||
GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
|
||||
{
|
||||
unsigned int i, size = 0;
|
||||
GLuint i, size = 0;
|
||||
|
||||
for (i = 0; i < agg->count; i++)
|
||||
{
|
||||
unsigned int element_size;
|
||||
GLuint element_size;
|
||||
|
||||
if (agg->arrays[i].type == slang_stor_aggregate)
|
||||
element_size = _slang_sizeof_aggregate (agg->arrays[i].aggregate);
|
||||
|
@ -283,20 +287,20 @@ unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
|
|||
|
||||
/* _slang_flatten_aggregate () */
|
||||
|
||||
int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
|
||||
GLboolean _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
|
||||
{
|
||||
unsigned int i;
|
||||
GLuint i;
|
||||
|
||||
for (i = 0; i < agg->count; i++)
|
||||
{
|
||||
unsigned int j;
|
||||
GLuint j;
|
||||
|
||||
for (j = 0; j < agg->arrays[i].length; j++)
|
||||
{
|
||||
if (agg->arrays[i].type == slang_stor_aggregate)
|
||||
{
|
||||
if (!_slang_flatten_aggregate (flat, agg->arrays[i].aggregate))
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -304,12 +308,12 @@ int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage
|
|||
|
||||
arr = slang_storage_aggregate_push_new (flat);
|
||||
if (arr == NULL)
|
||||
return 0;
|
||||
return GL_FALSE;
|
||||
arr->type = agg->arrays[i].type;
|
||||
arr->length = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,13 +32,13 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/*
|
||||
Program variable data storage is kept completely transparent to the front-end compiler. It is
|
||||
up to the back-end how the data is actually allocated. The slang_storage_type enum
|
||||
provides the basic information about how the memory is interpreted. This abstract piece
|
||||
of memory is called a data slot. A data slot of a particular type has a fixed size.
|
||||
|
||||
For now, only the three basic types are supported, that is bool, int and float. Other built-in
|
||||
types like vector or matrix can easily be decomposed into a series of basic types.
|
||||
* Program variable data storage is kept completely transparent to the front-end compiler. It is
|
||||
* up to the back-end how the data is actually allocated. The slang_storage_type enum
|
||||
* provides the basic information about how the memory is interpreted. This abstract piece
|
||||
* of memory is called a data slot. A data slot of a particular type has a fixed size.
|
||||
*
|
||||
* For now, only the three basic types are supported, that is bool, int and float. Other built-in
|
||||
* types like vector or matrix can easily be decomposed into a series of basic types.
|
||||
*/
|
||||
typedef enum slang_storage_type_
|
||||
{
|
||||
|
@ -49,59 +49,59 @@ typedef enum slang_storage_type_
|
|||
} slang_storage_type;
|
||||
|
||||
/*
|
||||
The slang_storage_array structure groups data slots of the same type into an array. This
|
||||
array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
|
||||
elements. They are also required to support indirect addressing. That is, if B references
|
||||
first data slot in the array, S is the size of the data slot and I is the integral index that
|
||||
is not known at compile time, B+I*S references I-th data slot.
|
||||
|
||||
This structure is also used to break down built-in data types that are not supported directly.
|
||||
Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
|
||||
an array of column vectors, which are in turn processed as other vectors.
|
||||
* The slang_storage_array structure groups data slots of the same type into an array. This
|
||||
* array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
|
||||
* elements. They are also required to support indirect addressing. That is, if B references
|
||||
* first data slot in the array, S is the size of the data slot and I is the integral index that
|
||||
* is not known at compile time, B+I*S references I-th data slot.
|
||||
*
|
||||
* This structure is also used to break down built-in data types that are not supported directly.
|
||||
* Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
|
||||
* an array of column vectors, which are in turn processed as other vectors.
|
||||
*/
|
||||
typedef struct slang_storage_array_
|
||||
{
|
||||
slang_storage_type type;
|
||||
struct slang_storage_aggregate_ *aggregate; /* slang_stor_aggregate */
|
||||
unsigned int length;
|
||||
GLuint length;
|
||||
} slang_storage_array;
|
||||
|
||||
int slang_storage_array_construct (slang_storage_array *);
|
||||
void slang_storage_array_destruct (slang_storage_array *);
|
||||
GLboolean slang_storage_array_construct (slang_storage_array *);
|
||||
GLvoid slang_storage_array_destruct (slang_storage_array *);
|
||||
|
||||
/*
|
||||
The slang_storage_aggregate structure relaxes the indirect addressing requirement for
|
||||
slang_storage_array structure. Aggregates are always accessed statically - its member
|
||||
addresses are well-known at compile time. For example, user-defined types are implemented as
|
||||
aggregates. Aggregates can collect data of a different type.
|
||||
* The slang_storage_aggregate structure relaxes the indirect addressing requirement for
|
||||
* slang_storage_array structure. Aggregates are always accessed statically - its member
|
||||
* addresses are well-known at compile time. For example, user-defined types are implemented as
|
||||
* aggregates. Aggregates can collect data of a different type.
|
||||
*/
|
||||
typedef struct slang_storage_aggregate_
|
||||
{
|
||||
slang_storage_array *arrays;
|
||||
unsigned int count;
|
||||
GLuint count;
|
||||
} slang_storage_aggregate;
|
||||
|
||||
int slang_storage_aggregate_construct (slang_storage_aggregate *);
|
||||
void slang_storage_aggregate_destruct (slang_storage_aggregate *);
|
||||
GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *);
|
||||
GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *);
|
||||
|
||||
int _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
|
||||
GLboolean _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
|
||||
struct slang_operation_ *, struct slang_function_scope_ *, slang_struct_scope *,
|
||||
slang_variable_scope *, struct slang_machine_ *, struct slang_assembly_file_ *,
|
||||
slang_atom_pool *);
|
||||
|
||||
/*
|
||||
returns total size (in machine units) of the given aggregate
|
||||
returns 0 on error
|
||||
* Returns total size (in machine units) of the given aggregate.
|
||||
* Returns 0 on error.
|
||||
*/
|
||||
unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *);
|
||||
GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *);
|
||||
|
||||
/*
|
||||
converts structured aggregate to a flat one, with arrays of generic type being
|
||||
one-element long
|
||||
returns 1 on success
|
||||
returns 0 otherwise
|
||||
* Converts structured aggregate to a flat one, with arrays of generic type being
|
||||
* one-element long.
|
||||
* Returns GL_TRUE on success.
|
||||
* Returns GL_FALSE otherwise.
|
||||
*/
|
||||
int _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
|
||||
GLboolean _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -200,6 +200,7 @@ SLANG_SOURCES = \
|
|||
shader/slang/slang_compile_struct.c \
|
||||
shader/slang/slang_compile_variable.c \
|
||||
shader/slang/slang_execute.c \
|
||||
shader/slang/slang_library_noise.c \
|
||||
shader/slang/slang_preprocess.c \
|
||||
shader/slang/slang_storage.c \
|
||||
shader/slang/slang_utility.c
|
||||
|
|
|
@ -176,11 +176,41 @@ static void fetch_output_vec4 (const char *name, GLuint attr, GLuint i, GLuint i
|
|||
_mesa_memcpy (&store->outputs[attr].data[i], vec, 16);
|
||||
}
|
||||
|
||||
static void fetch_uniform_mat4 (const char *name, const GLmatrix *matrix, GLuint index,
|
||||
static void fetch_uniform_mat4 (const char *name, GLmatrix *matrix, GLuint index,
|
||||
struct gl2_vertex_shader_intf **vs)
|
||||
{
|
||||
/* XXX: transpose? */
|
||||
GLuint len;
|
||||
GLfloat mat[16];
|
||||
char buffer[64];
|
||||
|
||||
_mesa_strcpy (buffer, name);
|
||||
len = _mesa_strlen (name);
|
||||
|
||||
/* we want inverse matrix */
|
||||
if (!matrix->inv)
|
||||
{
|
||||
/* allocate inverse matrix and make it dirty */
|
||||
_math_matrix_alloc_inv (matrix);
|
||||
_math_matrix_loadf (matrix, matrix->m);
|
||||
}
|
||||
_math_matrix_analyse (matrix);
|
||||
|
||||
/* identity */
|
||||
_slang_fetch_mat4 (vs, name, matrix->m, index, 1);
|
||||
|
||||
/* transpose */
|
||||
_mesa_strcpy (buffer + len, "Transpose");
|
||||
_math_transposef (mat, matrix->m);
|
||||
_slang_fetch_mat4 (vs, buffer, mat, index, 1);
|
||||
|
||||
/* inverse */
|
||||
_mesa_strcpy (buffer + len, "Inverse");
|
||||
_slang_fetch_mat4 (vs, buffer, matrix->inv, index, 1);
|
||||
|
||||
/* inverse transpose */
|
||||
_mesa_strcpy (buffer + len, "InverseTranspose");
|
||||
_math_transposef (mat, matrix->inv);
|
||||
_slang_fetch_mat4 (vs, buffer, mat, index, 1);
|
||||
}
|
||||
|
||||
static void fetch_normal_matrix (const char *name, GLmatrix *matrix,
|
||||
|
@ -189,14 +219,16 @@ static void fetch_normal_matrix (const char *name, GLmatrix *matrix,
|
|||
GLfloat mat[9];
|
||||
|
||||
_math_matrix_analyse (matrix);
|
||||
|
||||
/* inverse transpose */
|
||||
mat[0] = matrix->inv[0];
|
||||
mat[1] = matrix->inv[1];
|
||||
mat[2] = matrix->inv[2];
|
||||
mat[3] = matrix->inv[4];
|
||||
mat[1] = matrix->inv[4];
|
||||
mat[2] = matrix->inv[8];
|
||||
mat[3] = matrix->inv[1];
|
||||
mat[4] = matrix->inv[5];
|
||||
mat[5] = matrix->inv[6];
|
||||
mat[6] = matrix->inv[8];
|
||||
mat[7] = matrix->inv[9];
|
||||
mat[5] = matrix->inv[9];
|
||||
mat[6] = matrix->inv[2];
|
||||
mat[7] = matrix->inv[6];
|
||||
mat[8] = matrix->inv[10];
|
||||
_slang_fetch_mat3 (vs, name, mat, 0, 1);
|
||||
}
|
||||
|
@ -238,18 +270,6 @@ static GLboolean run_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stag
|
|||
for (j = 0; j < 8; j++)
|
||||
fetch_uniform_mat4 ("gl_TextureMatrix", ctx->TextureMatrixStack[j].Top, j, vs);
|
||||
fetch_normal_matrix ("gl_NormalMatrix", ctx->ModelviewMatrixStack.Top, vs);
|
||||
/* XXX: fetch uniform mat4 gl_ModelViewMatrixInverse */
|
||||
/* XXX: fetch uniform mat4 gl_ProjectionMatrixInverse */
|
||||
/* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverse */
|
||||
/* XXX: fetch uniform mat4 gl_TextureMatrixInverse */
|
||||
/* XXX: fetch uniform mat4 gl_ModelViewMatrixTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_ProjectionMatrixTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_TextureMatrixTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_ModelViewMatrixInverseTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_ProjectionMatrixInverseTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose */
|
||||
/* XXX: fetch uniform mat4 gl_TextureMatrixInverseTranspose */
|
||||
/* XXX: fetch uniform float gl_NormalScale */
|
||||
/* XXX: fetch uniform mat4 gl_ClipPlane */
|
||||
/* XXX: fetch uniform mat4 gl_TextureEnvColor */
|
||||
|
|
|
@ -522,6 +522,10 @@ SOURCE=..\..\..\..\src\mesa\shader\slang\slang_execute.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\src\mesa\shader\slang\slang_library_noise.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\src\mesa\shader\slang\slang_preprocess.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -1227,6 +1231,10 @@ SOURCE=..\..\..\..\src\mesa\shader\slang\slang_execute.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\src\mesa\shader\slang\slang_library_noise.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\src\mesa\shader\slang\slang_mesa.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
Loading…
Reference in New Issue