<commit_before>/* This is an implementation file to be included after certain #defines have been set.
See a particular renderer's *.c file for specifics. */

#ifndef DEGPERRAD
#define DEGPERRAD 57.2957795f
#endif

#ifndef RADPERDEG
#define RADPERDEG 0.0174532925f
#endif







// All shapes start this way for setup and so they can access the blit buffer properly
#define BEGIN_UNTEXTURED(function_name, shape, num_additional_vertices, num_additional_indices) \
    if(target == NULL) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_NULL_ARGUMENT, "target"); \
        return; \
    } \
    if(renderer != target->renderer) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "Mismatched renderer"); \
        return; \
    } \
     \
    makeContextCurrent(renderer, target); \
    if(renderer->current_context_target == NULL) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "NULL context"); \
        return; \
    } \
     \
    if(!bindFramebuffer(renderer, target)) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); \
        return; \
    } \
     \
    prepareToRenderToTarget(renderer, target); \
    prepareToRenderShapes(renderer, shape); \
     \
    GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; \
     \
    if(cdata->blit_buffer_num_vertices + (num_additional_vertices) >= cdata->blit_buffer_max_num_vertices) \
    { \
        if(!growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + (num_additional_vertices))) \
            renderer->FlushBlitBuffer(renderer); \
    } \
    if(cdata->index_buffer_num_vertices + (num_additional_indices) >= cdata->index_buffer_max_num_vertices) \
    { \
        if(!growIndexBuffer(cdata, cdata->index_buffer_num_vertices + (num_additional_indices))) \
            renderer->FlushBlitBuffer(renderer); \
    } \
     \
    float* blit_buffer = cdata->blit_buffer; \
    unsigned short* index_buffer = cdata->index_buffer; \
     \
    int vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
    int color_index = GPU_BLIT_BUFFER_COLOR_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
     \
    float r, g, b, a; \
    if(target->use_color) \
    { \
        r = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.r, color.r); \
        g = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.g, color.g); \
        b = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.b, color.b); \
        a = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(GET_ALPHA(target->color), GET_ALPHA(color)); \
    } \
    else \
    { \
        r = color.r/255.0f; \
        g = color.g/255.0f; \
        b = color.b/255.0f; \
        a = GET_ALPHA(color)/255.0f; \
    } \
    unsigned short blit_buffer_starting_index = cdata->blit_buffer_num_vertices; \
    (void)blit_buffer_starting_index;





static float SetLineThickness(GPU_Renderer* renderer, float thickness)
{
    if(renderer->current_context_target == NULL)
        return 1.0f;
    
	float old = renderer->current_context_target->context->line_thickness;
	if(old != thickness)
        renderer->FlushBlitBuffer(renderer);
    
	renderer->current_context_target->context->line_thickness = thickness;
	glLineWidth(thickness);
	return old;
}

static float GetLineThickness(GPU_Renderer* renderer)
{
    return renderer->current_context_target->context->line_thickness;
}

static void Pixel(GPU_Renderer* renderer, GPU_Target* target, float x, float y, SDL_Color color)
{
    BEGIN_UNTEXTURED("GPU_Pixel", GL_POINTS, 1, 1);
    
    SET_UNTEXTURED_VERTEX(x, y, r, g, b, a);
}

static void Line(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
{
    BEGIN_UNTEXTURED("GPU_Line", GL_LINES, 2, 2);
    
    SET_UNTEXTURED_VERTEX(x1, y1, r, g, b, a);
    SET_UNTEXTURED_VERTEX(x2, y2, r, g, b, a);
}

// Arc() might call Circle()
static void Circle(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, 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)
{
    float originalSA = start_angle;

    if(start_angle > end_angle)
    {
        float swapa = end_angle;
        end_angle = start_angle;
        start_angle = swapa;
    }
    if(start_angle == end_angle)
        return;

    // Big angle
    if(end_angle - start_angle >= 360)
    {
        Circle(renderer, target, x, y, radius, color);<commit_msg>Changed GPU_Line() to use triangles instead of lines.<commit_after>/* This is an implementation file to be included after certain #defines have been set.
See a particular renderer's *.c file for specifics. */

#ifndef DEGPERRAD
#define DEGPERRAD 57.2957795f
#endif

#ifndef RADPERDEG
#define RADPERDEG 0.0174532925f
#endif







// All shapes start this way for setup and so they can access the blit buffer properly
#define BEGIN_UNTEXTURED(function_name, shape, num_additional_vertices, num_additional_indices) \
    if(target == NULL) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_NULL_ARGUMENT, "target"); \
        return; \
    } \
    if(renderer != target->renderer) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "Mismatched renderer"); \
        return; \
    } \
     \
    makeContextCurrent(renderer, target); \
    if(renderer->current_context_target == NULL) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "NULL context"); \
        return; \
    } \
     \
    if(!bindFramebuffer(renderer, target)) \
    { \
        GPU_PushErrorCode(function_name, GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); \
        return; \
    } \
     \
    prepareToRenderToTarget(renderer, target); \
    prepareToRenderShapes(renderer, shape); \
     \
    GPU_CONTEXT_DATA* cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; \
     \
    if(cdata->blit_buffer_num_vertices + (num_additional_vertices) >= cdata->blit_buffer_max_num_vertices) \
    { \
        if(!growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + (num_additional_vertices))) \
            renderer->FlushBlitBuffer(renderer); \
    } \
    if(cdata->index_buffer_num_vertices + (num_additional_indices) >= cdata->index_buffer_max_num_vertices) \
    { \
        if(!growIndexBuffer(cdata, cdata->index_buffer_num_vertices + (num_additional_indices))) \
            renderer->FlushBlitBuffer(renderer); \
    } \
     \
    float* blit_buffer = cdata->blit_buffer; \
    unsigned short* index_buffer = cdata->index_buffer; \
     \
    int vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
    int color_index = GPU_BLIT_BUFFER_COLOR_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
     \
    float r, g, b, a; \
    if(target->use_color) \
    { \
        r = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.r, color.r); \
        g = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.g, color.g); \
        b = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.b, color.b); \
        a = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(GET_ALPHA(target->color), GET_ALPHA(color)); \
    } \
    else \
    { \
        r = color.r/255.0f; \
        g = color.g/255.0f; \
        b = color.b/255.0f; \
        a = GET_ALPHA(color)/255.0f; \
    } \
    unsigned short blit_buffer_starting_index = cdata->blit_buffer_num_vertices; \
    (void)blit_buffer_starting_index;





static float SetLineThickness(GPU_Renderer* renderer, float thickness)
{
    if(renderer->current_context_target == NULL)
        return 1.0f;
    
	float old = renderer->current_context_target->context->line_thickness;
	if(old != thickness)
        renderer->FlushBlitBuffer(renderer);
    
	renderer->current_context_target->context->line_thickness = thickness;
	glLineWidth(thickness);
	return old;
}

static float GetLineThickness(GPU_Renderer* renderer)
{
    return renderer->current_context_target->context->line_thickness;
}

static void Pixel(GPU_Renderer* renderer, GPU_Target* target, float x, float y, SDL_Color color)
{
    BEGIN_UNTEXTURED("GPU_Pixel", GL_POINTS, 1, 1);
    
    SET_UNTEXTURED_VERTEX(x, y, r, g, b, a);
}

static void Line(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
{
    BEGIN_UNTEXTURED("GPU_Line", GL_TRIANGLES, 4, 6);
    
	float thickness = renderer->GetLineThickness(renderer);

    float t = thickness/2;
    float line_angle = atan2f(y2 - y1, x2 - x1);
    float tc = t*cosf(line_angle);
    float ts = t*sinf(line_angle);
    SET_UNTEXTURED_VERTEX(x1 + ts, y1 - tc, r, g, b, a);
    SET_UNTEXTURED_VERTEX(x1 - ts, y1 + tc, r, g, b, a);
    SET_UNTEXTURED_VERTEX(x2 + ts, y2 - tc, r, g, b, a);
    
    SET_INDEXED_VERTEX(1);
    SET_INDEXED_VERTEX(2);
    SET_UNTEXTURED_VERTEX(x2 - ts, y2 + tc, r, g, b, a);
}

// Arc() might call Circle()
static void Circle(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, 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)
{
    float originalSA = start_angle;

    if(start_angle > end_angle)
    {
        float swapa = end_angle;
        end_angle = start_angle;
        start_angle = swapa;
    }
    if(start_angle == end_angle)
        return;

    // Big angle
    if(end_angle - start_angle >= 360)
    {
        Circle(renderer, target, x, y, radius, color);
{'fraction_non_alphanumeric': 0.11220816620384655, 'fraction_numerical': 0.012136171963385785, 'mean_word_length': 3.3236994219653178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4220132', 'n_tokens_mistral': 3498, 'n_tokens_neox': 3412, 'n_words': 642}