1 /* 2 * Copyright (C) 2013 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 */ 63 typedef char int8_t; 64 /** 65 * 16 bit integer type 66 */ 67 typedef short int16_t; 68 /** 69 * 32 bit integer type 70 */ 71 typedef int int32_t; 72 /** 73 * 64 bit integer type 74 */ 75 typedef long long int64_t; 76 /** 77 * 8 bit unsigned integer type 78 */ 79 typedef unsigned char uint8_t; 80 /** 81 * 16 bit unsigned integer type 82 */ 83 typedef unsigned short uint16_t; 84 /** 85 * 32 bit unsigned integer type 86 */ 87 typedef unsigned int uint32_t; 88 /** 89 * 64 bit unsigned integer type 90 */ 91 typedef unsigned long long uint64_t; 92 /** 93 * 8 bit unsigned integer type 94 */ 95 typedef uint8_t uchar; 96 /** 97 * 16 bit unsigned integer type 98 */ 99 typedef uint16_t ushort; 100 /** 101 * 32 bit unsigned integer type 102 */ 103 typedef uint32_t uint; 104 /** 105 * Typedef for unsigned long (use for 64-bit unsigned integers) 106 */ 107 typedef uint64_t ulong; 108 /** 109 * Typedef for unsigned int 110 */ 111 typedef uint32_t size_t; 112 /** 113 * Typedef for int (use for 32-bit integers) 114 */ 115 typedef int32_t ssize_t; 116 117 /** 118 * \brief Opaque handle to a RenderScript element. 119 * 120 * See: android.renderscript.Element 121 */ 122 typedef 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 */ 128 typedef 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 */ 134 typedef 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 */ 140 typedef 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 */ 146 typedef 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 */ 152 typedef 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 */ 158 typedef 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 */ 164 typedef 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 */ 170 typedef 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 */ 176 typedef 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 */ 182 typedef 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 */ 188 typedef 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 */ 195 typedef 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 */ 200 typedef 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 */ 206 typedef 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 */ 212 typedef 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 */ 217 typedef 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 */ 222 typedef 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 */ 228 typedef 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 */ 233 typedef 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 */ 238 typedef 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 */ 244 typedef 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 */ 249 typedef 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 */ 254 typedef 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 */ 260 typedef 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 */ 265 typedef 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 */ 270 typedef 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 */ 276 typedef 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 */ 281 typedef 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 */ 286 typedef 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 */ 292 typedef 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 */ 297 typedef 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 */ 302 typedef 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 */ 308 typedef 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 */ 313 typedef 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 */ 318 typedef 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 */ 324 typedef 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 */ 329 typedef 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 */ 334 typedef 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 */ 340 typedef 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 */ 345 typedef 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 */ 350 typedef 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 */ 358 typedef 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 */ 367 typedef 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 */ 376 typedef struct { 377 float m[4]; 378 } rs_matrix2x2; 379 380 /** 381 * quaternion type for use with the quaternion functions 382 */ 383 typedef 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 */ 393 typedef 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 */ 408 typedef 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 **/ 425 typedef 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 */ 478 typedef 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 */ 524 typedef 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 RS_KIND_PIXEL_YUV = 13, 534 535 RS_KIND_INVALID = 100, 536 } rs_data_kind; 537 538 typedef enum { 539 /** 540 * Always drawn 541 */ 542 RS_DEPTH_FUNC_ALWAYS = 0, 543 /** 544 * Drawn if the incoming depth value is less than that in the 545 * depth buffer 546 */ 547 RS_DEPTH_FUNC_LESS = 1, 548 /** 549 * Drawn if the incoming depth value is less or equal to that in 550 * the depth buffer 551 */ 552 RS_DEPTH_FUNC_LEQUAL = 2, 553 /** 554 * Drawn if the incoming depth value is greater than that in the 555 * depth buffer 556 */ 557 RS_DEPTH_FUNC_GREATER = 3, 558 /** 559 * Drawn if the incoming depth value is greater or equal to that 560 * in the depth buffer 561 */ 562 RS_DEPTH_FUNC_GEQUAL = 4, 563 /** 564 * Drawn if the incoming depth value is equal to that in the 565 * depth buffer 566 */ 567 RS_DEPTH_FUNC_EQUAL = 5, 568 /** 569 * Drawn if the incoming depth value is not equal to that in the 570 * depth buffer 571 */ 572 RS_DEPTH_FUNC_NOTEQUAL = 6, 573 /** 574 * Invalid depth function 575 */ 576 RS_DEPTH_FUNC_INVALID = 100, 577 } rs_depth_func; 578 579 typedef enum { 580 RS_BLEND_SRC_ZERO = 0, 581 RS_BLEND_SRC_ONE = 1, 582 RS_BLEND_SRC_DST_COLOR = 2, 583 RS_BLEND_SRC_ONE_MINUS_DST_COLOR = 3, 584 RS_BLEND_SRC_SRC_ALPHA = 4, 585 RS_BLEND_SRC_ONE_MINUS_SRC_ALPHA = 5, 586 RS_BLEND_SRC_DST_ALPHA = 6, 587 RS_BLEND_SRC_ONE_MINUS_DST_ALPHA = 7, 588 RS_BLEND_SRC_SRC_ALPHA_SATURATE = 8, 589 590 RS_BLEND_SRC_INVALID = 100, 591 } rs_blend_src_func; 592 593 typedef enum { 594 RS_BLEND_DST_ZERO = 0, 595 RS_BLEND_DST_ONE = 1, 596 RS_BLEND_DST_SRC_COLOR = 2, 597 RS_BLEND_DST_ONE_MINUS_SRC_COLOR = 3, 598 RS_BLEND_DST_SRC_ALPHA = 4, 599 RS_BLEND_DST_ONE_MINUS_SRC_ALPHA = 5, 600 RS_BLEND_DST_DST_ALPHA = 6, 601 RS_BLEND_DST_ONE_MINUS_DST_ALPHA = 7, 602 603 RS_BLEND_DST_INVALID = 100, 604 } rs_blend_dst_func; 605 606 typedef enum { 607 RS_CULL_BACK = 0, 608 RS_CULL_FRONT = 1, 609 RS_CULL_NONE = 2, 610 611 RS_CULL_INVALID = 100, 612 } rs_cull_mode; 613 614 typedef enum { 615 RS_SAMPLER_NEAREST = 0, 616 RS_SAMPLER_LINEAR = 1, 617 RS_SAMPLER_LINEAR_MIP_LINEAR = 2, 618 RS_SAMPLER_WRAP = 3, 619 RS_SAMPLER_CLAMP = 4, 620 RS_SAMPLER_LINEAR_MIP_NEAREST = 5, 621 RS_SAMPLER_MIRRORED_REPEAT = 6, 622 623 RS_SAMPLER_INVALID = 100, 624 } rs_sampler_value; 625 626 #endif // (defined(RS_VERSION) && (RS_VERSION >= 16)) 627 628 #endif // __RS_TYPES_RSH__ 629