1 /* TSI 2023.xmo */ 2 /******************************************************************************* 3 * Copyright (c) 2023 Think Silicon Single Member PC 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this header file and/or associated documentation files to use, copy, 7 * modify, merge, publish, distribute, sublicense, and/or sell copies of the 8 * Materials, and to permit persons to whom the Materials are furnished to do 9 * so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Materials. 13 * 14 * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS 15 * NEMAGFX API. THE UNMODIFIED, NORMATIVE VERSIONS OF THINK-SILICON NEMAGFX 16 * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT: 17 * https://think-silicon.com/products/software/nemagfx-api 18 * 19 * The software is provided 'as is', without warranty of any kind, express or 20 * implied, including but not limited to the warranties of merchantability, 21 * fitness for a particular purpose and noninfringement. In no event shall 22 * Think Silicon Single Member PC be liable for any claim, damages or other 23 * liability, whether in an action of contract, tort or otherwise, arising 24 * from, out of or in connection with the software or the use or other dealings 25 * in the software. 26 ******************************************************************************/ 27 28 29 #ifndef NEMA_GRAPHICS_H__ 30 #define NEMA_GRAPHICS_H__ 31 32 #include "nema_sys_defs.h" 33 #include "nema_hal.h" 34 #include "nema_matrix3x3.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 typedef struct _img_obj_ { 41 nema_buffer_t bo; 42 uint16_t w; 43 uint16_t h; 44 int stride; 45 uint32_t color; 46 uint8_t format; 47 uint8_t sampling_mode; // NEMA_FILTER* 48 } img_obj_t; 49 50 typedef img_obj_t nema_img_obj_t; 51 52 typedef enum { 53 NEMA_NOTEX = -1, /**< No Texture */ 54 NEMA_TEX0 = 0, /**< Texture 0 */ 55 NEMA_TEX1 = 1, /**< Texture 1 */ 56 NEMA_TEX2 = 2, /**< Texture 2 */ 57 NEMA_TEX3 = 3, /**< Texture 3 */ 58 NEMA_TEXMAX = 4 /**< Enum max value */ 59 } nema_tex_t; 60 61 #define NEMA_RGBX8888 0x00U /**< RGBX8888 */ 62 #define NEMA_RGBA8888 0x01U /**< RGBA8888 */ 63 #define NEMA_XRGB8888 0x02U /**< XRGB8888 */ 64 #define NEMA_ARGB8888 0x03U /**< ARGB8888 */ 65 #define NEMA_RGB565 0x04U /**< RGBA5650 */ 66 #define NEMA_RGBA5650 0x04U /**< RGBA5650 */ 67 #define NEMA_RGBA5551 0x05U /**< RGBA5551 */ 68 #define NEMA_RGBA4444 0x06U /**< RGBA4444 */ 69 #define NEMA_RGBA0800 0x07U /**< RGBA0800 */ 70 #define NEMA_A8 0x08U /**< RGBA0008 */ 71 #define NEMA_RGBA0008 0x08U /**< RGBA0008 */ 72 #define NEMA_L8 0x09U /**< L8 */ 73 #define NEMA_RGBA3320 0x38U /**< RGBA3320 (source only) */ 74 #define NEMA_RGB332 0x38U /**< RGBA3320 (source only) */ 75 #define NEMA_BW1 0x0CU /**< A1 (source only) */ 76 #define NEMA_A1 0x0CU /**< A1 (source only) */ 77 #define NEMA_L1 0x0BU /**< L1 (source only) */ 78 #define NEMA_UYVY 0x0DU /**< UYVY */ 79 #define NEMA_ABGR8888 0x0EU /**< ABGR8888 */ 80 #define NEMA_XBGR8888 0x0FU /**< XBGR8888 */ 81 #define NEMA_BGRA8888 0x10U /**< BGRA */ 82 #define NEMA_BGRX8888 0x11U /**< BGRX */ 83 #define NEMA_TSC4 0x12U /**< TSC4 */ 84 #define NEMA_TSC6 0x16U /**< TSC6 */ 85 #define NEMA_TSC6A 0x17U /**< TSC6A */ 86 #define NEMA_RV 0x18U /**< RV */ 87 #define NEMA_GU 0x19U /**< GU */ 88 #define NEMA_BY 0x1AU /**< BY */ 89 #define NEMA_YUV 0x1BU /**< YUV */ 90 #define NEMA_Z24_8 0x1cU /**< Z24_8 */ 91 #define NEMA_Z16 0x1dU /**< Z16 */ 92 #define NEMA_UV 0x1eU /**< UV */ 93 #define NEMA_A1LE 0x27U /**< A1LE (source only) */ 94 #define NEMA_A2LE 0x28U /**< A2LE (source only) */ 95 #define NEMA_A4LE 0x29U /**< A4LE (source only) */ 96 #define NEMA_L1LE 0x2AU /**< L1LE (source only) */ 97 #define NEMA_L2LE 0x2BU /**< L2LE (source only) */ 98 #define NEMA_L4LE 0x2CU /**< L4LE (source only) */ 99 #define NEMA_A2 0x30U /**< A2 (source only) */ 100 #define NEMA_A4 0x34U /**< A4 (source only) */ 101 #define NEMA_L2 0x31U /**< L2 (source only) */ 102 #define NEMA_L4 0x35U /**< L4 (source only) */ 103 #define NEMA_BGR24 0x39U /**< BGR24 */ 104 #define NEMA_RGB24 0x3CU /**< RGB24 */ 105 #define NEMA_RV10 0x3DU /**< RV-10bit */ 106 #define NEMA_GU10 0x3EU /**< GU-10bit */ 107 #define NEMA_BY10 0x3FU /**< BY-10bit */ 108 #define NEMA_RGBA2222 0x40U /**< RGBA2222 (Available if HW enabled - check HW manual) */ 109 #define NEMA_ABGR2222 0x41U /**< ABGR2222 (Available if HW enabled - check HW manual) */ 110 #define NEMA_BGRA2222 0x42U /**< BGRA2222 (Available if HW enabled - check HW manual) */ 111 #define NEMA_ARGB2222 0x43U /**< ARGB2222 (Available if HW enabled - check HW manual) */ 112 #define NEMA_AL88 0x44U /**< AL88 (Available if HW enabled - check HW manual) */ 113 #define NEMA_AL44 0x45U /**< AL44 (Available if HW enabled - check HW manual) */ 114 #define NEMA_ARGB1555 0x46U /**< ARGB1555 (Available if HW enabled - check HW manual) */ 115 #define NEMA_ARGB4444 0x47U /**< ARGB4444 (Available if HW enabled - check HW manual) */ 116 #define NEMA_BGRA5650 0x13U /**< BGRA5650 (Available if HW enabled - check HW manual) */ 117 #define NEMA_BGR565 0x13U /**< BGRA5650 (Available if HW enabled - check HW manual) */ 118 #define NEMA_BGRA5551 0x48U /**< BGRA5551 (Available if HW enabled - check HW manual) */ 119 #define NEMA_ABGR1555 0x49U /**< ABGR1555 (Available if HW enabled - check HW manual) */ 120 #define NEMA_BGRA4444 0x4aU /**< BGRA4444 (Available if HW enabled - check HW manual) */ 121 #define NEMA_ABGR4444 0x4bU /**< ABGR4444 (Available if HW enabled - check HW manual) */ 122 #define NEMA_TSC12 0x4cU /**< TSC12 (Available if HW enabled - check HW manual) */ 123 #define NEMA_TSC12A 0x4dU /**< TSC12A (Available if HW enabled - check HW manual) */ 124 #define NEMA_TSC6AP 0x4eU /**< TSC6AP (Available if HW enabled - check HW manual) */ 125 126 #define NEMA_DITHER 0x80U /**< Nema Dithering */ 127 #define NEMA_FORMAT_MASK 0x7FU /**< Format Mask */ 128 129 typedef uint32_t nema_tex_format_t; 130 131 //----------------------------------------------------------------------------------------------------------------------- 132 133 // Texture Unit Parameters 134 //----------------------------------------------------------------------------------------- 135 // Filtering - 0:0 136 //---------------------- 137 #define NEMA_FILTER_PS 0x00U /**< Point Sampling. */ 138 #define NEMA_FILTER_BL 0x01U /**< Bilinear filtering. */ 139 140 // Wrapping Mode 3:2 141 //---------------------- 142 #define NEMA_TEX_CLAMP (0x00U) /**< Clamp */ 143 #define NEMA_TEX_REPEAT (0x01U<<2) /**< Repeat */ 144 #define NEMA_TEX_BORDER (0x02U<<2) /**< Border */ 145 #define NEMA_TEX_MIRROR (0x03U<<2) /**< Mirror */ 146 147 // Texture Coordinates Ordering 4:4 148 //---------------------- 149 #define NEMA_TEX_MORTON_ORDER (0x10U) 150 151 // Texture Coordinates Format 6:5 152 //---------------------- 153 #define NEMA_TEX_RANGE_0_1 (0x1U<<5) /**< Interpolated Coordinates range: 0-1 */ 154 #define NEMA_TEX_LEFT_HANDED (0x1U<<6) /**< (0,0) is bottom left corner */ 155 156 typedef uint8_t nema_tex_mode_t; 157 158 // Triangle Culling 159 //----------------------------------------------------------------------------------------- 160 typedef enum { 161 NEMA_CULL_NONE = 0 , /**< Disable Triangle/Quadrilateral Culling */ 162 NEMA_CULL_CW = (1U<<28), /**< Cull clockwise Triangles/Quadrilaterals */ 163 NEMA_CULL_CCW = (1U<<29), /**< Cull anti-clockwise Triangles/Quadrilaterals */ 164 NEMA_CULL_ALL = NEMA_CULL_CW | NEMA_CULL_CCW /**< Cull all */ 165 } nema_tri_cull_t; 166 167 // Rotation Modes 168 //----------------------------------------------------------------------------------------------------------------------- 169 170 #define NEMA_ROT_000_CCW (0x0U) /**< No rotation */ 171 #define NEMA_ROT_090_CCW (0x1U) /**< Rotate 90 degrees counter-clockwise */ 172 #define NEMA_ROT_180_CCW (0x2U) /**< Rotate 180 degrees counter-clockwise */ 173 #define NEMA_ROT_270_CCW (0x3U) /**< Rotate 270 degrees counter-clockwise */ 174 #define NEMA_ROT_000_CW (0x0U) /**< No rotation */ 175 #define NEMA_ROT_270_CW (0x1U) /**< Rotate 270 degrees clockwise */ 176 #define NEMA_ROT_180_CW (0x2U) /**< Rotate 180 degrees clockwise */ 177 #define NEMA_ROT_090_CW (0x3U) /**< Rotate 90 degrees clockwise */ 178 #define NEMA_MIR_VERT (0x4U) /**< Mirror Vertically */ 179 #define NEMA_MIR_HOR (0x8U) /**< Mirror Horizontally */ 180 181 182 /** \brief Check if a known GPU is present 183 * 184 * \return -1 if no known GPU is present 185 * 186 */ 187 int nema_checkGPUPresence(void); 188 189 // ------------------------------ TEXTURES ------------------------------------- 190 191 /** \brief Program a Texture Unit 192 * 193 * \param texid Texture unit to be programmed 194 * \param addr_gpu Texture's address as seen by the GPU 195 * \param width Texture's width 196 * \param height Texture's height 197 * \param format Texture's format 198 * \param stride Texture's stride. If stride < 0, it's left to be calculated 199 * \param wrap_mode Wrap/Repeat mode to be used. When using 'repeat' or 'mirror', texture dimensions must be a power of two. Otherwise the behavior is undefined. 200 * 201 */ 202 void nema_bind_tex(nema_tex_t texid, uintptr_t addr_gpu, 203 uint32_t width, uint32_t height, 204 nema_tex_format_t format, int32_t stride, nema_tex_mode_t wrap_mode); 205 206 /** \brief Set Texture Mapping default color 207 * 208 * \param color default color in 32-bit RGBA format 209 * \see nema_rgba() 210 * 211 */ 212 void nema_set_tex_color(uint32_t color); 213 214 // ------------------------------ CONSTREGS ------------------------------------ 215 216 /** \brief Write a value to a Constant Register of the GPU 217 * 218 * \param reg Constant Register to be written 219 * \param value Value to be written 220 * 221 */ 222 void nema_set_const_reg(int reg, uint32_t value); 223 224 // --------------------------------- CLIP -------------------------------------- 225 226 /** \brief Sets the drawing area's Clipping Rectangle 227 * 228 * \param x Clip Window top-left x coordinate 229 * \param y Clip Window minimum y 230 * \param w Clip Window width 231 * \param h Clip Window height 232 * 233 */ 234 void nema_set_clip(int32_t x, int32_t y, uint32_t w, uint32_t h); 235 236 void nema_enable_gradient(int enable); 237 238 void nema_enable_depth(int enable); 239 240 /** \brief Enables MSAA per edge 241 * 242 * \param e0 Enable MSAA for edge 0 (vertices 0-1) 243 * \param e1 Enable MSAA for edge 1 (vertices 1-2) 244 * \param e2 Enable MSAA for edge 2 (vertices 2-3) 245 * \param e3 Enable MSAA for edge 3 (vertices 3-0) 246 * \return previous AA flags (may be ignored) 247 * 248 */ 249 uint32_t nema_enable_aa(uint8_t e0, uint8_t e1, uint8_t e2, uint8_t e3); 250 251 // ------------------------------- DIRTY REGIONS ------------------------------------ 252 253 /** \brief Returns the bounding rectangle of all the pixels that have been modified since its previous call. 254 * Available only on Nema|P and Nema|PVG GPUs. 255 * 256 * \param minx x coordinate of the upper left corner of the dirty region 257 * \param miny y coordinate of the upper left corner of the dirty region 258 * \param maxx x coordinate of the lower right corner of the dirty region 259 * \param maxy y coordinate of the lower right corner of the dirty region 260 * 261 */ 262 void nema_get_dirty_region(int *minx, int *miny, int *maxx, int *maxy); 263 264 /** \brief Clear dirty region information - runs via the bound command-list 265 * Available only on Nema|P and Nema|PVG GPUs. 266 * 267 * \see nema_get_dirty_region() 268 * \see nema_clear_dirty_region_imm() 269 * 270 */ 271 void nema_clear_dirty_region(void); 272 273 /** \brief Clear dirty region information immediately, no command-list involved 274 * Available only on Nema|P and Nema|PVG GPUs. 275 * 276 * \see nema_get_dirty_region() 277 * \see nema_clear_dirty_region() 278 * 279 */ 280 void nema_clear_dirty_region_imm(void); 281 282 // -------------------------------- UTILS -------------------------------------- 283 284 /** \brief Set triangle/quadrilateral culling mode 285 * 286 * \param cull Culling mode 287 * 288 */ 289 void nema_tri_cull(nema_tri_cull_t cull); 290 291 /** \brief Return pixel size in bytes 292 * 293 * \param format Color format 294 * \return Pixel size in bytes 295 * 296 */ 297 int nema_format_size (nema_tex_format_t format); 298 299 /** \brief Return stride in bytes 300 * 301 * \param format Color format 302 * \param wrap_mode Wrap/Repeat mode to be used. When using 'repeat' or 'mirror', texture dimensions must be a power of two. Otherwise the behavior is undefined. 303 * \param width Texture color format 304 * \return Stride in bytes 305 * 306 */ 307 int nema_stride_size(nema_tex_format_t format, nema_tex_mode_t wrap_mode, int width); 308 309 310 /** \brief Return texture size in bytes 311 * 312 * \param format Texture color format 313 * \param wrap_mode Wrap/Repeat mode to be used. When using 'repeat' or 'mirror', texture dimensions must be a power of two. Otherwise the behavior is undefined. 314 * \param width Texture width 315 * \param height Texture height 316 * \return Texture size in bytes 317 * 318 */ 319 int nema_texture_size(nema_tex_format_t format, nema_tex_mode_t wrap_mode, int width, int height); 320 321 /** \brief Return Nema internal RGBA color 322 * 323 * \param R Red component 324 * \param G Green component 325 * \param B Blue component 326 * \param A Alpha component 327 * \return RGBA value 328 * 329 */ 330 uint32_t nema_rgba(unsigned char R, 331 unsigned char G, 332 unsigned char B, 333 unsigned char A); 334 335 /** \brief Premultiply RGB channels with Alpha channel 336 * 337 * \param rgba RGBA color 338 * \return Premultiplied RGBA color 339 * 340 */ 341 uint32_t nema_premultiply_rgba(uint32_t rgba); 342 343 /** \brief Initialize NemaGFX library 344 * 345 * \return negative value on error 346 * 347 */ 348 int nema_init(void); 349 350 /** \brief Reinitialize NemaGFX library 351 * 352 * \details This function reinitializes the NemaGFX library after a GPU poweroff 353 * No memory allocation for ringbuffer etc is performed. 354 * 355 * \return negative value on error 356 * 357 */ 358 int nema_reinit(void); 359 360 // ------------------------------- CONTEXT ------------------------------------- 361 362 /** \brief Program Texture Unit with a foreground (source) texture (NEMA_TEX1) 363 * 364 * \param baseaddr_phys Address of the source texture, as seen by the GPU 365 * \param width Texture width 366 * \param height Texture hight 367 * \param format Texture format 368 * \param stride Texture stride. If negative, it's calculated internally. 369 * \param wrap_mode Wrap/Repeat mode to be used. When using 'repeat' or 'mirror', texture dimensions must be a power of two. Otherwise the behavior is undefined. 370 * 371 */ 372 void nema_bind_src_tex(uintptr_t baseaddr_phys, 373 uint32_t width, uint32_t height, 374 nema_tex_format_t format, int32_t stride, nema_tex_mode_t mode); 375 376 /** \brief Program Texture Unit with a background texture ((NEMA_TEX2) 377 * 378 * \param baseaddr_phys Address of the source2 texture, as seen by the GPU 379 * \param width Texture width 380 * \param height Texture hight 381 * \param format Texture format 382 * \param stride Texture stride. If negative, it's calculated internally. 383 * \param wrap_mode Wrap/Repeat mode to be used. When using 'repeat' or 'mirror', texture dimensions must be a power of two. Otherwise the behavior is undefined. 384 * 385 */ 386 void nema_bind_src2_tex(uintptr_t baseaddr_phys, 387 uint32_t width, uint32_t height, 388 nema_tex_format_t format, int32_t stride, nema_tex_mode_t mode); 389 390 /** \brief Program Texture Unit with a destination texture (NEMA_TEX0) 391 * 392 * \param baseaddr_phys Address of the destination texture, as seen by the GPU 393 * \param width Texture width 394 * \param height Texture hight 395 * \param format Texture format 396 * \param stride Texture stride. If negative, it's calculated internally. 397 * 398 */ 399 void nema_bind_dst_tex(uintptr_t baseaddr_phys, 400 uint32_t width, uint32_t height, 401 nema_tex_format_t format, int32_t stride); 402 403 /** \brief Program Texture Unit with a lut/palette texture (NEMA_TEX2) and index texture (NEMA_TEX1_) 404 * 405 * \param baseaddr_phys Address of the index texture 406 * \param width Index texture width 407 * \param height Index texture hight 408 * \param format Index texture format 409 * \param stride Index texture stride. If negative, it's calculated internally. 410 * \param mode Index texture sampling mode. When using 'NEMA_TEX_REPEAT' or 'NEMA_TEX_MIRROR' wrapping mode, 411 * texture dimensions must be a power of two, otherwise the behavior is undefined. NEMA_FILTER_BL is not supported. 412 * \param palette_baseaddr_phys Address of the lut/palette texture 413 * \param palette_format lut/palette texture format 414 * 415 */ 416 void nema_bind_lut_tex( uintptr_t baseaddr_phys, 417 uint32_t width, uint32_t height, 418 nema_tex_format_t format, int32_t stride, nema_tex_mode_t mode, 419 uintptr_t palette_baseaddr_phys, 420 nema_tex_format_t palette_format); 421 422 /** \brief Bind Depth Buffer 423 * 424 * \param baseaddr_phys Address of the depth buffer, as seen by the GPU 425 * \param width Buffer width 426 * \param height Buffer hight 427 * 428 */ 429 void nema_bind_depth_buffer(uintptr_t baseaddr_phys, 430 uint32_t width, uint32_t height); 431 432 /** \private */ 433 // -------------------------------- DEPTH -------------------------------------- 434 void nema_set_depth(float start, float dx, float dy); 435 436 // ------------------------------ GRADIENT ------------------------------------- 437 /** \private */ 438 void nema_set_gradient(float r_init, float g_init, float b_init, float a_init, 439 float r_dx, float r_dy, 440 float g_dx, float g_dy, 441 float b_dx, float b_dy, 442 float a_dx, float a_dy); 443 444 // ------------------------------- DRAWING ------------------------------------- 445 /** \brief Clear destination texture with color 446 * 447 * \param rgba8888 32-bit RGBA color 448 * \see nema_rgba() 449 * 450 */ 451 void nema_clear(uint32_t rgba8888); 452 453 /** \brief Clear depth buffer with specified value 454 * 455 * \param val Clear value 456 * 457 */ 458 void nema_clear_depth(uint32_t val); 459 460 /** \brief Draw a colored line 461 * 462 * \param x0 x coordinate at the beginning of the line 463 * \param y0 y coordinate at the beginning of the line 464 * \param x1 x coordinate at the end of the line 465 * \param y1 y coordinate at the end of the line 466 * \param rgba8888 Color to be used 467 * \see nema_set_blend_fill() 468 * \see nema_rgba() 469 * 470 */ 471 void nema_draw_line(int x0, int y0, int x1, int y1, uint32_t rgba8888); 472 473 474 /** \brief Draw a line with width. Apply AA if available 475 * 476 * \param x0 x coordinate at the beginning of the line 477 * \param y0 y coordinate at the beginning of the line 478 * \param x1 x coordinate at the end of the line 479 * \param y1 y coordinate at the end of the line 480 * \param w line width 481 * \param rgba8888 Color to be used 482 * \see nema_draw_line() 483 * \see nema_set_blend_fill() 484 * \see nema_rgba() 485 * 486 */ 487 void 488 nema_draw_line_aa(float x0, float y0, float x1, float y1, float w, 489 uint32_t rgba8888); 490 491 /** \brief Draw a colored circle with 1 pixel width 492 * 493 * \param x x coordinate of the circle's center 494 * \param y y coordinate of the circle's center 495 * \param r circle's radius 496 * \param rgba8888 Color to be used 497 * \see nema_set_blend_fill() 498 * \see nema_rgba() 499 * 500 */ 501 void nema_draw_circle(int x, int y, int r, uint32_t rgba8888); 502 503 /** \brief Draw a colored circle with Anti-Aliasing (if available) and specified width 504 * 505 * \param x x coordinate of the circle's center 506 * \param y y coordinate of the circle's center 507 * \param r circle's radius 508 * \param w pencil width 509 * \param rgba8888 Color to be used 510 * \see nema_set_blend_fill() 511 * \see nema_rgba() 512 * 513 */ 514 void nema_draw_circle_aa(float x, float y, float r, float w, uint32_t rgba8888); 515 516 /** \brief Draw a colored rectangle with rounded edges 517 * 518 * \param x0 x coordinate of the upper left vertex of the rectangle 519 * \param y0 y coordinate at the upper left vertex of the rectangle 520 * \param w width of the rectangle 521 * \param h height of the rectangle 522 * \param r corner radius 523 * \param rgba8888 524 * \see nema_set_blend_fill() 525 * \see nema_rgba() 526 * 527 */ 528 void nema_draw_rounded_rect(int x0, int y0, int w, int h, int r, uint32_t rgba8888); 529 530 /** \brief Draw a colored rectangle 531 * 532 * \param x x coordinate of the upper left vertex of the rectangle 533 * \param y y coordinate at the upper left vertex of the rectangle 534 * \param w width of the rectangle 535 * \param h height of the rectangle 536 * \param rgba8888 Color to be used 537 * \see nema_set_blend_fill() 538 * \see nema_rgba() 539 * 540 */ 541 void nema_draw_rect(int x, int y, int w, int h, uint32_t rgba8888); 542 543 /** \brief Fill a circle with color 544 * 545 * \param x x coordinate of the circle's center 546 * \param y y coordinate of the circle's center 547 * \param r circle's radius 548 * \param rgba8888 Color to be used 549 * \see nema_set_blend_fill() 550 * \see nema_rgba() 551 * 552 */ 553 void nema_fill_circle(int x, int y, int r, uint32_t rgba8888); 554 555 /** \brief Fill a circle with color, use Anti-Aliasing if available 556 * 557 * \param x x coordinate of the circle's center 558 * \param y y coordinate of the circle's center 559 * \param r circle's radius 560 * \param rgba8888 Color to be used 561 * \see nema_set_blend_fill() 562 * \see nema_rgba() 563 * 564 */ 565 void nema_fill_circle_aa(float x, float y, float r, uint32_t rgba8888); 566 567 /** \brief Fill a triangle with color 568 * 569 * \param x0 x coordinate at the first vertex of the triangle 570 * \param y0 y coordinate at the first vertex of the triangle 571 * \param x1 x coordinate at the second vertex of the triangle 572 * \param y1 y coordinate at the second vertex of the triangle 573 * \param x2 x coordinate at the third vertex of the triangle 574 * \param y2 y coordinate at the third vertex of the triangle 575 * \param rgba8888 Color to be used 576 * \see nema_set_blend_fill() 577 * 578 */ 579 void nema_fill_triangle(int x0, int y0, int x1, int y1, int x2, int y2, uint32_t rgba8888); 580 581 /** \brief Fill a rectangle with rounded edges with color 582 * 583 * \param x0 x coordinate of the upper left vertex of the rectangle 584 * \param y0 y coordinate at the upper left vertex of the rectangle 585 * \param w width of the rectangle 586 * \param h height of the rectangle 587 * \param r corner radius 588 * \param rgba8888 589 * \see nema_set_blend_fill() 590 * \see nema_rgba() 591 * 592 */ 593 void nema_fill_rounded_rect(int x0, int y0, int w, int h, int r, uint32_t rgba8888); 594 595 /** \brief Fill a rectangle with color 596 * 597 * \param x x coordinate of the upper left vertex of the rectangle 598 * \param y y coordinate at the upper left vertex of the rectangle 599 * \param w width of the rectangle 600 * \param h height of the rectangle 601 * \param rgba8888 Color to be used 602 * \see nema_set_blend_fill() 603 * \see nema_rgba() 604 * 605 */ 606 void nema_fill_rect(int x, int y, int w, int h, uint32_t rgba8888); 607 608 /** \brief Fill a quadrilateral with color 609 * 610 * \param x0 x coordinate at the first vertex of the quadrilateral 611 * \param y0 y coordinate at the first vertex of the quadrilateral 612 * \param x1 x coordinate at the second vertex of the quadrilateral 613 * \param y1 y coordinate at the second vertex of the quadrilateral 614 * \param x2 x coordinate at the third vertex of the quadrilateral 615 * \param y2 y coordinate at the third vertex of the quadrilateral 616 * \param x3 x coordinate at the fourth vertex of the quadrilateral 617 * \param y3 y coordinate at the fourth vertex of the quadrilateral 618 * \param rgba8888 Color to be used 619 * \see nema_set_blend_fill() 620 * \see nema_rgba() 621 * 622 */ 623 void nema_fill_quad(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t rgba8888); 624 625 626 /** \brief Fill a rectangle with color (float coordinates) 627 * 628 * \param x x coordinate of the upper left vertex of the rectangle 629 * \param y y coordinate at the upper left vertex of the rectangle 630 * \param w width of the rectangle 631 * \param h height of the rectangle 632 * \param rgba8888 Color to be used 633 * \see nema_set_blend_fill() 634 * \see nema_rgba() 635 * 636 */ 637 void nema_fill_rect_f(float x, float y, float w, float h, uint32_t rgba8888); 638 639 640 /** \brief Fill a quadrilateral with color (float coordinates) 641 * 642 * \param x0 x coordinate at the first vertex of the quadrilateral 643 * \param y0 y coordinate at the first vertex of the quadrilateral 644 * \param x1 x coordinate at the second vertex of the quadrilateral 645 * \param y1 y coordinate at the second vertex of the quadrilateral 646 * \param x2 x coordinate at the third vertex of the quadrilateral 647 * \param y2 y coordinate at the third vertex of the quadrilateral 648 * \param x3 x coordinate at the fourth vertex of the quadrilateral 649 * \param y3 y coordinate at the fourth vertex of the quadrilateral 650 * \param rgba8888 Color to be used 651 * \see nema_set_blend_fill() 652 * \see nema_rgba() 653 * 654 */ 655 void nema_fill_quad_f(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, uint32_t rgba8888); 656 657 658 /** \brief Fill a triangle with color (float coordinates) 659 * 660 * \param x0 x coordinate at the first vertex of the triangle 661 * \param y0 y coordinate at the first vertex of the triangle 662 * \param x1 x coordinate at the second vertex of the triangle 663 * \param y1 y coordinate at the second vertex of the triangle 664 * \param x2 x coordinate at the third vertex of the triangle 665 * \param y2 y coordinate at the third vertex of the triangle 666 * \param rgba8888 Color to be used 667 * \see nema_set_blend_fill() 668 * 669 */ 670 void nema_fill_triangle_f(float x0, float y0, float x1, float y1, float x2, float y2, uint32_t rgba8888); 671 672 673 // ------------------------------- BLITTING ------------------------------------ 674 675 /** \brief Blit source texture to destination texture 676 * 677 * \param x destination x coordinate 678 * \param y destination y coordinate 679 * \see nema_set_blend_fill() 680 * 681 */ 682 void nema_blit (int x, int y); 683 684 685 /** \brief Blit source texture to destination texture with rounded corners 686 * 687 * \param x destination x coordinate 688 * \param y destination y coordinate 689 * \param r destination corner radius 690 * \see nema_set_blend_fill() 691 * 692 */ 693 void nema_blit_rounded (int x, int y, int r); 694 695 /** \brief Blit source texture to destination's specified rectangle (crop or wrap when needed) 696 * 697 * \param x destination x coordinate 698 * \param y destination y coordinate 699 * \param w destination width 700 * \param h destination height 701 * \see nema_set_blend_blit() 702 * 703 */ 704 void nema_blit_rect (int x, int y, int w, int h); 705 706 /** \brief Blit part of a source texture to destination's specified rectangle (crop or wrap when needed) 707 * 708 * \param x destination x coordinate 709 * \param y destination y coordinate 710 * \param w destination width 711 * \param h destination height 712 * \param x source x coordinate 713 * \param y source y coordinate 714 * \see nema_blit_subrect() 715 * \see nema_set_blend_blit() 716 * 717 */ 718 void nema_blit_subrect(int dst_x, int dst_y, int w, int h, int src_x, int src_y); 719 720 /** \brief Blit source texture to destination. Fit (scale) texture to specified rectangle. 721 * 722 * \param x destination x coordinate 723 * \param y destination y coordinate 724 * \param w destination width 725 * \param h destination height 726 * \see nema_set_blend_blit() 727 * 728 */ 729 void nema_blit_rect_fit(int x, int y, int w, int h); 730 731 732 /** \brief Blit part of source texture to destination. Fit (scale) texture to specified rectangle. 733 * 734 * \param x destination x coordinate 735 * \param y destination y coordinate 736 * \param w destination width 737 * \param h destination height 738 * \param x source x coordinate 739 * \param y source y coordinate 740 * \param w source width 741 * \param h source height 742 * \see nema_blit_rect_fit() 743 * \see nema_set_blend_blit() 744 * 745 */ 746 void nema_blit_subrect_fit( int dst_x, int dst_y, int dst_w, int dst_h, 747 int src_x, int src_y, int src_w, int src_h); 748 749 /** \brief Rotate around pivot point and Blit source texture. 750 * 751 * \param cx destination rotation center x coordinate 752 * \param cy destination rotation center y coordinate 753 * \param px source pivot point x coordinate 754 * \param py source pivot point y coordinate 755 * \param degrees_cw degrees of clockwise rotation in range [0, 360] 756 * \see nema_set_blend_blit() 757 * 758 */ 759 void nema_blit_rotate_pivot( float cx, float cy, 760 float px, float py, float degrees_cw ); 761 762 /** \brief Rotate and Blit source texture to destination. 763 * 764 * \param x destination x coordinate 765 * \param y destination y coordinate 766 * \param rotation Rotation to be done 767 * \see nema_set_blend_blit() 768 * 769 */ 770 void nema_blit_rotate(int x, int y, uint32_t rotation); 771 772 /** \brief Rotate and Blit partial source texture to destination. 773 * 774 * \param sx source upper left x coordinate 775 * \param sy source upper left y coordinate 776 * \param sw source width of partial region 777 * \param sh source height of partial region 778 * \param x destination x coordinate 779 * \param y destination y coordinate 780 * \param rotation Rotation to be done 781 * \see nema_set_blend_blit() 782 * 783 */ 784 void nema_blit_rotate_partial(int sx, int sy, 785 int sw, int sh, 786 int x, int y, 787 uint32_t rotation); 788 789 790 /** \brief Blit source texture to destination. Fit texture to specified triangle. 791 * 792 * \param dx0 x coordinate at the first vertex of the triangle 793 * \param dy0 y coordinate at the first vertex of the triangle 794 * \param v0 in [0, 3] indicates the corner of the texture that fits to the first vertex of the triangle 795 * 0 _ _ 1 796 * |_ _| 797 * 3 2 798 * \param dx1 x coordinate at the second vertex of the triangle 799 * \param dy1 y coordinate at the second vertex of the triangle 800 * \param v1 in [0, 3] indicates the corner of the texture that fits to the second vertex of the triangle 801 * \param dx2 x coordinate at the third vertex of the triangle 802 * \param dy2 y coordinate at the third vertex of the triangle 803 * \param v2 in [0, 3] indicates the corner of the texture that fits to the third vertex of the triangle 804 * \see nema_set_blend_blit() 805 * 806 */ 807 void nema_blit_tri_fit (float dx0, float dy0, int v0, 808 float dx1, float dy1, int v1, 809 float dx2, float dy2, int v2); 810 811 /** \brief Blit a triangular part of the source tecture to a triangular destination area 812 * 813 * \param dx0 x coordinate at the first vertex of the destination triangle 814 * \param dy0 y coordinate at the first vertex of the destination triangle 815 * \param dw0 w coordinate at the first vertex of the destination triangle 816 * \param dx1 x coordinate at the second vertex of the destination triangle 817 * \param dy1 y coordinate at the second vertex of the destination triangle 818 * \param dw1 w coordinate at the second vertex of the destination triangle 819 * \param dx2 x coordinate at the third vertex of the destination triangle 820 * \param dy2 y coordinate at the third vertex of the destination triangle 821 * \param dw2 w coordinate at the third vertex of the destination triangle 822 * \param sx0 x coordinate at the first vertex of the source triangle 823 * \param sy0 y coordinate at the first vertex of the source triangle 824 * \param sx1 x coordinate at the second vertex of the source triangle 825 * \param sy1 y coordinate at the second vertex of the source triangle 826 * \param sx2 x coordinate at the third vertex of the source triangle 827 * \param sy2 y coordinate at the third vertex of the source triangle 828 * \see nema_set_blend_blit() 829 * 830 */ 831 void nema_blit_tri_uv (float dx0, float dy0, float dw0, 832 float dx1, float dy1, float dw1, 833 float dx2, float dy2, float dw2, 834 float sx0, float sy0, 835 float sx1, float sy1, 836 float sx2, float sy2 837 ); 838 839 /** \brief Blit source texture to destination. Fit texture to specified quadrilateral. 840 * 841 * \param dx0 x coordinate at the first vertex of the quadrilateral 842 * \param dy0 y coordinate at the first vertex of the quadrilateral 843 * \param dx1 x coordinate at the second vertex of the quadrilateral 844 * \param dy1 y coordinate at the second vertex of the quadrilateral 845 * \param dx2 x coordinate at the third vertex of the quadrilateral 846 * \param dy2 y coordinate at the third vertex of the quadrilateral 847 * \param dx3 x coordinate at the fourth vertex of the quadrilateral 848 * \param dy3 y coordinate at the fourth vertex of the quadrilateral 849 * \see nema_set_blend_blit() 850 * \see nema_blit_subrect_quad_fit() 851 * 852 */ 853 void nema_blit_quad_fit (float dx0, float dy0, 854 float dx1, float dy1, 855 float dx2, float dy2, 856 float dx3, float dy3); 857 858 /** \brief Blit source texture to destination. Fit rectangulare area of texture to specified quadrilateral. 859 * 860 * \param dx0 x coordinate at the first vertex of the quadrilateral 861 * \param dy0 y coordinate at the first vertex of the quadrilateral 862 * \param dx1 x coordinate at the second vertex of the quadrilateral 863 * \param dy1 y coordinate at the second vertex of the quadrilateral 864 * \param dx2 x coordinate at the third vertex of the quadrilateral 865 * \param dy2 y coordinate at the third vertex of the quadrilateral 866 * \param dx3 x coordinate at the fourth vertex of the quadrilateral 867 * \param dy3 y coordinate at the fourth vertex of the quadrilateral 868 * \param sx x coordinate of the top left corner of the texture's rectangular area to be blitted 869 * \param sy y coordinate of the top left corner of the texture's rectangular area to be blitted 870 * \param sw width of the texture's rectangular area to be blitted 871 * \param sh height of the texture's rectangular area to be blitted 872 * \see nema_set_blend_blit() 873 * \see nema_blit_quad_fit() 874 * 875 */ 876 void nema_blit_subrect_quad_fit(float dx0, float dy0, 877 float dx1, float dy1, 878 float dx2, float dy2, 879 float dx3, float dy3, 880 int sx, int sy, 881 int sw, int sh); 882 883 /** \brief Blit source texture to destination. Use the matrix provided by the user. 884 * 885 * \param dx0 x coordinate at the first vertex of the quadrilateral 886 * \param dy0 y coordinate at the first vertex of the quadrilateral 887 * \param dx1 x coordinate at the second vertex of the quadrilateral 888 * \param dy1 y coordinate at the second vertex of the quadrilateral 889 * \param dx2 x coordinate at the third vertex of the quadrilateral 890 * \param dy2 y coordinate at the third vertex of the quadrilateral 891 * \param dx3 x coordinate at the fourth vertex of the quadrilateral 892 * \param dy3 y coordinate at the fourth vertex of the quadrilateral 893 * \param m 3x3 matrix (screen coordinates to texture coordinates) 894 * \see nema_set_blend_blit() 895 * 896 */ 897 void nema_blit_quad_m(float dx0, float dy0, 898 float dx1, float dy1, 899 float dx2, float dy2, 900 float dx3, float dy3, nema_matrix3x3_t m); 901 902 903 904 905 /** \brief Enable breakpoints 906 * 907 * \see nema_brk_disable() 908 * 909 */ 910 void nema_brk_enable(void); 911 912 /** \brief Disable breakpoints 913 * 914 * \see nema_brk_enable() 915 * 916 */ 917 void nema_brk_disable(void); 918 919 920 /** \brief Add a breakpoint to the current Command List 921 * 922 * \return Breakpoint ID 923 * 924 */ 925 int nema_brk_add(void); 926 927 /** \brief Add a breakpoint to the current Command List 928 * 929 * \param brk_id Breakpoint ID to wait for. If zero (0), wait until next Breakpoint 930 * \return ID of reached Breakpoint 931 * 932 */ 933 int nema_brk_wait(int brk_id); 934 935 /** \brief Instruct the GPU to resume execution 936 * 937 * 938 */ 939 void nema_brk_continue(void); 940 941 /** \brief Enable external hold signals 942 * 943 * \param hold_id Hold signals to be enabled [0-3] 944 * \see nema_ext_hold_disable() 945 * 946 */ 947 void nema_ext_hold_enable(uint32_t hold_id); 948 949 /** \brief Disable external hold signals 950 * 951 * \param hold_id Hold signals to be disabled [0-3] 952 * \see nema_ext_hold_enable() 953 * 954 */ 955 void nema_ext_hold_disable(uint32_t hold_id); 956 957 /** \brief Enable Interrupt Request when GPU reaches hold point 958 * 959 * \param hold_id Hold signals' IRQ to be enabled [0-3] 960 * \see nema_ext_hold_disable() 961 * 962 */ 963 void nema_ext_hold_irq_enable(uint32_t hold_id); 964 965 /** \brief Disable external hold signals 966 * 967 * \param hold_id Hold signals' IRQ to be disabled [0-3] 968 * \see nema_ext_hold_enable() 969 * 970 */ 971 void nema_ext_hold_irq_disable(uint32_t hold_id); 972 973 974 /** \brief Assert hold signals internally via a Command List 975 * 976 * \param hold_id Hold signal to be asserted 977 * \param stop If not zero, force Command List Processor to wait for FLAG to be deasserted 978 * \see nema_ext_hold_deassert() 979 * 980 */ 981 void nema_ext_hold_assert(uint32_t hold_id, int stop); 982 983 /** \brief Dessert hold signals internally via a Command List 984 * 985 * \param hold_id Hold signal to be deasserted 986 * \see nema_ext_hold_assert() 987 * 988 */ 989 void nema_ext_hold_deassert(uint32_t hold_id); 990 991 /** \brief Assert hold signals from the CPU (no Command List) 992 * 993 * \param hold_id Hold signal to be asserted 994 * \see nema_ext_hold_deassert() 995 * 996 */ 997 void nema_ext_hold_assert_imm(uint32_t hold_id); 998 999 /** \brief Dessert hold signals from the CPU (no Command List) 1000 * 1001 * \param hold_id Hold signal to be deasserted 1002 * \see nema_ext_hold_assert() 1003 * 1004 */ 1005 void nema_ext_hold_deassert_imm(uint32_t hold_id); 1006 1007 /** \brief Check for which architeture is the library compiled 1008 * 1009 * \return Returns string with the architecture name 1010 * 1011 */ 1012 const char* nema_get_sw_device_name(void); 1013 1014 1015 #ifdef __cplusplus 1016 } 1017 #endif 1018 1019 #endif 1020