]> gitweb.factorcode.org Git - factor.git/blob - extra/gpu/render/render-docs.factor
Update some copyright headers to follow the current convention
[factor.git] / extra / gpu / render / render-docs.factor
1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.syntax byte-arrays classes
4 gpu.buffers gpu.framebuffers gpu.shaders gpu.textures help.markup
5 help.syntax images kernel math sequences
6 specialized-arrays strings ;
7 QUALIFIED-WITH: alien.c-types c
8 QUALIFIED-WITH: math m
9 SPECIALIZED-ARRAY: c:float
10 SPECIALIZED-ARRAY: int
11 SPECIALIZED-ARRAY: uint
12 SPECIALIZED-ARRAY: ulong
13 SPECIALIZED-ARRAY: void*
14 IN: gpu.render
15
16 HELP: <index-elements>
17 { $values
18     { "ptr" gpu-data-ptr } { "count" integer } { "index-type" index-type }
19     { "index-elements" index-elements }
20 }
21 { $description "Constructs an " { $link index-elements } " tuple." } ;
22
23 HELP: <index-range>
24 { $values
25     { "start" integer } { "count" integer }
26     { "index-range" index-range }
27 }
28 { $description "Constructs an " { $link index-range } " tuple." } ;
29
30 HELP: <multi-index-elements>
31 { $values
32     { "buffer" { $maybe buffer } } { "ptrs" "an " { $link uint-array } " or " { $link void*-array } } { "counts" uint-array } { "index-type" index-type }
33     { "multi-index-elements" multi-index-elements }
34 }
35 { $description "Constructs a " { $link multi-index-elements } " tuple." } ;
36
37 HELP: <multi-index-range>
38 { $values
39     { "starts" uint-array } { "counts" uint-array }
40     { "multi-index-range" multi-index-range }
41 }
42 { $description "Constructs a " { $link multi-index-range } " tuple." } ;
43
44 HELP: UNIFORM-TUPLE:
45 { $syntax "UNIFORM-TUPLE: class-name
46     { \"slot\" uniform-type dimension }
47     { \"slot\" uniform-type dimension }
48     ...
49     { \"slot\" uniform-type dimension } ;" }
50 { $description "Defines a new " { $link uniform-tuple } " class. Tuples of the new class can be used as the " { $snippet "uniforms" } " slot of a " { $link render-set } " in order to set the uniform parameters of the active shader program. The " { $link uniform-type } " of each slot defines the component type, and the " { $snippet "dimension" } " specifies an array length if not " { $link f } "."
51 $nl
52 "Uniform parameters are passed from Factor to the shader program through the uniform tuple as follows:"
53 { $list
54 { { $link int-uniform } "s and " { $link uint-uniform } "s take their values from Factor " { $link integer } "s." }
55 { { $link float-uniform } "s take their values from Factor " { $link m:float } "s." }
56 { { $link bool-uniform } "s take their values from Factor " { $link boolean } "s." }
57 { { $link texture-uniform } "s take their values from " { $link texture } " objects." }
58 { "Vector uniforms take their values from Factor " { $link sequence } "s of the corresponding component type."
59     { $list
60     { "Float vector types: " { $link vec2-uniform } ", " { $link vec3-uniform } ", " { $link vec4-uniform } }
61     { "Integer vector types: " { $link ivec2-uniform } ", " { $link ivec3-uniform } ", " { $link ivec4-uniform } }
62     { "Unsigned integer vector types: " { $link uvec2-uniform } ", " { $link uvec3-uniform } ", " { $link uvec4-uniform } }
63     { "Boolean vector types: " { $link bvec2-uniform } ", " { $link bvec3-uniform } ", " { $link bvec4-uniform } }
64     }
65 }
66 { "Matrix uniforms take their values either from row-major Factor " { $link sequence } "s of sequences of floats, or from " { $link alien } "s or " { $link float-array } "s referencing packed column-major arrays of floats. Matrix types are:"
67     { $list
68     { { $link mat2-uniform } ", " { $link mat2x3-uniform } ", " { $link mat2x4-uniform } }
69     { { $link mat3x2-uniform } ", " { $link mat3-uniform } ", " { $link mat3x4-uniform } }
70     { { $link mat4x2-uniform } ", " { $link mat4x3-uniform } ", " { $link mat4-uniform } }
71     }
72 "Rectangular matrix type names are column x row."
73 }
74 { "Uniform slots can also be defined as other " { $snippet "uniform-tuple" } " types to bind uniform structures. The uniform structure will take its value from the slots of a tuple of the given type." }
75 { "Array uniforms are passed either as Factor sequences of the corresponding type specified above, or as " { $link alien } "s or " { $vocab-link "specialized-arrays" } " that reference pre-packed binary arrays of " { $link c:int } "s or " { $link c:float } "s." }
76 }
77 $nl
78 "A value of a uniform tuple type is a standard Factor tuple. Uniform tuples are constructed with " { $link new } " or " { $link boa } ", and values are placed inside them using standard slot accessors."
79 } ;
80
81 HELP: bool-uniform
82 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a boolean uniform parameter." } ;
83
84 HELP: bvec2-uniform
85 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component boolean vector uniform parameter." } ;
86
87 HELP: bvec3-uniform
88 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component boolean vector uniform parameter." } ;
89
90 HELP: bvec4-uniform
91 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component boolean vector uniform parameter." } ;
92
93 HELP: define-uniform-tuple
94 { $values
95     { "class" class } { "superclass" class } { "uniforms" sequence }
96 }
97 { $description "Defines a new " { $link uniform-tuple } " as a subclass of " { $snippet "superclass" } " with the slots specified by the " { $link uniform } " tuple values in " { $snippet "uniforms" } ". The runtime equivalent of " { $link POSTPONE: UNIFORM-TUPLE: } ". This word must be called inside a compilation unit." } ;
98
99 HELP: float-uniform
100 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a float uniform parameter." } ;
101
102 { index-elements index-range multi-index-elements multi-index-range } related-words
103
104 HELP: index-elements
105 { $class-description "Objects of this tuple class can be passed as the " { $snippet "indexes" } " slot of a " { $link render-set } " to instruct " { $link render } " to assemble primitives from the active " { $link vertex-array } " by using an array of indexes in CPU or GPU memory."
106 { $list
107 { "The " { $snippet "ptr" } " slot contains a " { $link byte-array } ", " { $link alien } ", or " { $link buffer-ptr } " value referencing the beginning of the index array." }
108 { "The " { $snippet "count" } " slot contains an " { $link integer } " value specifying the number of indexes to supply from the array." }
109 { "The " { $snippet "index-type" } " slot contains an " { $link index-type } " value specifying whether the array consists of " { $link ubyte-indexes } ", " { $link ushort-indexes } ", or " { $link uint-indexes } "." }
110 } } ;
111
112 HELP: index-range
113 { $class-description "Objects of this tuple class can be passed as the " { $snippet "indexes" } " slot of a " { $link render-set } " to instruct " { $link render } " to assemble primitives sequentially from a slice of the active " { $link vertex-array } "."
114 { $list
115 { "The " { $snippet "start" } " slot contains an " { $link integer } " value indicating the first element of the array to draw." }
116 { "The " { $snippet "count" } " slot contains an " { $link integer } " value indicating the number of elements to draw." }
117 } } ;
118
119 HELP: index-type
120 { $class-description "The " { $snippet "index-type" } " slot of an " { $link index-elements } " or " { $link multi-index-elements } " tuple indicates the type of the index array's elements: one-byte " { $link ubyte-indexes } ", two-byte " { $link ushort-indexes } ", or four-byte " { $link uint-indexes } "." } ;
121
122 { index-type ubyte-indexes ushort-indexes uint-indexes } related-words
123
124 HELP: int-uniform
125 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a signed integer uniform parameter." } ;
126
127 HELP: invalid-uniform-type
128 { $values
129     { "uniform" uniform }
130 }
131 { $description "Throws an error indicating that a slot of a " { $link uniform-tuple } " has been declared to have an invalid type." } ;
132
133 HELP: ivec2-uniform
134 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component integer vector uniform parameter." } ;
135
136 HELP: ivec3-uniform
137 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component integer vector uniform parameter." } ;
138
139 HELP: ivec4-uniform
140 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component integer vector uniform parameter." } ;
141
142 HELP: lines-mode
143 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to assemble a line from each pair of indexed vertex array elements." } ;
144
145 HELP: line-loop-mode
146 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to assemble a connected loop of lines from each consecutive pair of indexed vertex array elements, adding another line to close the last and first elements." } ;
147
148 HELP: line-strip-mode
149 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to assemble a connected strip of lines from each consecutive pair of indexed vertex array elements." } ;
150
151 HELP: mat2-uniform
152 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 2x2 square float matrix uniform parameter." } ;
153
154 HELP: mat2x3-uniform
155 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 2-column, 3-row float matrix uniform parameter." } ;
156
157 HELP: mat2x4-uniform
158 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 2-column, 4-row float matrix uniform parameter." } ;
159
160 HELP: mat3x2-uniform
161 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 3-column, 2-row float matrix uniform parameter." } ;
162
163 HELP: mat3-uniform
164 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 3x3 square float matrix uniform parameter." } ;
165
166 HELP: mat3x4-uniform
167 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 3-column, 4-row float matrix uniform parameter." } ;
168
169 HELP: mat4x2-uniform
170 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 4-column, 2-row float matrix uniform parameter." } ;
171
172 HELP: mat4x3-uniform
173 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 4-column, 3-row float matrix uniform parameter." } ;
174
175 HELP: mat4-uniform
176 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 4x4 square float matrix uniform parameter." } ;
177
178 HELP: multi-index-elements
179 { $class-description "Objects of this tuple class can be passed as the " { $snippet "indexes" } " slot of a non-instanced " { $link render-set } " to instruct " { $link render } " to assemble primitives from the active " { $link vertex-array } " by using multiple arrays of indexes in CPU or GPU memory."
180 { $list
181 { "The " { $snippet "buffer" } " slot contains either a " { $link buffer } " object to read indexes from, or " { $link f } " to read from CPU memory." }
182 { "The " { $snippet "ptrs" } " slot contains either a " { $link void*-array } " of pointers to the starts of index data, or a pointer-sized " { $link ulong-array } " of offsets into " { $snippet "buffer" } "." }
183 { "The " { $snippet "counts" } " slot contains a " { $link uint-array } " containing the number of indexes to read from each pointer or offset in " { $snippet "ptrs" } "." }
184 { "The " { $snippet "index-type" } " slot contains an " { $link index-type } " value specifying whether the arrays consist of " { $link ubyte-indexes } ", " { $link ushort-indexes } ", or " { $link uint-indexes } "." }
185 } } ;
186
187 HELP: multi-index-range
188 { $class-description "Objects of this tuple class can be passed as the " { $snippet "indexes" } " slot of a non-instanced " { $link render-set } " to instruct " { $link render } " to assemble primitives from the active " { $link vertex-array } " by using multiple consecutive slices of its elements."
189 { $list
190 { "The " { $snippet "starts" } " slot contains a " { $link uint-array } " of indexes into the array from which to start generating primitives." }
191 { "The " { $snippet "counts" } " slot contains a " { $link uint-array } " of corresponding counts of indexes to read from each specified " { $snippet "start" } " index." }
192 } } ;
193
194 HELP: points-mode
195 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to generate a point for each indexed vertex array element." } ;
196
197 HELP: primitive-mode
198 { $class-description "The " { $snippet "primitive-mode" } " slot of a " { $link render-set } " tells " { $link render } " what kind of primitives to generate and how to assemble them from the selected elements of the active " { $link vertex-array } "." }
199 { $list
200 { { $link points-mode } " causes each element to generate a point." }
201 { { $link lines-mode } " causes each pair of elements to generate a disconnected line." }
202 { { $link line-strip-mode } " causes each consecutive pair of elements to generate a connected strip of lines." }
203 { { $link line-loop-mode } " causes each consecutive pair of elements to generate a connected loop of lines, with an extra line connecting the last and first elements." }
204 { { $link triangles-mode } " causes every 3 elements to generate an independent triangle." }
205 { { $link triangle-strip-mode } " causes every consecutive group of 3 elements to generate a connected strip of triangles." }
206 { { $link triangle-fan-mode } " causes a triangle to be generated from the first element and every subsequent consecutive pair of elements in a fan pattern." } } ;
207
208 { primitive-mode points-mode lines-mode line-strip-mode line-loop-mode triangles-mode triangle-strip-mode triangle-fan-mode } related-words
209
210 HELP: render
211 { $values
212     { "render-set" render-set }
213 }
214 { $description "Submits a rendering job to the GPU. The values in the " { $link render-set } " tuple describe the job." } ;
215
216 HELP: render-set
217 { $class-description "A " { $snippet "render-set" } " tuple describes a GPU rendering job."
218 { $list
219 { "The " { $link primitive-mode } " slot determines what kind of primitives should be rendered, and how they should be assembled." }
220 { "The " { $link vertex-array } " slot supplies the shader program and vertex data to be rendered." }
221 { "The " { $snippet "uniforms" } " slot contains a " { $link uniform-tuple } " with values for the shader program's uniform parameters." }
222 { "The " { $snippet "indexes" } " slot contains one of the " { $link vertex-indexes } " types and selects elements from the vertex array to be rendered." }
223 { "The " { $snippet "instances" } " slot, if not " { $link f } ", instructs the GPU to render several instances of the same set of vertexes. Instancing requires OpenGL 3.1 or one of the " { $snippet "GL_EXT_draw_instanced" } " or " { $snippet "GL_ARB_draw_instanced" } " extensions." }
224 { "The " { $snippet "framebuffer" } " slot determines the target for the rendering output. Either the " { $link system-framebuffer } " or a user-created " { $link framebuffer } " object can be specified. " { $link f } " can also be specified to disable rasterization and only run the vertex transformation rendering stage." }
225 { "The " { $snippet "output-attachments" } " slot specifies which of the framebuffer's " { $link color-attachment-ref } "s to write the fragment shader's color output to. If the shader uses " { $snippet "gl_FragColor" } " or " { $snippet "gl_FragData[n]" } " to write its output, then " { $snippet "output-attachments" } " should be an array of " { $link color-attachment-ref } "s, and the output to color attachment binding is determined positionally. If the shader uses named output values, then " { $snippet "output-attachments" } " should be a list of string/" { $link color-attachment-ref } " pairs, mapping output names to color attachments." }
226 { "The " { $snippet "transform-feedback-output" } " slot specifies a target for transform feedback output from the vertex shader: either an entire " { $link buffer } ", a " { $link buffer-range } " subset, or a " { $link buffer-ptr } " offset into the buffer. If " { $link f } ", no transform feedback output is collected. The shader program associated with " { $snippet "vertex-array" } " must have a transform feedback output format specified." }
227 } }
228 { $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." } ;
229
230 HELP: bind-uniforms
231 { $values { "program-instance" program-instance } { "uniforms" uniform-tuple } }
232 { $description "Binds the uniform shader parameters for " { $snippet "program-instance" } " using values from the given uniform tuple." }
233 { $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." } ;
234
235 { render render-set } related-words
236
237 HELP: texture-uniform
238 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a texture uniform parameter." } ;
239
240 HELP: triangle-fan-mode
241 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to generate a fan of triangles using the first indexed vertex array element and every subsequent consecutive pair of elements." } ;
242
243 HELP: triangle-strip-mode
244 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to generate a strip of triangles using every consecutive group of 3 indexed vertex array elements." } ;
245
246 HELP: triangles-mode
247 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to generate a triangle for each group of 3 indexed vertex array elements." } ;
248
249 HELP: ubyte-indexes
250 { $class-description "This " { $link index-type } " indicates that an " { $link index-elements } " or " { $link multi-index-elements } " buffer consists of unsigned byte indexes." } ;
251
252 HELP: uint-indexes
253 { $class-description "This " { $link index-type } " indicates that an " { $link index-elements } " or " { $link multi-index-elements } " buffer consists of four-byte unsigned int indexes." } ;
254
255 HELP: uint-uniform
256 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to an unsigned integer uniform parameter." } ;
257
258 HELP: uniform
259 { $class-description "Values of this tuple type are passed to " { $link define-uniform-tuple } " to define a new " { $link uniform-tuple } " type." } ;
260
261 HELP: uniform-tuple
262 { $class-description "The base class for tuple types defined with " { $link POSTPONE: UNIFORM-TUPLE: } ". A uniform tuple is used as part of a " { $link render-set } " to supply values for a shader program's uniform parameters. See the " { $link POSTPONE: UNIFORM-TUPLE: } " documentation for details on how uniform tuples are defined and used." } ;
263
264 HELP: uniform-type
265 { $class-description { $snippet "uniform-type" } " values are used as part of a " { $link POSTPONE: UNIFORM-TUPLE: } " definition to define the types of uniform slots." } ;
266
267 HELP: ushort-indexes
268 { $class-description "This " { $link index-type } " indicates that an " { $link index-elements } " or " { $link multi-index-elements } " buffer consists of two-byte unsigned short indexes." } ;
269
270 { index-type ubyte-indexes ushort-indexes uint-indexes } related-words
271
272 HELP: uvec2-uniform
273 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component unsigned integer vector uniform parameter." } ;
274
275 HELP: uvec3-uniform
276 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component unsigned integer vector uniform parameter." } ;
277
278 HELP: uvec4-uniform
279 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component unsigned integer vector uniform parameter." } ;
280
281 HELP: vec2-uniform
282 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component float vector uniform parameter." } ;
283
284 HELP: vec3-uniform
285 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component float vector uniform parameter." } ;
286
287 HELP: vec4-uniform
288 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component float vector uniform parameter." } ;
289
290 HELP: vertex-indexes
291 { $class-description "This class is a union of the following tuple types, any of which can be used as the " { $snippet "indexes" } " slot of a " { $link render-set } " to select elements from a " { $link vertex-array } " for rendering."
292 { $list
293 { "An " { $link index-range } " value submits a sequential slice of a vertex array for rendering." }
294 { "An " { $link index-elements } " value submits vertex array elements in an order specified by an array of indexes." }
295 { "A " { $link multi-index-range } " value submits multiple sequential slices of a vertex array." }
296 { "A " { $link multi-index-elements } " value submits multiple separate lists of indexed vertex array elements." }
297 { "Specialized arrays of " { $link c:uchar } ", " { $link c:ushort } ", or " { $link c:uint } " elements may also be used directly as arrays of indexes." }
298 } } ;
299
300 ARTICLE: "gpu.render" "Rendering"
301 "The " { $vocab-link "gpu.render" } " vocabulary contains words for organizing and submitting data to the GPU for rendering."
302 { $subsections
303     render
304     render-set
305 }
306 { $link uniform-tuple } "s provide Factor types for containing and submitting shader uniform parameters:"
307 { $subsections POSTPONE: UNIFORM-TUPLE: }
308 ;
309
310 ABOUT: "gpu.render"