Commit 3654193a authored by Michal Krol's avatar Michal Krol

More GLSL code.

- general constructors allowed;
- implement noise functions (from Stefan Gustavson - thanks!)
- cosmetic stuff.
parent e94be8d5
......@@ -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 <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);
......
/*
* 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));
......
......@@ -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
This diff is collapsed.
......@@ -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,