• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/** @file rs_types.rsh
18 *
19 *  Define the standard Renderscript types
20 *
21 *  Integers
22 *  8 bit: char, int8_t
23 *  16 bit: short, int16_t
24 *  32 bit: int, in32_t
25 *  64 bit: long, long long, int64_t
26 *
27 *  Unsigned Integers
28 *  8 bit: uchar, uint8_t
29 *  16 bit: ushort, uint16_t
30 *  32 bit: uint, uint32_t
31 *  64 bit: ulong, uint64_t
32 *
33 *  Floating point
34 *  32 bit: float
35 *  64 bit: double
36 *
37 *  Vectors of length 2, 3, and 4 are supported for all the types above.
38 *
39 */
40
41#ifndef __RS_TYPES_RSH__
42#define __RS_TYPES_RSH__
43
44#define M_PI        3.14159265358979323846264338327950288f   /* pi */
45
46#include "stdbool.h"
47/**
48 * 8 bit integer type
49 */
50typedef char int8_t;
51/**
52 * 16 bit integer type
53 */
54typedef short int16_t;
55/**
56 * 32 bit integer type
57 */
58typedef int int32_t;
59/**
60 * 64 bit integer type
61 */
62typedef long long int64_t;
63/**
64 * 8 bit unsigned integer type
65 */
66typedef unsigned char uint8_t;
67/**
68 * 16 bit unsigned integer type
69 */
70typedef unsigned short uint16_t;
71/**
72 * 32 bit unsigned integer type
73 */
74typedef unsigned int uint32_t;
75/**
76 * 64 bit unsigned integer type
77 */
78typedef unsigned long long uint64_t;
79/**
80 * 8 bit unsigned integer type
81 */
82typedef uint8_t uchar;
83/**
84 * 16 bit unsigned integer type
85 */
86typedef uint16_t ushort;
87/**
88 * 32 bit unsigned integer type
89 */
90typedef uint32_t uint;
91/**
92 * Typedef for unsigned long (use for 64-bit unsigned integers)
93 */
94typedef uint64_t ulong;
95/**
96 * Typedef for unsigned int
97 */
98typedef uint32_t size_t;
99/**
100 * Typedef for int (use for 32-bit integers)
101 */
102typedef int32_t ssize_t;
103
104/**
105 * \brief Opaque handle to a Renderscript element.
106 *
107 * See: android.renderscript.Element
108 */
109typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_element;
110/**
111 * \brief Opaque handle to a Renderscript type.
112 *
113 * See: android.renderscript.Type
114 */
115typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_type;
116/**
117 * \brief Opaque handle to a Renderscript allocation.
118 *
119 * See: android.renderscript.Allocation
120 */
121typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_allocation;
122/**
123 * \brief Opaque handle to a Renderscript sampler object.
124 *
125 * See: android.renderscript.Sampler
126 */
127typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_sampler;
128/**
129 * \brief Opaque handle to a Renderscript script object.
130 *
131 * See: android.renderscript.ScriptC
132 */
133typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_script;
134/**
135 * \brief Opaque handle to a Renderscript mesh object.
136 *
137 * See: android.renderscript.Mesh
138 */
139typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_mesh;
140/**
141 * \brief Opaque handle to a Renderscript Path object.
142 *
143 * See: android.renderscript.Path
144 */
145typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_path;
146/**
147 * \brief Opaque handle to a Renderscript ProgramFragment object.
148 *
149 * See: android.renderscript.ProgramFragment
150 */
151typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_fragment;
152/**
153 * \brief Opaque handle to a Renderscript ProgramVertex object.
154 *
155 * See: android.renderscript.ProgramVertex
156 */
157typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_vertex;
158/**
159 * \brief Opaque handle to a Renderscript ProgramRaster object.
160 *
161 * See: android.renderscript.ProgramRaster
162 */
163typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_raster;
164/**
165 * \brief Opaque handle to a Renderscript ProgramStore object.
166 *
167 * See: android.renderscript.ProgramStore
168 */
169typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_program_store;
170/**
171 * \brief Opaque handle to a Renderscript font object.
172 *
173 * See: android.renderscript.Font
174 */
175typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_font;
176
177/**
178 * Vector version of the basic float type.
179 * Provides two float fields packed into a single 64 bit field with 64 bit
180 * alignment.
181 */
182typedef float float2 __attribute__((ext_vector_type(2)));
183/**
184 * Vector version of the basic float type. Provides three float fields packed
185 * into a single 128 bit field with 128 bit alignment.
186 */
187typedef float float3 __attribute__((ext_vector_type(3)));
188/**
189 * Vector version of the basic float type.
190 * Provides four float fields packed into a single 128 bit field with 128 bit
191 * alignment.
192 */
193typedef float float4 __attribute__((ext_vector_type(4)));
194
195/**
196 * Vector version of the basic double type. Provides two double fields packed
197 * into a single 128 bit field with 128 bit alignment.
198 */
199typedef double double2 __attribute__((ext_vector_type(2)));
200/**
201 * Vector version of the basic double type. Provides three double fields packed
202 * into a single 256 bit field with 256 bit alignment.
203 */
204typedef double double3 __attribute__((ext_vector_type(3)));
205/**
206 * Vector version of the basic double type. Provides four double fields packed
207 * into a single 256 bit field with 256 bit alignment.
208 */
209typedef double double4 __attribute__((ext_vector_type(4)));
210
211/**
212 * Vector version of the basic uchar type. Provides two uchar fields packed
213 * into a single 16 bit field with 16 bit alignment.
214 */
215typedef uchar uchar2 __attribute__((ext_vector_type(2)));
216/**
217 * Vector version of the basic uchar type. Provides three uchar fields packed
218 * into a single 32 bit field with 32 bit alignment.
219 */
220typedef uchar uchar3 __attribute__((ext_vector_type(3)));
221/**
222 * Vector version of the basic uchar type. Provides four uchar fields packed
223 * into a single 32 bit field with 32 bit alignment.
224 */
225typedef uchar uchar4 __attribute__((ext_vector_type(4)));
226
227/**
228 * Vector version of the basic ushort type. Provides two ushort fields packed
229 * into a single 32 bit field with 32 bit alignment.
230 */
231typedef ushort ushort2 __attribute__((ext_vector_type(2)));
232/**
233 * Vector version of the basic ushort type. Provides three ushort fields packed
234 * into a single 64 bit field with 64 bit alignment.
235 */
236typedef ushort ushort3 __attribute__((ext_vector_type(3)));
237/**
238 * Vector version of the basic ushort type. Provides four ushort fields packed
239 * into a single 64 bit field with 64 bit alignment.
240 */
241typedef ushort ushort4 __attribute__((ext_vector_type(4)));
242
243/**
244 * Vector version of the basic uint type. Provides two uint fields packed into a
245 * single 64 bit field with 64 bit alignment.
246 */
247typedef uint uint2 __attribute__((ext_vector_type(2)));
248/**
249 * Vector version of the basic uint type. Provides three uint fields packed into
250 * a single 128 bit field with 128 bit alignment.
251 */
252typedef uint uint3 __attribute__((ext_vector_type(3)));
253/**
254 * Vector version of the basic uint type. Provides four uint fields packed into
255 * a single 128 bit field with 128 bit alignment.
256 */
257typedef uint uint4 __attribute__((ext_vector_type(4)));
258
259/**
260 * Vector version of the basic ulong type. Provides two ulong fields packed into
261 * a single 128 bit field with 128 bit alignment.
262 */
263typedef ulong ulong2 __attribute__((ext_vector_type(2)));
264/**
265 * Vector version of the basic ulong type. Provides three ulong fields packed
266 * into a single 256 bit field with 256 bit alignment.
267 */
268typedef ulong ulong3 __attribute__((ext_vector_type(3)));
269/**
270 * Vector version of the basic ulong type. Provides four ulong fields packed
271 * into a single 256 bit field with 256 bit alignment.
272 */
273typedef ulong ulong4 __attribute__((ext_vector_type(4)));
274
275/**
276 * Vector version of the basic char type. Provides two char fields packed into a
277 * single 16 bit field with 16 bit alignment.
278 */
279typedef char char2 __attribute__((ext_vector_type(2)));
280/**
281 * Vector version of the basic char type. Provides three char fields packed into
282 * a single 32 bit field with 32 bit alignment.
283 */
284typedef char char3 __attribute__((ext_vector_type(3)));
285/**
286 * Vector version of the basic char type. Provides four char fields packed into
287 * a single 32 bit field with 32 bit alignment.
288 */
289typedef char char4 __attribute__((ext_vector_type(4)));
290
291/**
292 * Vector version of the basic short type. Provides two short fields packed into
293 * a single 32 bit field with 32 bit alignment.
294 */
295typedef short short2 __attribute__((ext_vector_type(2)));
296/**
297 * Vector version of the basic short type. Provides three short fields packed
298 * into a single 64 bit field with 64 bit alignment.
299 */
300typedef short short3 __attribute__((ext_vector_type(3)));
301/**
302 * Vector version of the basic short type. Provides four short fields packed
303 * into a single 64 bit field with 64 bit alignment.
304 */
305typedef short short4 __attribute__((ext_vector_type(4)));
306
307/**
308 * Vector version of the basic int type. Provides two int fields packed into a
309 * single 64 bit field with 64 bit alignment.
310 */
311typedef int int2 __attribute__((ext_vector_type(2)));
312/**
313 * Vector version of the basic int type. Provides three int fields packed into a
314 * single 128 bit field with 128 bit alignment.
315 */
316typedef int int3 __attribute__((ext_vector_type(3)));
317/**
318 * Vector version of the basic int type. Provides two four fields packed into a
319 * single 128 bit field with 128 bit alignment.
320 */
321typedef int int4 __attribute__((ext_vector_type(4)));
322
323/**
324 * Vector version of the basic long type. Provides two long fields packed into a
325 * single 128 bit field with 128 bit alignment.
326 */
327typedef long long2 __attribute__((ext_vector_type(2)));
328/**
329 * Vector version of the basic long type. Provides three long fields packed into
330 * a single 256 bit field with 256 bit alignment.
331 */
332typedef long long3 __attribute__((ext_vector_type(3)));
333/**
334 * Vector version of the basic long type. Provides four long fields packed into
335 * a single 256 bit field with 256 bit alignment.
336 */
337typedef long long4 __attribute__((ext_vector_type(4)));
338
339/**
340 * \brief 4x4 float matrix
341 *
342 * Native holder for RS matrix.  Elements are stored in the array at the
343 * location [row*4 + col]
344 */
345typedef struct {
346    float m[16];
347} rs_matrix4x4;
348/**
349 * \brief 3x3 float matrix
350 *
351 * Native holder for RS matrix.  Elements are stored in the array at the
352 * location [row*3 + col]
353 */
354typedef struct {
355    float m[9];
356} rs_matrix3x3;
357/**
358 * \brief 2x2 float matrix
359 *
360 * Native holder for RS matrix.  Elements are stored in the array at the
361 * location [row*2 + col]
362 */
363typedef struct {
364    float m[4];
365} rs_matrix2x2;
366
367/**
368 * quaternion type for use with the quaternion functions
369 */
370typedef float4 rs_quaternion;
371
372#define RS_PACKED __attribute__((packed, aligned(4)))
373#define NULL ((void *)0)
374
375#if (defined(RS_VERSION) && (RS_VERSION >= 14))
376
377/**
378 * \brief Enum for selecting cube map faces
379 */
380typedef enum {
381    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
382    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
383    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
384    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
385    RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
386    RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
387} rs_allocation_cubemap_face;
388
389/**
390 * \brief Bitfield to specify the usage types for an allocation.
391 *
392 * These values are ORed together to specify which usages or memory spaces are
393 * relevant to an allocation or an operation on an allocation.
394 */
395typedef enum {
396    RS_ALLOCATION_USAGE_SCRIPT = 0x0001,
397    RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
398    RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
399    RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
400    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010
401} rs_allocation_usage_type;
402
403#endif //defined(RS_VERSION) && (RS_VERSION >= 14)
404
405// New API's
406#if (defined(RS_VERSION) && (RS_VERSION >= 16))
407
408/**
409 * Describes the way mesh vertex data is interpreted when rendering
410 *
411 **/
412typedef enum {
413    /**
414    * Vertex data will be rendered as a series of points
415    */
416    RS_PRIMITIVE_POINT              = 0,
417    /**
418    * Vertex pairs will be rendered as lines
419    */
420    RS_PRIMITIVE_LINE               = 1,
421    /**
422    * Vertex data will be rendered as a connected line strip
423    */
424    RS_PRIMITIVE_LINE_STRIP         = 2,
425    /**
426    * Vertices will be rendered as individual triangles
427    */
428    RS_PRIMITIVE_TRIANGLE           = 3,
429    /**
430    * Vertices will be rendered as a connected triangle strip
431    * defined by the first three vertices with each additional
432    * triangle defined by a new vertex
433    */
434    RS_PRIMITIVE_TRIANGLE_STRIP     = 4,
435    /**
436    * Vertices will be rendered as a sequence of triangles that all
437    * share first vertex as the origin
438    */
439    RS_PRIMITIVE_TRIANGLE_FAN       = 5,
440
441    /**
442    * Invalid primitive
443    */
444    RS_PRIMITIVE_INVALID            = 100,
445} rs_primitive;
446
447/**
448 * \brief Enumeration for possible element data types
449 *
450 * DataType represents the basic type information for a basic element.  The
451 * naming convention follows.  For numeric types it is FLOAT,
452 * SIGNED, or UNSIGNED followed by the _BITS where BITS is the
453 * size of the data.  BOOLEAN is a true / false (1,0)
454 * represented in an 8 bit container.  The UNSIGNED variants
455 * with multiple bit definitions are for packed graphical data
456 * formats and represent vectors with per vector member sizes
457 * which are treated as a single unit for packing and alignment
458 * purposes.
459 *
460 * MATRIX the three matrix types contain FLOAT_32 elements and are treated
461 * as 32 bits for alignment purposes.
462 *
463 * RS_* objects.  32 bit opaque handles.
464 */
465typedef enum {
466    RS_TYPE_NONE             = 0,
467    RS_TYPE_FLOAT_32         = 2,
468    RS_TYPE_FLOAT_64         = 3,
469    RS_TYPE_SIGNED_8         = 4,
470    RS_TYPE_SIGNED_16        = 5,
471    RS_TYPE_SIGNED_32        = 6,
472    RS_TYPE_SIGNED_64        = 7,
473    RS_TYPE_UNSIGNED_8       = 8,
474    RS_TYPE_UNSIGNED_16      = 9,
475    RS_TYPE_UNSIGNED_32      = 10,
476    RS_TYPE_UNSIGNED_64      = 11,
477
478    RS_TYPE_BOOLEAN          = 12,
479
480    RS_TYPE_UNSIGNED_5_6_5   = 13,
481    RS_TYPE_UNSIGNED_5_5_5_1 = 14,
482    RS_TYPE_UNSIGNED_4_4_4_4 = 15,
483
484    RS_TYPE_MATRIX_4X4       = 16,
485    RS_TYPE_MATRIX_3X3       = 17,
486    RS_TYPE_MATRIX_2X2       = 18,
487
488    RS_TYPE_ELEMENT          = 1000,
489    RS_TYPE_TYPE             = 1001,
490    RS_TYPE_ALLOCATION       = 1002,
491    RS_TYPE_SAMPLER          = 1003,
492    RS_TYPE_SCRIPT           = 1004,
493    RS_TYPE_MESH             = 1005,
494    RS_TYPE_PROGRAM_FRAGMENT = 1006,
495    RS_TYPE_PROGRAM_VERTEX   = 1007,
496    RS_TYPE_PROGRAM_RASTER   = 1008,
497    RS_TYPE_PROGRAM_STORE    = 1009,
498    RS_TYPE_FONT             = 1010,
499
500    RS_TYPE_INVALID          = 10000,
501} rs_data_type;
502
503/**
504 * \brief Enumeration for possible element data kind
505 *
506 * The special interpretation of the data if required.  This is primarly
507 * useful for graphical data.  USER indicates no special interpretation is
508 * expected.  PIXEL is used in conjunction with the standard data types for
509 * representing texture formats.
510 */
511typedef enum {
512    RS_KIND_USER         = 0,
513
514    RS_KIND_PIXEL_L      = 7,
515    RS_KIND_PIXEL_A      = 8,
516    RS_KIND_PIXEL_LA     = 9,
517    RS_KIND_PIXEL_RGB    = 10,
518    RS_KIND_PIXEL_RGBA   = 11,
519    RS_KIND_PIXEL_DEPTH  = 12,
520
521    RS_KIND_INVALID      = 100,
522} rs_data_kind;
523
524typedef enum {
525    /**
526    * Always drawn
527    */
528    RS_DEPTH_FUNC_ALWAYS        = 0,
529    /**
530    * Drawn if the incoming depth value is less than that in the
531    * depth buffer
532    */
533    RS_DEPTH_FUNC_LESS          = 1,
534    /**
535    * Drawn if the incoming depth value is less or equal to that in
536    * the depth buffer
537    */
538    RS_DEPTH_FUNC_LEQUAL        = 2,
539    /**
540    * Drawn if the incoming depth value is greater than that in the
541    * depth buffer
542    */
543    RS_DEPTH_FUNC_GREATER       = 3,
544    /**
545    * Drawn if the incoming depth value is greater or equal to that
546    * in the depth buffer
547    */
548    RS_DEPTH_FUNC_GEQUAL        = 4,
549    /**
550    * Drawn if the incoming depth value is equal to that in the
551    * depth buffer
552    */
553    RS_DEPTH_FUNC_EQUAL         = 5,
554    /**
555    * Drawn if the incoming depth value is not equal to that in the
556    * depth buffer
557    */
558    RS_DEPTH_FUNC_NOTEQUAL      = 6,
559    /**
560    * Invalid depth function
561    */
562    RS_DEPTH_FUNC_INVALID       = 100,
563} rs_depth_func;
564
565typedef enum {
566    RS_BLEND_SRC_ZERO                   = 0,
567    RS_BLEND_SRC_ONE                    = 1,
568    RS_BLEND_SRC_DST_COLOR              = 2,
569    RS_BLEND_SRC_ONE_MINUS_DST_COLOR    = 3,
570    RS_BLEND_SRC_SRC_ALPHA              = 4,
571    RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA    = 5,
572    RS_BLEND_SRC_DST_ALPHA              = 6,
573    RS_BLEND_SRC_ONE_MINUS_DST_ALPHA    = 7,
574    RS_BLEND_SRC_SRC_ALPHA_SATURATE     = 8,
575
576    RS_BLEND_SRC_INVALID                = 100,
577} rs_blend_src_func;
578
579typedef enum {
580    RS_BLEND_DST_ZERO                   = 0,
581    RS_BLEND_DST_ONE                    = 1,
582    RS_BLEND_DST_SRC_COLOR              = 2,
583    RS_BLEND_DST_ONE_MINUS_SRC_COLOR    = 3,
584    RS_BLEND_DST_SRC_ALPHA              = 4,
585    RS_BLEND_DST_ONE_MINUS_SRC_ALPHA    = 5,
586    RS_BLEND_DST_DST_ALPHA              = 6,
587    RS_BLEND_DST_ONE_MINUS_DST_ALPHA    = 7,
588
589    RS_BLEND_DST_INVALID                = 100,
590} rs_blend_dst_func;
591
592typedef enum {
593    RS_CULL_BACK     = 0,
594    RS_CULL_FRONT    = 1,
595    RS_CULL_NONE     = 2,
596
597    RS_CULL_INVALID  = 100,
598} rs_cull_mode;
599
600typedef enum {
601    RS_SAMPLER_NEAREST              = 0,
602    RS_SAMPLER_LINEAR               = 1,
603    RS_SAMPLER_LINEAR_MIP_LINEAR    = 2,
604    RS_SAMPLER_WRAP                 = 3,
605    RS_SAMPLER_CLAMP                = 4,
606    RS_SAMPLER_LINEAR_MIP_NEAREST   = 5,
607
608    RS_SAMPLER_INVALID              = 100,
609} rs_sampler_value;
610
611#endif // (defined(RS_VERSION) && (RS_VERSION >= 16))
612
613#endif // __RS_TYPES_RSH__
614