this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added GPU_PrimitiveEnum, GPU_PrimitiveBatch(), and GPU_PrimitiveBatchV() to support rendering points, lines, and other geometric primitives. GPU_TriangleBatch() is rebased to work on this. This resolves #107.

+58 -16
+35 -3
include/SDL_gpu.h
··· 479 479 static const Uint32 GPU_NONE = 0x0; 480 480 481 481 /*! \ingroup Rendering 482 - * Bit flags for geometry batching. 482 + * Primitive types for rendering arbitrary geometry. The values are intentionally identical to the GL_* primitives. 483 + * \see GPU_PrimitiveBatch() 484 + * \see GPU_PrimitiveBatchV() 485 + */ 486 + typedef Uint32 GPU_PrimitiveEnum; 487 + static const GPU_PrimitiveEnum GPU_POINTS = 0x0; 488 + static const GPU_PrimitiveEnum GPU_LINES = 0x1; 489 + static const GPU_PrimitiveEnum GPU_LINE_LOOP = 0x2; 490 + static const GPU_PrimitiveEnum GPU_LINE_STRIP = 0x3; 491 + static const GPU_PrimitiveEnum GPU_TRIANGLES = 0x4; 492 + static const GPU_PrimitiveEnum GPU_TRIANGLE_STRIP = 0x5; 493 + static const GPU_PrimitiveEnum GPU_TRIANGLE_FAN = 0x6; 494 + 495 + 496 + /*! Bit flags for geometry batching. 483 497 * \see GPU_TriangleBatch() 484 498 * \see GPU_TriangleBatchX() 499 + * \see GPU_PrimitiveBatch() 500 + * \see GPU_PrimitiveBatchV() 485 501 */ 486 502 typedef Uint32 GPU_BatchFlagEnum; 487 503 static const GPU_BatchFlagEnum GPU_BATCH_XY = 0x1; ··· 1449 1465 DECLSPEC void SDLCALL GPU_BlitRectX(GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, GPU_Rect* dest_rect, float degrees, float pivot_x, float pivot_y, GPU_FlipEnum flip_direction); 1450 1466 1451 1467 1452 - /*! Renders triangles from the given set of vertices. This lets you render arbitrary 2D geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1468 + /*! Renders triangles from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1453 1469 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0. Pass NULL to render with only custom shader attributes. 1454 1470 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1455 1471 * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1456 1472 */ 1457 1473 DECLSPEC void SDLCALL GPU_TriangleBatch(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1458 1474 1459 - /*! Renders triangles from the given set of vertices. This lets you render arbitrary 2D geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1475 + /*! Renders triangles from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1460 1476 * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0 (or 0 - 255 for 8-bit color components). Pass NULL to render with only custom shader attributes. 1461 1477 * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1462 1478 * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1463 1479 */ 1464 1480 DECLSPEC void SDLCALL GPU_TriangleBatchX(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1481 + 1482 + /*! Renders primitives from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1483 + * \param primitive_type The kind of primitive to render. 1484 + * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0 (or 0 - 255 for 8-bit color components). Pass NULL to render with only custom shader attributes. 1485 + * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1486 + * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1487 + */ 1488 + DECLSPEC void SDLCALL GPU_PrimitiveBatch(GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1489 + 1490 + /*! Renders primitives from the given set of vertices. This lets you render arbitrary geometry. It is a direct path to the GPU, so the format is different than typical SDL_gpu calls. 1491 + * \param primitive_type The kind of primitive to render. 1492 + * \param values A tightly-packed array of vertex position (e.g. x,y), texture coordinates (e.g. s,t), and color (e.g. r,g,b,a) values. Texture coordinates and color values are expected to be already normalized to 0.0 - 1.0 (or 0 - 255 for 8-bit color components). Pass NULL to render with only custom shader attributes. 1493 + * \param indices If not NULL, this is used to specify which vertices to use and in what order (i.e. it indexes the vertices in the 'values' array). 1494 + * \param flags Bit flags to control the interpretation of the 'values' array parameters. 1495 + */ 1496 + DECLSPEC void SDLCALL GPU_PrimitiveBatchV(GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 1465 1497 1466 1498 /*! Send all buffered blitting data to the current context target. */ 1467 1499 DECLSPEC void SDLCALL GPU_FlushBlitBuffer(void);
+2 -2
include/SDL_gpu_RendererImpl.h
··· 118 118 /*! \see GPU_BlitTransformX() */ 119 119 void (SDLCALL *BlitTransformX)(GPU_Renderer* renderer, GPU_Image* image, GPU_Rect* src_rect, GPU_Target* target, float x, float y, float pivot_x, float pivot_y, float degrees, float scaleX, float scaleY); 120 120 121 - /*! \see GPU_TriangleBatchX() */ 122 - void (SDLCALL *TriangleBatchX)(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 121 + /*! \see GPU_PrimitiveBatchV() */ 122 + void (SDLCALL *PrimitiveBatchV)(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags); 123 123 124 124 /*! \see GPU_GenerateMipmaps() */ 125 125 void (SDLCALL *GenerateMipmaps)(GPU_Renderer* renderer, GPU_Image* image);
+12 -2
src/SDL_gpu.c
··· 1512 1512 1513 1513 void GPU_TriangleBatch(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 1514 1514 { 1515 - GPU_TriangleBatchX(image, target, num_vertices, (void*)values, num_indices, indices, flags); 1515 + GPU_PrimitiveBatchV(image, target, GPU_TRIANGLES, num_vertices, (void*)values, num_indices, indices, flags); 1516 1516 } 1517 1517 1518 1518 void GPU_TriangleBatchX(GPU_Image* image, GPU_Target* target, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 1519 1519 { 1520 + GPU_PrimitiveBatchV(image, target, GPU_TRIANGLES, num_vertices, values, num_indices, indices, flags); 1521 + } 1522 + 1523 + void GPU_PrimitiveBatch(GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, float* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 1524 + { 1525 + GPU_PrimitiveBatchV(image, target, primitive_type, num_vertices, (void*)values, num_indices, indices, flags); 1526 + } 1527 + 1528 + void GPU_PrimitiveBatchV(GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 1529 + { 1520 1530 if(!CHECK_RENDERER) 1521 1531 RETURN_ERROR(GPU_ERROR_USER_ERROR, "NULL renderer"); 1522 1532 MAKE_CURRENT_IF_NONE(target); ··· 1530 1540 return; 1531 1541 1532 1542 1533 - _gpu_current_renderer->impl->TriangleBatchX(_gpu_current_renderer, image, target, num_vertices, values, num_indices, indices, flags); 1543 + _gpu_current_renderer->impl->PrimitiveBatchV(_gpu_current_renderer, image, target, primitive_type, num_vertices, values, num_indices, indices, flags); 1534 1544 } 1535 1545 1536 1546
+7 -7
src/renderer_GL_common.inl
··· 4788 4788 4789 4789 4790 4790 // Assumes the right format 4791 - static void TriangleBatchX(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 4791 + static void PrimitiveBatchV(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 4792 4792 { 4793 4793 GPU_Context* context; 4794 4794 GPU_CONTEXT_DATA* cdata; ··· 4809 4809 4810 4810 if(target == NULL) 4811 4811 { 4812 - GPU_PushErrorCode("GPU_TriangleBatchX", GPU_ERROR_NULL_ARGUMENT, "target"); 4812 + GPU_PushErrorCode("GPU_PrimitiveBatchX", GPU_ERROR_NULL_ARGUMENT, "target"); 4813 4813 return; 4814 4814 } 4815 4815 if((image != NULL && renderer != image->renderer) || renderer != target->renderer) 4816 4816 { 4817 - GPU_PushErrorCode("GPU_TriangleBatchX", GPU_ERROR_USER_ERROR, "Mismatched renderer"); 4817 + GPU_PushErrorCode("GPU_PrimitiveBatchX", GPU_ERROR_USER_ERROR, "Mismatched renderer"); 4818 4818 return; 4819 4819 } 4820 4820 ··· 4827 4827 // Bind the FBO 4828 4828 if(!bindFramebuffer(renderer, target)) 4829 4829 { 4830 - GPU_PushErrorCode("GPU_TriangleBatchX", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4830 + GPU_PushErrorCode("GPU_PrimitiveBatchX", GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); 4831 4831 return; 4832 4832 } 4833 4833 ··· 4835 4835 if(using_texture) 4836 4836 prepareToRenderImage(renderer, target, image); 4837 4837 else 4838 - prepareToRenderShapes(renderer, GL_TRIANGLES); 4838 + prepareToRenderShapes(renderer, primitive_type); 4839 4839 changeViewport(target); 4840 4840 changeCamera(target); 4841 4841 ··· 5002 5002 float* vertex_pointer = (float*)(values); 5003 5003 float* texcoord_pointer = (float*)((char*)values + offset_texcoords); 5004 5004 5005 - glBegin(GL_TRIANGLES); 5005 + glBegin(primitive_type); 5006 5006 for(i = 0; i < num_indices; i++) 5007 5007 { 5008 5008 if(indices == NULL) ··· 6872 6872 impl->BlitScale = &BlitScale; \ 6873 6873 impl->BlitTransform = &BlitTransform; \ 6874 6874 impl->BlitTransformX = &BlitTransformX; \ 6875 - impl->TriangleBatchX = &TriangleBatchX; \ 6875 + impl->PrimitiveBatchV = &PrimitiveBatchV; \ 6876 6876 \ 6877 6877 impl->GenerateMipmaps = &GenerateMipmaps; \ 6878 6878 \
+2 -2
tests/renderer/main.c
··· 734 734 } 735 735 736 736 737 - static void TriangleBatchX(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 737 + static void PrimitiveBatchV(GPU_Renderer* renderer, GPU_Image* image, GPU_Target* target, GPU_PrimitiveEnum primitive_type, unsigned short num_vertices, void* values, unsigned int num_indices, unsigned short* indices, GPU_BatchFlagEnum flags) 738 738 { 739 739 GPU_Log(" %s (dummy)\n", __func__); 740 740 } ··· 1209 1209 impl->BlitScale = &BlitScale; 1210 1210 impl->BlitTransform = &BlitTransform; 1211 1211 impl->BlitTransformX = &BlitTransformX; 1212 - impl->TriangleBatchX = &TriangleBatchX; 1212 + impl->PrimitiveBatchV = &PrimitiveBatchV; 1213 1213 1214 1214 impl->GenerateMipmaps = &GenerateMipmaps; 1215 1215