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