]> gitweb.factorcode.org Git - factor.git/blob - extra/gpu/render/render-docs.factor
Specialized array overhaul
[factor.git] / extra / gpu / render / render-docs.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: alien alien.syntax byte-arrays classes gpu.buffers
3 gpu.framebuffers gpu.shaders gpu.textures help.markup
4 help.syntax images kernel math multiline sequences
5 specialized-arrays strings ;
6 SPECIALIZED-ARRAY: float
7 SPECIALIZED-ARRAY: int
8 SPECIALIZED-ARRAY: uint
9 SPECIALIZED-ARRAY: ulong
10 SPECIALIZED-ARRAY: void*
11 IN: gpu.render
12
13 HELP: <index-elements>
14 { $values
15     { "ptr" gpu-data-ptr } { "count" integer } { "index-type" index-type }
16     { "index-elements" index-elements }
17 }
18 { $description "Constructs an " { $link index-elements } " tuple." } ;
19
20 HELP: <index-range>
21 { $values
22     { "start" integer } { "count" integer }
23     { "index-range" index-range }
24 }
25 { $description "Constructs an " { $link index-range } " tuple." } ;
26
27 HELP: <multi-index-elements>
28 { $values
29     { "buffer" { $maybe buffer } } { "ptrs" "an " { $link uint-array } " or " { $link void*-array } } { "counts" uint-array } { "index-type" index-type }
30     { "multi-index-elements" multi-index-elements }
31 }
32 { $description "Constructs a " { $link multi-index-elements } " tuple." } ;
33
34 HELP: <multi-index-range>
35 { $values
36     { "starts" uint-array } { "counts" uint-array }
37     { "multi-index-range" multi-index-range }
38 }
39 { $description "Constructs a " { $link multi-index-range } " tuple." } ;
40
41 HELP: UNIFORM-TUPLE:
42 { $syntax <" UNIFORM-TUPLE: class-name
43     { "slot" uniform-type dimension }
44     { "slot" uniform-type dimension }
45     ...
46     { "slot" uniform-type dimension } ; "> }
47 { $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 } "."
48 $nl
49 "Uniform parameters are passed from Factor to the shader program through the uniform tuple as follows:"
50 { $list
51 { { $link int-uniform } "s and " { $link uint-uniform } "s take their values from Factor " { $link integer } "s." }
52 { { $link float-uniform } "s take their values from Factor " { $link float } "s." }
53 { { $link bool-uniform } "s take their values from Factor " { $link boolean } "s." }
54 { { $link texture-uniform } "s take their values from " { $link texture } " objects." }
55 { "Vector uniforms take their values from Factor " { $link sequence } "s of the corresponding component type."
56     { $list
57     { "Float vector types: " { $link vec2-uniform } ", " { $link vec3-uniform } ", " { $link vec4-uniform } }
58     { "Integer vector types: " { $link ivec2-uniform } ", " { $link ivec3-uniform } ", " { $link ivec4-uniform } }
59     { "Unsigned integer vector types: " { $link uvec2-uniform } ", " { $link uvec3-uniform } ", " { $link uvec4-uniform } }
60     { "Boolean vector types: " { $link bvec2-uniform } ", " { $link bvec3-uniform } ", " { $link bvec4-uniform } }
61     }
62 }
63 { "Matrix uniforms take their values from row-major Factor " { $link sequence } "s of sequences of floats. Matrix types are:" 
64     { $list
65     { { $link mat2-uniform } ", " { $link mat2x3-uniform } ", " { $link mat2x4-uniform } }
66     { { $link mat3x2-uniform } ", " { $link mat3-uniform } ", " { $link mat3x4-uniform } }
67     { { $link mat4x2-uniform } ", " { $link mat4x3-uniform } ", " { $link mat4-uniform } }
68     }
69 "Rectangular matrix type names are column x row."
70 }
71 { "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." }
72 { "Array uniforms are passed as Factor sequences of the corresponding value type above." }
73 }
74 $nl
75 "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."
76 } ;
77
78 HELP: bool-uniform
79 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a boolean uniform parameter." } ;
80
81 HELP: bvec2-uniform
82 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component boolean vector uniform parameter." } ;
83
84 HELP: bvec3-uniform
85 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component boolean vector uniform parameter." } ;
86
87 HELP: bvec4-uniform
88 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component boolean vector uniform parameter." } ;
89
90 HELP: define-uniform-tuple
91 { $values
92     { "class" class } { "superclass" class } { "uniforms" sequence }
93 }
94 { $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." } ;
95
96 HELP: float-uniform
97 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a float uniform parameter." } ;
98
99 { index-elements index-range multi-index-elements multi-index-range } related-words
100
101 HELP: index-elements
102 { $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."
103 { $list
104 { "The " { $snippet "ptr" } " slot contains a " { $link byte-array } ", " { $link alien } ", or " { $link buffer-ptr } " value referencing the beginning of the index array." }
105 { "The " { $snippet "count" } " slot contains an " { $link integer } " value specifying the number of indexes to supply from the array." }
106 { "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 } "." } 
107 } } ;
108
109 HELP: index-range
110 { $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 } "."
111 { $list
112 { "The " { $snippet "start" } " slot contains an " { $link integer } " value indicating the first element of the array to draw." }
113 { "The " { $snippet "count" } " slot contains an " { $link integer } " value indicating the number of elements to draw." }
114 } } ;
115
116 HELP: index-type
117 { $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 } "."  } ;
118
119 { index-type ubyte-indexes ushort-indexes uint-indexes } related-words
120
121 HELP: int-uniform
122 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a signed integer uniform parameter." } ;
123
124 HELP: invalid-uniform-type
125 { $values
126     { "uniform" uniform }
127 }
128 { $description "Throws an error indicating that a slot of a " { $link uniform-tuple } " has been declared to have an invalid type." } ;
129
130 HELP: ivec2-uniform
131 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component integer vector uniform parameter." } ;
132
133 HELP: ivec3-uniform
134 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component integer vector uniform parameter." } ;
135
136 HELP: ivec4-uniform
137 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component integer vector uniform parameter." } ;
138
139 HELP: lines-mode
140 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to assemble a line from each pair of indexed vertex array elements." } ;
141
142 HELP: line-loop-mode
143 { $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." } ;
144
145 HELP: line-strip-mode
146 { $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." } ;
147
148 HELP: mat2-uniform
149 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 2x2 square float matrix uniform parameter." } ;
150
151 HELP: mat2x3-uniform
152 { $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." } ;
153
154 HELP: mat2x4-uniform
155 { $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." } ;
156
157 HELP: mat3x2-uniform
158 { $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." } ;
159
160 HELP: mat3-uniform
161 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 3x3 square float matrix uniform parameter." } ;
162
163 HELP: mat3x4-uniform
164 { $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." } ;
165
166 HELP: mat4x2-uniform
167 { $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." } ;
168
169 HELP: mat4x3-uniform
170 { $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." } ;
171
172 HELP: mat4-uniform
173 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a 4x4 square float matrix uniform parameter." } ;
174
175 HELP: multi-index-elements
176 { $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."
177 { $list
178 { "The " { $snippet "buffer" } " slot contains either a " { $link buffer } " object to read indexes from, or " { $link f } " to read from CPU memory." }
179 { "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" } "." }
180 { "The " { $snippet "counts" } " slot contains a " { $link uint-array } " containing the number of indexes to read from each pointer or offset in " { $snippet "ptrs" } "." }
181 { "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 } "." }
182 } } ;
183
184 HELP: multi-index-range
185 { $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."
186 { $list
187 { "The " { $snippet "starts" } " slot contains a " { $link uint-array } " of indexes into the array from which to start generating primitives." }
188 { "The " { $snippet "counts" } " slot contains a " { $link uint-array } " of corresponding counts of indexes to read from each specified " { $snippet "start" } " index." }
189 } } ;
190
191 HELP: points-mode
192 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to generate a point for each indexed vertex array element." } ;
193
194 HELP: primitive-mode
195 { $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 } "."  }
196 { $list
197 { { $link points-mode } " causes each element to generate a point." }
198 { { $link lines-mode } " causes each pair of elements to generate a disconnected line." }
199 { { $link line-strip-mode } " causes each consecutive pair of elements to generate a connected strip of lines." }
200 { { $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." } 
201 { { $link triangles-mode } " causes every 3 elements to generate an independent triangle." }
202 { { $link triangle-strip-mode } " causes every consecutive group of 3 elements to generate a connected strip of triangles." } 
203 { { $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." } } ;
204
205 { primitive-mode points-mode lines-mode line-strip-mode line-loop-mode triangles-mode triangle-strip-mode triangle-fan-mode } related-words
206
207 HELP: render
208 { $values
209     { "render-set" render-set }
210 }
211 { $description "Submits a rendering job to the GPU. The values in the " { $link render-set } " tuple describe the job." } ;
212
213 HELP: render-set
214 { $class-description "A " { $snippet "render-set" } " tuple describes a GPU rendering job."
215 { $list
216 { "The " { $link primitive-mode } " slot determines what kind of primitives should be rendered, and how they should be assembled." }
217 { "The " { $link vertex-array } " slot supplies the shader program and vertex data to be rendered." }
218 { "The " { $snippet "uniforms" } " slot contains a " { $link uniform-tuple } " with values for the shader program's uniform parameters." }
219 { "The " { $snippet "indexes" } " slot contains one of the " { $link vertex-indexes } " types and selects elements from the vertex array to be rendered." }
220 { "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." }
221 { "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." }
222 { "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." }
223 { "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." }
224 } }
225 { $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." } ;
226
227 { render render-set } related-words
228
229 HELP: texture-uniform
230 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a texture uniform parameter." } ;
231
232 HELP: triangle-fan-mode
233 { $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." } ;
234
235 HELP: triangle-strip-mode
236 { $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." } ;
237
238 HELP: triangles-mode
239 { $class-description "This " { $link primitive-mode } " value instructs " { $link render } " to generate a triangle for each group of 3 indexed vertex array elements." } ;
240
241 HELP: ubyte-indexes
242 { $class-description "This " { $link index-type } " indicates that an " { $link index-elements } " or " { $link multi-index-elements } " buffer consists of unsigned byte indexes." } ;
243
244 HELP: uint-indexes
245 { $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." } ;
246
247 HELP: uint-uniform
248 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to an unsigned integer uniform parameter." } ;
249
250 HELP: uniform
251 { $class-description "Values of this tuple type are passed to " { $link define-uniform-tuple } " to define a new " { $link uniform-tuple } " type." } ;
252
253 HELP: uniform-tuple
254 { $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." } ;
255
256 HELP: uniform-type
257 { $class-description { $snippet "uniform-type" } " values are used as part of a " { $link POSTPONE: UNIFORM-TUPLE: } " definition to define the types of uniform slots." } ;
258
259 HELP: ushort-indexes
260 { $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." } ;
261
262 { index-type ubyte-indexes ushort-indexes uint-indexes } related-words
263
264 HELP: uvec2-uniform
265 { $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." } ;
266
267 HELP: uvec3-uniform
268 { $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." } ;
269
270 HELP: uvec4-uniform
271 { $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." } ;
272
273 HELP: vec2-uniform
274 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a two-component float vector uniform parameter." } ;
275
276 HELP: vec3-uniform
277 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a three-component float vector uniform parameter." } ;
278
279 HELP: vec4-uniform
280 { $class-description "This " { $link uniform-type } " indicates that a slot of a " { $link uniform-tuple } " corresponds to a four-component float vector uniform parameter." } ;
281
282 HELP: vertex-indexes
283 { $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."
284 { $list
285 { "An " { $link index-range } " value submits a sequential slice of a vertex array for rendering." }
286 { "An " { $link index-elements } " value submits vertex array elements in an order specified by an array of indexes." }
287 { "A " { $link multi-index-range } " value submits multiple sequential slices of a vertex array." }
288 { "A " { $link multi-index-elements } " value submits multiple separate lists of indexed vertex array elements." }
289 } } ;
290
291 ARTICLE: "gpu.render" "Rendering"
292 "The " { $vocab-link "gpu.render" } " vocabulary contains words for organizing and submitting data to the GPU for rendering."
293 { $subsection render }
294 { $subsection render-set }
295 { $link uniform-tuple } "s provide Factor types for containing and submitting shader uniform parameters:"
296 { $subsection POSTPONE: UNIFORM-TUPLE: }
297 ;
298
299 ABOUT: "gpu.render"