factor/extra/gpu/util/util.factor

135 lines
3.6 KiB
Factor
Raw Normal View History

2009-07-19 15:31:10 -04:00
! (c)2009 Joe Groff bsd license
2010-04-05 04:38:39 -04:00
USING: accessors arrays gpu.buffers gpu.framebuffers gpu.render
gpu.shaders gpu.textures images kernel locals opengl.framebuffers
specialized-arrays ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: float
2009-07-19 15:31:10 -04:00
IN: gpu.util
CONSTANT: environment-cube-map-mv-matrices
H{
{ +X {
{ 0.0 0.0 -1.0 0.0 }
{ 0.0 -1.0 0.0 0.0 }
{ -1.0 0.0 0.0 0.0 }
{ 0.0 0.0 0.0 1.0 }
} }
{ +Y {
{ 1.0 0.0 0.0 0.0 }
{ 0.0 0.0 1.0 0.0 }
{ 0.0 -1.0 0.0 0.0 }
{ 0.0 0.0 0.0 1.0 }
} }
{ +Z {
{ 1.0 0.0 0.0 0.0 }
{ 0.0 -1.0 0.0 0.0 }
{ 0.0 0.0 -1.0 0.0 }
{ 0.0 0.0 0.0 1.0 }
} }
{ -X {
{ 0.0 0.0 1.0 0.0 }
{ 0.0 -1.0 0.0 0.0 }
{ 1.0 0.0 0.0 0.0 }
{ 0.0 0.0 0.0 1.0 }
} }
{ -Y {
{ 1.0 0.0 0.0 0.0 }
{ 0.0 0.0 -1.0 0.0 }
{ 0.0 1.0 0.0 0.0 }
{ 0.0 0.0 0.0 1.0 }
} }
{ -Z {
{ -1.0 0.0 0.0 0.0 }
{ 0.0 -1.0 0.0 0.0 }
{ 0.0 0.0 1.0 0.0 }
{ 0.0 0.0 0.0 1.0 }
} }
}
2010-04-04 21:57:58 -04:00
GLSL-SHADER: window-vertex-shader vertex-shader
attribute vec2 vertex;
varying vec2 texcoord;
void main()
{
texcoord = vertex * vec2(0.5) + vec2(0.5);
gl_Position = vec4(vertex, 0.0, 1.0);
}
;
2009-07-19 15:31:10 -04:00
2010-04-04 21:57:58 -04:00
GLSL-SHADER: window-fragment-shader fragment-shader
uniform sampler2D texture;
varying vec2 texcoord;
void main()
{
gl_FragColor = texture2D(texture, texcoord);
}
;
VERTEX-FORMAT: window-vertex-format
2009-07-19 15:31:10 -04:00
{ "vertex" float-components 2 f } ;
2010-04-04 21:57:58 -04:00
UNIFORM-TUPLE: window-uniforms
{ "texture" texture-uniform f } ;
GLSL-PROGRAM: window-program window-vertex-shader window-fragment-shader window-vertex-format ;
GLSL-SHADER: window-point-vertex-shader vertex-shader
uniform float point_size;
attribute vec2 vertex;
void main()
{
gl_Position = vec4(vertex, 0.0, 1.0);
gl_PointSize = point_size;
}
;
GLSL-SHADER: window-point-fragment-shader fragment-shader
2010-04-05 04:38:39 -04:00
#version 120
2010-04-04 21:57:58 -04:00
uniform sampler2D texture;
void main()
{
gl_FragColor = texture2D(texture, gl_PointCoord);
}
;
UNIFORM-TUPLE: window-point-uniforms
{ "texture" texture-uniform f }
{ "point_size" float-uniform f } ;
GLSL-PROGRAM: window-point-program window-point-vertex-shader window-point-fragment-shader window-vertex-format ;
2009-07-19 15:31:10 -04:00
CONSTANT: window-vertexes
float-array{
-1.0 -1.0
-1.0 1.0
1.0 -1.0
1.0 1.0
}
: <window-vertex-buffer> ( -- buffer )
window-vertexes
static-upload draw-usage vertex-buffer
2010-01-15 17:03:15 -05:00
byte-array>buffer ; inline
2009-07-19 15:31:10 -04:00
: <window-vertex-array> ( program-instance -- vertex-array )
2010-04-04 21:57:58 -04:00
[ <window-vertex-buffer> ] dip window-vertex-format <vertex-array*> ; inline
:: <2d-render-texture> ( dim order type -- renderbuffer texture )
2010-04-05 04:38:39 -04:00
order type
T{ texture-parameters
{ wrap clamp-texcoord-to-edge }
{ min-filter filter-linear }
{ min-mipmap-filter f } }
<texture-2d> [
0 <texture-2d-attachment> 1array f f dim <framebuffer>
dup { { default-attachment { 0 0 0 } } } clear-framebuffer
] keep ;
2010-04-04 21:57:58 -04:00
: draw-texture ( texture -- )
{
{ "primitive-mode" [ drop triangle-strip-mode ] }
{ "uniforms" [ window-uniforms boa ] }
{ "vertex-array" [ drop <window-vertex-buffer> window-program <program-instance> <vertex-array> ] }
{ "indexes" [ drop T{ index-range f 0 4 } ] }
} <render-set> render ;