From 08768d0e2f233281b0aaa32846bb4d3d2691eab6 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 18 Oct 2009 18:31:38 -0500 Subject: [PATCH] gpu.render: factor out and make public a "bind-uniforms" word for binding a uniform-tuple to a program-instance independent of a render-set --- extra/gpu/render/render-docs.factor | 5 +++++ extra/gpu/render/render.factor | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/extra/gpu/render/render-docs.factor b/extra/gpu/render/render-docs.factor index fdaa510e02..629a3ad662 100755 --- a/extra/gpu/render/render-docs.factor +++ b/extra/gpu/render/render-docs.factor @@ -226,6 +226,11 @@ HELP: render-set } } { $notes "User-created framebuffers require OpenGL 3.0 or one of the " { $snippet "GL_EXT_framebuffer_object" } " or " { $snippet "GL_ARB_framebuffer_object" } " extensions. Disabling rasterization requires OpenGL 3.0 or the " { $snippet "GL_EXT_transform_feedback" } " extension. Named output-attachment values are available in GLSL 1.30 or later, and GLSL 1.20 and earlier using the " { $snippet "GL_EXT_gpu_shader4" } " extension. Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ; +HELP: bind-uniforms +{ $values { "program-instance" program-instance } { "uniforms" uniform-tuple } } +{ $description "Binds the uniform shader parameters for " { $snippet "program-instance" } " using values from the given uniform tuple." } +{ $notes "The " { $link render } " word uses this word. Calling this word directly is only necessary if uniform parameters need to be bound independently of a " { $snippet "render" } " operation." } ; + { render render-set } related-words HELP: texture-uniform diff --git a/extra/gpu/render/render.factor b/extra/gpu/render/render.factor index 4f2437c0c1..5f92cf3dbf 100644 --- a/extra/gpu/render/render.factor +++ b/extra/gpu/render/render.factor @@ -168,12 +168,12 @@ M: multi-index-elements render-vertex-indexes : (bind-texture-unit) ( texture texture-unit -- ) swap [ GL_TEXTURE0 + glActiveTexture ] [ bind-texture drop ] bi* ; inline -GENERIC: bind-uniform-textures ( program-instance uniform-tuple -- ) -GENERIC: bind-uniforms ( program-instance uniform-tuple -- ) +GENERIC: (bind-uniform-textures) ( program-instance uniform-tuple -- ) +GENERIC: (bind-uniforms) ( program-instance uniform-tuple -- ) -M: uniform-tuple bind-uniform-textures +M: uniform-tuple (bind-uniform-textures) 2drop ; -M: uniform-tuple bind-uniforms +M: uniform-tuple (bind-uniforms) 2drop ; : uniform-slot-type ( uniform -- type ) @@ -363,7 +363,7 @@ DEFER: [bind-uniform-tuple] :: [bind-uniforms] ( superclass uniforms -- quot ) superclass "uniform-tuple-texture-units" word-prop 0 or :> first-texture-unit - superclass \ bind-uniforms method :> next-method + superclass \ (bind-uniforms) method :> next-method first-texture-unit uniforms "" [bind-uniform-tuple] nip :> bind-quot { 2dup next-method } bind-quot [ ] append-as ; @@ -371,10 +371,10 @@ DEFER: [bind-uniform-tuple] : define-uniform-tuple-methods ( class superclass uniforms -- ) [ 2drop - [ \ bind-uniform-textures create-method-in ] + [ \ (bind-uniform-textures) create-method-in ] [ [bind-uniform-textures] ] bi define ] [ - [ \ bind-uniforms create-method-in ] 2dip + [ \ (bind-uniforms) create-method-in ] 2dip [bind-uniforms] define ] 3bi ; @@ -481,12 +481,15 @@ TUPLE: render-set : 3 ( x y z quot-assoc -- render-set ) render-set swap 3make-tuple ; inline +: bind-uniforms ( program-instance uniforms -- ) + [ (bind-uniform-textures) ] [ (bind-uniforms) ] 2bi ; inline + : render ( render-set -- ) { [ vertex-array>> program-instance>> handle>> glUseProgram ] [ [ vertex-array>> program-instance>> ] [ uniforms>> ] bi - [ bind-uniform-textures ] [ bind-uniforms ] 2bi + bind-uniforms ] [ framebuffer>>