5 #define DEGPERRAD 57.2957795f
9 #define RADPERDEG 0.0174532925f
19 #define BEGIN_UNTEXTURED(function_name, shape, num_additional_vertices, num_additional_indices) \
20 GPU_CONTEXT_DATA* cdata; \
22 unsigned short* index_buffer; \
26 unsigned short blit_buffer_starting_index; \
29 GPU_PushErrorCode(function_name, GPU_ERROR_NULL_ARGUMENT, "target"); \
32 if(renderer != target->renderer) \
34 GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "Mismatched renderer"); \
38 makeContextCurrent(renderer, target); \
39 if(renderer->current_context_target == NULL) \
41 GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "NULL context"); \
45 if(!bindFramebuffer(renderer, target)) \
47 GPU_PushErrorCode(function_name, GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); \
51 prepareToRenderToTarget(renderer, target); \
52 prepareToRenderShapes(renderer, shape); \
54 cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; \
56 if(cdata->blit_buffer_num_vertices + (num_additional_vertices) >= cdata->blit_buffer_max_num_vertices) \
58 if(!growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + (num_additional_vertices))) \
59 renderer->FlushBlitBuffer(renderer); \
61 if(cdata->index_buffer_num_vertices + (num_additional_indices) >= cdata->index_buffer_max_num_vertices) \
63 if(!growIndexBuffer(cdata, cdata->index_buffer_num_vertices + (num_additional_indices))) \
64 renderer->FlushBlitBuffer(renderer); \
67 blit_buffer = cdata->blit_buffer; \
68 index_buffer = cdata->index_buffer; \
70 vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
71 color_index = GPU_BLIT_BUFFER_COLOR_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
73 if(target->use_color) \
75 r = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.r, color.r); \
76 g = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.g, color.g); \
77 b = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.b, color.b); \
78 a = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(GET_ALPHA(target->color), GET_ALPHA(color)); \
85 a = GET_ALPHA(color)/255.0f; \
87 blit_buffer_starting_index = cdata->blit_buffer_num_vertices; \
88 (void)blit_buffer_starting_index;
126 float t = thickness/2;
127 float line_angle = atan2f(y2 - y1, x2 - x1);
128 float tc = t*cosf(line_angle);
129 float ts = t*sinf(line_angle);
153 if(start_angle > end_angle)
155 float swapa = end_angle;
156 end_angle = start_angle;
159 if(start_angle == end_angle)
163 if(end_angle - start_angle >= 360)
165 Circle(renderer, target, x, y, radius, color);
170 while(start_angle < 0 && end_angle < 0)
175 while(start_angle > 360 && end_angle > 360)
183 dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(radius)) *
DEGPERRAD;
185 numSegments = fabs(end_angle - start_angle)/dt;
194 dy = radius*sin(t*RADPERDEG);
198 for (i = 1; i < numSegments; i++)
200 dx = radius*cos(t*RADPERDEG);
201 dy = radius*sin(t*RADPERDEG);
208 dx = radius*cos(end_angle*RADPERDEG);
209 dy = radius*sin(end_angle*RADPERDEG);
225 if(start_angle > end_angle)
227 float swapa = end_angle;
228 end_angle = start_angle;
231 if(start_angle == end_angle)
235 if(end_angle - start_angle >= 360)
242 while(start_angle < 0 && end_angle < 0)
247 while(start_angle > 360 && end_angle > 360)
254 dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(radius)) *
DEGPERRAD;
256 numSegments = fabs(end_angle - start_angle)/dt;
267 dy = radius*sin(t*RADPERDEG);
270 dx = radius*cos(t*RADPERDEG);
271 dy = radius*sin(t*RADPERDEG);
275 for (i = 2; i < numSegments + 1; i++)
277 dx = radius*cos(t*RADPERDEG);
278 dy = radius*sin(t*RADPERDEG);
286 dx = radius*cos(end_angle*RADPERDEG);
287 dy = radius*sin(end_angle*RADPERDEG);
297 float dt = (1.25f/sqrtf(radius)) *
DEGPERRAD;
299 int numSegments = 360/dt+1;
308 for(i = 1; i < numSegments; i++)
311 dy = radius*sin(t*RADPERDEG);
323 float dt = (1.25f/sqrtf(radius)) *
DEGPERRAD;
326 int numSegments = 360/dt+1;
338 dy = radius*sin(t*RADPERDEG);
342 for(i = 2; i < numSegments; i++)
344 dx = radius*cos(t*RADPERDEG);
345 dy = radius*sin(t*RADPERDEG);
360 float dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4;
362 if(inner_radius < 0.0
f)
364 if(outer_radius < 0.0
f)
367 if(inner_radius > outer_radius)
369 float s = inner_radius;
370 inner_radius = outer_radius;
374 if(start_angle > end_angle)
376 float swapa = end_angle;
377 end_angle = start_angle;
380 if(start_angle == end_angle)
383 if(inner_radius == outer_radius)
385 Arc(renderer, target, x, y, inner_radius, start_angle, end_angle, color);
389 circled = (end_angle - start_angle >= 360);
391 Arc(renderer, target, x, y, inner_radius, start_angle, end_angle, color);
395 dx1 = inner_radius*cos(end_angle*
RADPERDEG);
396 dy1 = inner_radius*sin(end_angle*RADPERDEG);
397 dx2 = outer_radius*cos(end_angle*RADPERDEG);
398 dy2 = outer_radius*sin(end_angle*RADPERDEG);
399 Line(renderer, target, x+dx1, y+dy1, x+dx2, y+dy2, color);
402 Arc(renderer, target, x, y, outer_radius, start_angle, end_angle, color);
406 dx3 = inner_radius*cos(start_angle*
RADPERDEG);
407 dy3 = inner_radius*sin(start_angle*RADPERDEG);
408 dx4 = outer_radius*cos(start_angle*RADPERDEG);
409 dy4 = outer_radius*sin(start_angle*RADPERDEG);
410 Line(renderer, target, x+dx3, y+dy3, x+dx4, y+dy4, color);
422 if(inner_radius < 0.0
f)
424 if(outer_radius < 0.0
f)
427 if(inner_radius > outer_radius)
429 float s = inner_radius;
430 inner_radius = outer_radius;
434 if(inner_radius == outer_radius)
436 Arc(renderer, target, x, y, inner_radius, start_angle, end_angle, color);
441 if(start_angle > end_angle)
443 float swapa = end_angle;
444 end_angle = start_angle;
447 if(start_angle == end_angle)
450 if(end_angle - start_angle >= 360)
451 end_angle = start_angle + 360;
455 dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(outer_radius)) *
DEGPERRAD;
457 numSegments = fabs(end_angle - start_angle)/dt;
470 dy = inner_radius*sin(t*RADPERDEG);
473 dx = outer_radius*cos(t*RADPERDEG);
474 dy = outer_radius*sin(t*RADPERDEG);
477 dx = inner_radius*cos(t*RADPERDEG);
478 dy = inner_radius*sin(t*RADPERDEG);
482 for (i = 2; i < numSegments + 1; i++)
488 dx = inner_radius*cos(t*RADPERDEG);
489 dy = inner_radius*sin(t*RADPERDEG);
493 dx = outer_radius*cos(t*RADPERDEG);
494 dy = outer_radius*sin(t*RADPERDEG);
498 use_inner = !use_inner;
505 dx = inner_radius*cos(t*RADPERDEG);
506 dy = inner_radius*sin(t*RADPERDEG);
510 dx = outer_radius*cos(t*RADPERDEG);
511 dy = outer_radius*sin(t*RADPERDEG);
516 use_inner = !use_inner;
521 dx = inner_radius*cos(t*RADPERDEG);
522 dy = inner_radius*sin(t*RADPERDEG);
526 dx = outer_radius*cos(t*RADPERDEG);
527 dy = outer_radius*sin(t*RADPERDEG);
576 float t = thickness / 2;
645 if(radius > (x2-x1)/2)
647 if(radius > (y2-y1)/2)
648 radius = (y2 - y1) / 2;
651 float tau = 2 *
M_PI;
653 int verts_per_corner = 7;
654 float corner_angle_increment = (tau / 4) / (verts_per_corner - 1);
656 float angle = tau*0.75f;
660 BEGIN_UNTEXTURED(
"GPU_RectangleRound",
GL_LINES, 4 + 4 * (verts_per_corner - 1), 8 + 4 * (verts_per_corner - 1) * 2);
666 for (i = 1; i < verts_per_corner; i++)
670 angle += corner_angle_increment;
675 for (i = 1; i < verts_per_corner; i++)
679 angle += corner_angle_increment;
684 for (i = 1; i < verts_per_corner; i++)
688 angle += corner_angle_increment;
693 for (i = 1; i < verts_per_corner; i++)
697 angle += corner_angle_increment;
720 if(radius > (x2-x1)/2)
722 if(radius > (y2-y1)/2)
723 radius = (y2 - y1) / 2;
726 float tau = 2 *
M_PI;
728 int verts_per_corner = 7;
729 float corner_angle_increment = (tau / 4) / (verts_per_corner - 1);
732 float angle = tau*0.75f;
736 BEGIN_UNTEXTURED(
"GPU_RectangleRoundFilled",
GL_TRIANGLES, 6 + 4 * (verts_per_corner - 1) - 1, 15 + 4 * (verts_per_corner - 1) * 3 - 3);
742 angle += corner_angle_increment;
744 angle += corner_angle_increment;
746 for (i = 2; i < verts_per_corner; i++)
751 angle += corner_angle_increment;
757 for (i = 1; i < verts_per_corner; i++)
762 angle += corner_angle_increment;
768 for (i = 1; i < verts_per_corner; i++)
773 angle += corner_angle_increment;
779 for (i = 1; i < verts_per_corner; i++)
784 angle += corner_angle_increment;
800 int numSegments = 2 * num_vertices;
807 for (i = 2; i < numSegments; i += 2)
823 int numSegments = 2 * num_vertices;
833 if (num_vertices > 3)
838 for (i = 6; i < numSegments; i += 2)
static void Circle(GPU_Renderer *renderer, GPU_Target *target, float x, float y, float radius, SDL_Color color)
static void Rectangle(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, SDL_Color color)
static void ArcFilled(GPU_Renderer *renderer, GPU_Target *target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color)
static void Arc(GPU_Renderer *renderer, GPU_Target *target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color)
static float GetLineThickness(GPU_Renderer *renderer)
static void SectorFilled(GPU_Renderer *renderer, GPU_Target *target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color)
GLint GLint GLint GLint GLint GLint y
void(* FlushBlitBuffer)(GPU_Renderer *renderer)
#define BEGIN_UNTEXTURED(function_name, shape, num_additional_vertices, num_additional_indices)
GLAPI void GLAPIENTRY glLineWidth(GLfloat width)
static void RectangleRoundFilled(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, float radius, SDL_Color color)
GLdouble GLdouble GLdouble b
static void Polygon(GPU_Renderer *renderer, GPU_Target *target, unsigned int num_vertices, float *vertices, SDL_Color color)
GPU_Target * current_context_target
GLboolean GLboolean GLboolean GLboolean a
static void PolygonFilled(GPU_Renderer *renderer, GPU_Target *target, unsigned int num_vertices, float *vertices, SDL_Color color)
static void Sector(GPU_Renderer *renderer, GPU_Target *target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color)
static float SetLineThickness(GPU_Renderer *renderer, float thickness)
static void CircleFilled(GPU_Renderer *renderer, GPU_Target *target, float x, float y, float radius, SDL_Color color)
static void RectangleFilled(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, SDL_Color color)
static void TriFilled(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
GLint GLint GLint GLint GLint x
GLdouble GLdouble GLdouble r
static void Tri(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
static void Line(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, SDL_Color color)
static void RectangleRound(GPU_Renderer *renderer, GPU_Target *target, float x1, float y1, float x2, float y2, float radius, SDL_Color color)
static void Pixel(GPU_Renderer *renderer, GPU_Target *target, float x, float y, SDL_Color color)
#define SET_INDEXED_VERTEX(offset)
#define SET_UNTEXTURED_VERTEX(x, y, r, g, b, a)
float(* GetLineThickness)(GPU_Renderer *renderer)