Auto-formatting with clang-format

This commit is contained in:
Martin Fouilleul 2023-08-19 14:49:23 +02:00
parent 0d920670a2
commit 94b9cb2bbf
168 changed files with 42897 additions and 40823 deletions

View File

@ -1,14 +1,17 @@
AllowAllArgumentsOnNextLine: false
BreakBeforeBraces: Allman
ColumnLimit: 0
Cpp11BracedListStyle: false
ColumnLimit: 0
BreakBeforeBinaryOperators: NonAssignment
AlignOperands: AlignAfterOperator
IndentPPDirectives: BeforeHash
IndentCaseLabels: true
IndentWidth: 4
TabWidth: 4
UseTab: Never
LineEnding: LF
MaxEmptyLinesToKeep: 1
PointerAlignment: Left
SeparateDefinitionBlocks: Always
SpaceBeforeParens: Never
TabWidth: 4
UseTab: Never
ReflowComments: false

1
ext/.clang-format Normal file
View File

@ -0,0 +1 @@
DisableFormat: true

View File

@ -7,14 +7,17 @@
*
*****************************************************************/
#include"orca.h"
#include"math.h"
#include "glsl_shaders.h"
#include "math.h"
#include "orca.h"
//----------------------------------------------------------------
//NOTE(martin): GL vertex struct and identifiers
//----------------------------------------------------------------
typedef struct Vertex { float x, y; } Vertex;
typedef struct Vertex
{
float x, y;
} Vertex;
typedef struct advect_program
{
@ -156,7 +159,6 @@ GLuint compile_shader(const char* vs, const char* fs)
glAttachShader(prog, fragmentShader);
glLinkProgram(prog);
//TODO errors
int status = 0;
glGetProgramiv(prog, GL_LINK_STATUS, &status);
@ -284,7 +286,6 @@ void init_blit_residue(blit_residue_program* program)
program->bTex = glGetUniformLocation(program->prog, "bTex");
}
GLuint create_texture(int width, int height, GLenum internalFormat, GLenum format, GLenum type, char* initData)
{
GLuint texture;
@ -406,7 +407,6 @@ mouse_input mouseInput = {0};
int frameWidth = 800;
int frameHeight = 600;
ORCA_EXPORT void oc_on_mouse_down(int button)
{
mouseInput.down = true;
@ -454,7 +454,6 @@ void init_velocity_vortex()
float y = 2 * i / (float)texWidth - 1;
velocityInitData[i][j][0] = sinf(2 * M_PI * y);
velocityInitData[i][j][1] = sinf(2 * M_PI * x);
}
}
}
@ -506,7 +505,6 @@ void apply_splat(float splatPosX, float splatPosY, float radius, float splatVelX
glDrawArrays(GL_TRIANGLES, 0, 6);
frame_buffer_swap(&colorBuffer);
}
void jacobi_solve(frame_buffer* x, frame_buffer* b, float invGridSize, int iterationCount)
@ -653,8 +651,7 @@ ORCA_EXPORT void oc_on_init()
}
// init vertex buffer
static Vertex vertices[6] =
{
static Vertex vertices[6] = {
{ -1, -1 },
{ 1, -1 },
{ 1, 1 },
@ -672,7 +669,6 @@ ORCA_EXPORT void oc_on_init()
glEnableVertexAttribArray(0);
glVertexAttribPointer(blitProgram.pos, 2, GL_FLOAT, GL_FALSE, 0, 0);
for(int i = 0; i < texWidth / 2; i++)
{
for(int j = 0; j < texHeight / 2; j++)
@ -772,7 +768,6 @@ ORCA_EXPORT void oc_on_frame_refresh()
input_splat(t);
//NOTE: compute divergence of advected velocity
glUseProgram(divProgram.prog);
glBindFramebuffer(GL_FRAMEBUFFER, divBuffer[0].fbos[1]);
@ -815,9 +810,6 @@ ORCA_EXPORT void oc_on_frame_refresh()
}
#endif
//NOTE: subtract pressure gradient to advected velocity
glUseProgram(subtractProgram.prog);
glBindFramebuffer(GL_FRAMEBUFFER, velocityBuffer.fbos[1]);
@ -865,7 +857,8 @@ ORCA_EXPORT void oc_on_frame_refresh()
1 / aspectRatio, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
0, 0, 0, 1
};
/*
glUseProgram(blitResidueProgram.prog);

View File

@ -14,15 +14,24 @@ vec3 color_map(float v)
float f = floor(logv + 7.0);
float i = floor(4.0 * (logv + 7.0 - f));
if(f < 0.0) return vec3(0.0);
if(f < 1.0) return mix(vec3(1.0, 0.0, 0.0), vec3(1.0), i/4.0);
if(f < 2.0) return mix(vec3(0.0, 1.0, 0.0), vec3(1.0), i/4.0);
if(f < 3.0) return mix(vec3(0.0, 0.0, 1.0), vec3(1.0), i/4.0);
if(f < 4.0) return mix(vec3(1.0, 1.0, 0.0), vec3(1.0), i/4.0);
if(f < 5.0) return mix(vec3(1.0, 0.0, 1.0), vec3(1.0), i/4.0);
if(f < 6.0) return mix(vec3(0.0, 1.0, 1.0), vec3(1.0), i/4.0);
if(f < 7.0) return mix(vec3(1.0, 0.5, 0.0), vec3(1.0), i/4.0);
if(f < 8.0) return mix(vec3(1.0, 1.0, 1.0), vec3(1.0), i/4.0);
if(f < 0.0)
return vec3(0.0);
if(f < 1.0)
return mix(vec3(1.0, 0.0, 0.0), vec3(1.0), i / 4.0);
if(f < 2.0)
return mix(vec3(0.0, 1.0, 0.0), vec3(1.0), i / 4.0);
if(f < 3.0)
return mix(vec3(0.0, 0.0, 1.0), vec3(1.0), i / 4.0);
if(f < 4.0)
return mix(vec3(1.0, 1.0, 0.0), vec3(1.0), i / 4.0);
if(f < 5.0)
return mix(vec3(1.0, 0.0, 1.0), vec3(1.0), i / 4.0);
if(f < 6.0)
return mix(vec3(0.0, 1.0, 1.0), vec3(1.0), i / 4.0);
if(f < 7.0)
return mix(vec3(1.0, 0.5, 0.0), vec3(1.0), i / 4.0);
if(f < 8.0)
return mix(vec3(1.0, 1.0, 1.0), vec3(1.0), i / 4.0);
return vec3(1.0);
}

View File

@ -39,15 +39,24 @@ vec3 color_map(float v)
float f = floor(logv + 7.0);
float i = floor(4.0 * (logv + 7.0 - f));
if(f < 0.0) return vec3(0.0);
if(f < 1.0) return mix(vec3(1.0, 0.0, 0.0), vec3(1.0), i/4.0);
if(f < 2.0) return mix(vec3(0.0, 1.0, 0.0), vec3(1.0), i/4.0);
if(f < 3.0) return mix(vec3(0.0, 0.0, 1.0), vec3(1.0), i/4.0);
if(f < 4.0) return mix(vec3(1.0, 1.0, 0.0), vec3(1.0), i/4.0);
if(f < 5.0) return mix(vec3(1.0, 0.0, 1.0), vec3(1.0), i/4.0);
if(f < 6.0) return mix(vec3(0.0, 1.0, 1.0), vec3(1.0), i/4.0);
if(f < 7.0) return mix(vec3(1.0, 0.5, 0.0), vec3(1.0), i/4.0);
if(f < 8.0) return mix(vec3(1.0, 1.0, 1.0), vec3(1.0), i/4.0);
if(f < 0.0)
return vec3(0.0);
if(f < 1.0)
return mix(vec3(1.0, 0.0, 0.0), vec3(1.0), i / 4.0);
if(f < 2.0)
return mix(vec3(0.0, 1.0, 0.0), vec3(1.0), i / 4.0);
if(f < 3.0)
return mix(vec3(0.0, 0.0, 1.0), vec3(1.0), i / 4.0);
if(f < 4.0)
return mix(vec3(1.0, 1.0, 0.0), vec3(1.0), i / 4.0);
if(f < 5.0)
return mix(vec3(1.0, 0.0, 1.0), vec3(1.0), i / 4.0);
if(f < 6.0)
return mix(vec3(0.0, 1.0, 1.0), vec3(1.0), i / 4.0);
if(f < 7.0)
return mix(vec3(1.0, 0.5, 0.0), vec3(1.0), i / 4.0);
if(f < 8.0)
return mix(vec3(1.0, 1.0, 1.0), vec3(1.0), i / 4.0);
return vec3(1.0);
}

View File

@ -63,9 +63,9 @@ ORCA_EXPORT void oc_on_init(void)
glLinkProgram(program);
glUseProgram(program);
GLfloat vertices[] = {
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
-0.866 / 2, -0.5 / 2, 0, 0.866 / 2, -0.5 / 2, 0, 0, 0.5, 0
};
GLuint buffer;
glGenBuffers(1, &buffer);

View File

@ -62,7 +62,6 @@ void widget_begin_view(char* str)
oc_ui_box_begin(str, OC_UI_FLAG_DRAW_BORDER);
oc_ui_label(str);
}
void widget_end_view(void)
@ -217,7 +216,6 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
.size.height = { OC_UI_SIZE_PARENT, 1 } },
OC_UI_STYLE_SIZE);
oc_ui_pattern pattern = { 0 };
oc_ui_pattern_push(oc_scratch(), &pattern, (oc_ui_selector){ .kind = OC_UI_SEL_TAG, .tag = oc_ui_tag_make("checkbox") });
oc_ui_style_match_after(pattern,
@ -385,13 +383,11 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
}
}
}
}
}
}
}
oc_canvas_set_current(canvas);
oc_surface_select(surface);
oc_ui_draw();

View File

@ -6,9 +6,9 @@
* @revision:
*
*****************************************************************/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -70,7 +70,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -18,7 +18,6 @@
#define LOG_SUBSYSTEM "Main"
mg_font create_font()
{
//NOTE(martin): create font
@ -102,7 +101,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_KEYBOARD_KEY:
{
@ -127,7 +127,8 @@ int main()
y += 0.3 * factor;
}
}
} break;
}
break;
default:
break;

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -67,7 +67,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;
@ -102,8 +103,6 @@ int main()
mg_image_draw(image, (mp_rect){ 100, 100, 300, 300 });
mg_image_draw(image2, (mp_rect){ 300, 200, 300, 300 });
mg_render(surface, canvas);
mg_surface_present(surface);

View File

@ -1,6 +1,6 @@
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define MG_INCLUDE_GL_API 1
#include "milepost.h"
@ -64,7 +64,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;

View File

@ -59,7 +59,6 @@ static const char* TEST_STRING =
"faucibus eros, vel luctus justo leo vitae ante. Curabitur aliquam condimentum ipsum sit amet ultrices. Nullam ac velit semper, dapibus urna "
"sit amet, malesuada enim. Mauris ultricies nibh orci.";
mg_font create_font(const char* path)
{
//NOTE(martin): create font
@ -92,7 +91,10 @@ mg_font create_font(const char* path)
return (font);
}
enum { FONT_COUNT = 3 };
enum
{
FONT_COUNT = 3
};
int main()
{
@ -175,7 +177,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_MOUSE_BUTTON:
{
@ -193,7 +196,8 @@ int main()
tracked = false;
}
}
} break;
}
break;
case MP_EVENT_MOUSE_WHEEL:
{
@ -206,7 +210,8 @@ int main()
startX = mousePos.x / zoom - trackX;
startY = mousePos.y / zoom - trackY;
} break;
}
break;
case MP_EVENT_KEYBOARD_KEY:
{
@ -214,7 +219,8 @@ int main()
{
fontIndex = (fontIndex + 1) % FONT_COUNT;
}
} break;
}
break;
default:
break;
@ -294,7 +300,6 @@ int main()
mg_text_outlines(text);
mg_fill();
f64 startFlushTime = mp_get_time(MP_CLOCK_MONOTONIC);
mg_surface_prepare(surface);
@ -318,7 +323,6 @@ int main()
mem_arena_clear(mem_scratch());
}
for(int i = 0; i < FONT_COUNT; i++)
{
mg_font_destroy(fonts[i]);

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -65,7 +65,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_KEYBOARD_KEY:
{
@ -88,7 +89,8 @@ int main()
y += 1;
}
}
} break;
}
break;
default:
break;

View File

@ -1,6 +1,6 @@
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define MG_INCLUDE_GL_API 1
#include "milepost.h"
@ -20,7 +20,8 @@ i32 render_thread(void* user)
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;

View File

@ -6,8 +6,8 @@
* @revision:
*
*****************************************************************/
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "milepost.h"
@ -35,7 +35,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_WINDOW_RESIZE:
{
@ -48,7 +49,8 @@ int main()
event->move.content.y,
event->move.content.w,
event->move.content.h);
} break;
}
break;
case MP_EVENT_WINDOW_MOVE:
{
@ -61,7 +63,8 @@ int main()
event->move.content.y,
event->move.content.w,
event->move.content.h);
} break;
}
break;
case MP_EVENT_MOUSE_MOVE:
{
@ -70,43 +73,50 @@ int main()
event->mouse.y,
event->mouse.deltaX,
event->mouse.deltaY);
} break;
}
break;
case MP_EVENT_MOUSE_WHEEL:
{
printf("mouse wheel, delta = {%f, %f}\n",
event->mouse.deltaX,
event->mouse.deltaY);
} break;
}
break;
case MP_EVENT_MOUSE_ENTER:
{
printf("mouse enter\n");
} break;
}
break;
case MP_EVENT_MOUSE_LEAVE:
{
printf("mouse leave\n");
} break;
}
break;
case MP_EVENT_MOUSE_BUTTON:
{
printf("mouse button %i: %i\n",
event->key.code,
event->key.action == MP_KEY_PRESS ? 1 : 0);
} break;
}
break;
case MP_EVENT_KEYBOARD_KEY:
{
printf("key %i: %s\n",
event->key.code,
event->key.action == MP_KEY_PRESS ? "press" : (event->key.action == MP_KEY_RELEASE ? "release" : "repeat"));
} break;
}
break;
case MP_EVENT_KEYBOARD_CHAR:
{
printf("entered char %s\n", event->character.sequence);
} break;
}
break;
default:
break;

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -59,7 +59,8 @@ void compile_shader(GLuint shader, const char* source)
}
GLfloat vertices[] = {
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
-0.866 / 2, -0.5 / 2, 0, 0.866 / 2, -0.5 / 2, 0, 0, 0.5, 0
};
typedef struct app_data
{
@ -78,12 +79,14 @@ void process_event(app_data* app, mp_event event)
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_WINDOW_RESIZE:
{
log_info("resizing window!\n");
} break;
}
break;
default:
break;
@ -110,7 +113,6 @@ void update_and_render(app_data* app)
glUniformMatrix4fv(0, 1, false, matrix);
glBindBuffer(GL_ARRAY_BUFFER, app->vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
@ -136,12 +138,12 @@ i32 render(void* user)
glGenBuffers(1, &app->vertexBuffer);
GLfloat vertices[] = {
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
-0.866 / 2, -0.5 / 2, 0, 0.866 / 2, -0.5 / 2, 0, 0, 0.5, 0
};
glBindBuffer(GL_ARRAY_BUFFER, app->vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
unsigned int vshader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fshader = glCreateShader(GL_FRAGMENT_SHADER);
program = glCreateProgram();
@ -199,7 +201,6 @@ int main()
mg_surface_swap_interval(surface, 1);
mg_surface_deselect();
// start app
mp_window_bring_to_front(window);
mp_window_focus(window);

View File

@ -5,8 +5,8 @@
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define MG_INCLUDE_GL_API 1
#include "milepost.h"
@ -59,7 +59,6 @@
}
#endif
unsigned int program;
const char* vshaderSource =
@ -125,12 +124,12 @@ int child_main(int writeFd)
glGenBuffers(1, &vertexBuffer);
GLfloat vertices[] = {
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
-0.866 / 2, -0.5 / 2, 0, 0.866 / 2, -0.5 / 2, 0, 0, 0.5, 0
};
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
unsigned int vshader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fshader = glCreateShader(GL_FRAGMENT_SHADER);
program = glCreateProgram();
@ -169,7 +168,8 @@ int child_main(int writeFd)
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;
@ -198,7 +198,6 @@ int child_main(int writeFd)
glUniformMatrix4fv(0, 1, false, matrix);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
@ -274,7 +273,8 @@ int main(int argc, char** argv)
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -111,7 +111,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_MOUSE_BUTTON:
{
@ -129,7 +130,8 @@ int main()
tracked = false;
}
}
} break;
}
break;
case MP_EVENT_MOUSE_WHEEL:
{
@ -142,7 +144,8 @@ int main()
startX = mousePos.x - pinX * zoom;
startY = mousePos.y - pinY * zoom;
} break;
}
break;
case MP_EVENT_KEYBOARD_KEY:
{
@ -164,7 +167,8 @@ int main()
{
zoom += 0.001;
}
} break;
}
break;
case MP_KEY_DOWN:
{
@ -176,10 +180,12 @@ int main()
{
zoom -= 0.001;
}
} break;
}
break;
}
}
} break;
}
break;
default:
break;

View File

@ -4857,5 +4857,4 @@ void draw_tiger(bool singlePath, int singlePathIndex)
mg_set_color_rgba(0.000, 0.000, 0.000, 1);
mg_stroke();
}
}

View File

@ -77,12 +77,12 @@ int main()
glGenBuffers(1, &vertexBuffer);
GLfloat vertices[] = {
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
-0.866 / 2, -0.5 / 2, 0, 0.866 / 2, -0.5 / 2, 0, 0, 0.5, 0
};
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
unsigned int vshader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fshader = glCreateShader(GL_FRAGMENT_SHADER);
program = glCreateProgram();
@ -120,7 +120,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;
@ -145,7 +146,6 @@ int main()
glUniformMatrix4fv(0, 1, false, matrix);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

View File

@ -77,12 +77,12 @@ int main()
glGenBuffers(1, &vertexBuffer);
GLfloat vertices[] = {
-0.866/2, -0.5/2, 0, 0.866/2, -0.5/2, 0, 0, 0.5, 0};
-0.866 / 2, -0.5 / 2, 0, 0.866 / 2, -0.5 / 2, 0, 0, 0.5, 0
};
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
unsigned int vshader = glCreateShader(GL_VERTEX_SHADER);
unsigned int fshader = glCreateShader(GL_FRAGMENT_SHADER);
program = glCreateProgram();
@ -120,7 +120,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;
@ -145,7 +146,6 @@ int main()
glUniformMatrix4fv(0, 1, false, matrix);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

View File

@ -88,7 +88,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
default:
break;

View File

@ -10,8 +10,10 @@ typedef struct
vector_float4 col;
} my_vertex;
typedef enum { vertexInputIndexVertices = 0,
vertexInputIndexViewportSize = 1 } vertexInputIndex;
typedef enum
{
vertexInputIndexVertices = 0,
vertexInputIndexViewportSize = 1
} vertexInputIndex;
#endif //__VERTEX_H__

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include<errno.h>
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include <math.h>
@ -60,7 +60,8 @@ void debug_print_rule(ui_style_rule* rule)
{
printf("dragging: ");
}
} break;
}
break;
case UI_SEL_KEY:
printf("key=0x%llx: ", selector->key.hash);
@ -73,6 +74,7 @@ void debug_print_rule(ui_style_rule* rule)
}
printf("=> font size = %f\n", rule->style->fontSize);
}
void debug_print_size(ui_box* box, ui_axis axis, int indent)
{
debug_print_indent(indent);
@ -100,7 +102,6 @@ void debug_print_size(ui_box* box, ui_axis axis, int indent)
printf("pixels: %f\n", value);
break;
}
}
void debug_print_styles(ui_box* box, int indent)
@ -193,7 +194,6 @@ void widget_begin_view(char* str)
ui_box_begin(str, UI_FLAG_DRAW_BORDER);
ui_label(str);
}
void widget_end_view(void)
@ -256,8 +256,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
}
break;
case MP_EVENT_KEYBOARD_KEY:
{
@ -265,7 +265,8 @@ int main()
{
printDebugStyle = true;
}
} break;
}
break;
default:
break;
@ -438,7 +439,6 @@ int main()
.size.height = { UI_SIZE_PARENT, 1 } },
UI_STYLE_SIZE);
ui_pattern pattern = { 0 };
ui_pattern_push(mem_scratch(), &pattern, (ui_selector){ .kind = UI_SEL_TAG, .tag = ui_tag_make("checkbox") });
ui_style_match_after(pattern,
@ -606,7 +606,6 @@ int main()
}
}
}
}
}
}

View File

@ -6,8 +6,8 @@
* @revision:
*
*****************************************************************/
#include"platform/platform_debug.h"
#include "app_internal.h"
#include "platform/platform_debug.h"
oc_app oc_appData = { 0 };

View File

@ -9,27 +9,34 @@
#ifndef __APP_H_
#define __APP_H_
#include"util/typedefs.h"
#include"util/utf8.h"
#include "util/lists.h"
#include "util/memory.h"
#include "util/typedefs.h"
#include "util/utf8.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
//--------------------------------------------------------------------
// Typedefs, enums and constants
//--------------------------------------------------------------------
typedef struct oc_window { u64 h; } oc_window;
typedef struct oc_window
{
u64 h;
} oc_window;
typedef enum { OC_MOUSE_CURSOR_ARROW,
typedef enum
{
OC_MOUSE_CURSOR_ARROW,
OC_MOUSE_CURSOR_RESIZE_0,
OC_MOUSE_CURSOR_RESIZE_90,
OC_MOUSE_CURSOR_RESIZE_45,
OC_MOUSE_CURSOR_RESIZE_135,
OC_MOUSE_CURSOR_TEXT } oc_mouse_cursor;
OC_MOUSE_CURSOR_TEXT
} oc_mouse_cursor;
typedef i32 oc_window_style;
static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0,
@ -41,7 +48,9 @@ static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01<<0,
OC_WINDOW_STYLE_POPUPMENU = 0x01 << 6,
OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7;
typedef enum { OC_EVENT_NONE,
typedef enum
{
OC_EVENT_NONE,
OC_EVENT_KEYBOARD_MODS, //TODO: remove, keep only key?
OC_EVENT_KEYBOARD_KEY,
OC_EVENT_KEYBOARD_CHAR,
@ -59,14 +68,20 @@ typedef enum { OC_EVENT_NONE,
OC_EVENT_WINDOW_CLOSE,
OC_EVENT_PATHDROP,
OC_EVENT_FRAME,
OC_EVENT_QUIT } oc_event_type;
OC_EVENT_QUIT
} oc_event_type;
typedef enum { OC_KEY_NO_ACTION,
typedef enum
{
OC_KEY_NO_ACTION,
OC_KEY_PRESS,
OC_KEY_RELEASE,
OC_KEY_REPEAT } oc_key_action;
OC_KEY_REPEAT
} oc_key_action;
typedef enum { OC_KEY_UNKNOWN = 0,
typedef enum
{
OC_KEY_UNKNOWN = 0,
OC_KEY_SPACE = 32,
OC_KEY_APOSTROPHE = 39, /* ' */
OC_KEY_COMMA = 44, /* , */
@ -187,23 +202,28 @@ typedef enum { OC_KEY_UNKNOWN = 0,
OC_KEY_RIGHT_ALT = 346,
OC_KEY_RIGHT_SUPER = 347,
OC_KEY_MENU = 348,
OC_KEY_COUNT } oc_key_code;
OC_KEY_COUNT
} oc_key_code;
typedef enum {
typedef enum
{
OC_KEYMOD_NONE = 0x00,
OC_KEYMOD_ALT = 0x01,
OC_KEYMOD_SHIFT = 0x02,
OC_KEYMOD_CTRL = 0x04,
OC_KEYMOD_CMD = 0x08,
OC_KEYMOD_MAIN_MODIFIER = 0x16 /* CMD on Mac, CTRL on Win32 */ } oc_keymod_flags;
OC_KEYMOD_MAIN_MODIFIER = 0x16 /* CMD on Mac, CTRL on Win32 */
} oc_keymod_flags;
typedef enum {
typedef enum
{
OC_MOUSE_LEFT = 0x00,
OC_MOUSE_RIGHT = 0x01,
OC_MOUSE_MIDDLE = 0x02,
OC_MOUSE_EXT1 = 0x03,
OC_MOUSE_EXT2 = 0x04,
OC_MOUSE_BUTTON_COUNT } oc_mouse_button;
OC_MOUSE_BUTTON_COUNT
} oc_mouse_button;
typedef struct oc_key_event // keyboard and mouse buttons input
{
@ -372,7 +392,6 @@ ORCA_API int oc_alert_popup(oc_str8 title,
oc_str8 message,
oc_str8_list options);
//--------------------------------------------------------------------
// file system stuff... //TODO: move elsewhere
//--------------------------------------------------------------------
@ -381,12 +400,10 @@ ORCA_API int oc_file_remove(oc_str8 path);
ORCA_API int oc_directory_create(oc_str8 path);
#endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
#ifdef __cplusplus
} // extern "C"
#endif
#endif //__APP_H_

View File

@ -48,7 +48,6 @@ typedef struct oc_window_data
OC_PLATFORM_WINDOW_DATA
} oc_window_data;
//---------------------------------------------------------------
// Global App State
//---------------------------------------------------------------
@ -59,8 +58,10 @@ typedef struct oc_key_utf8
char label[8];
} oc_key_utf8;
enum { OC_APP_MAX_WINDOWS = 128 };
enum
{
OC_APP_MAX_WINDOWS = 128
};
typedef struct oc_app
{

View File

@ -82,6 +82,4 @@ typedef struct oc_layer
CAContext* caContext;
} oc_layer;
#endif //__OSX_APP_H_

View File

@ -12,13 +12,13 @@
#include <stdlib.h> // malloc/free
#include"lists.h"
#include"ringbuffer.h"
#include"memory.h"
#include"macros.h"
#include"platform_debug.h"
#include"platform_clock.h"
#include "graphics/graphics_surface.h"
#include "lists.h"
#include "macros.h"
#include "memory.h"
#include "platform_clock.h"
#include "platform_debug.h"
#include "ringbuffer.h"
#include "app.c"
@ -262,7 +262,8 @@ static void oc_update_keyboard_layout()
&deadKeyState,
sizeof(characters) / sizeof(UniChar),
&characterCount,
characters) != noErr)
characters)
!= noErr)
{
oc_appData.keyLabels[key].labelLen = 0;
}
@ -300,7 +301,6 @@ oc_key_code oc_label_to_key(oc_str8 label)
return (res);
}
@interface OCWindow : NSWindow
{
oc_window_data* mpWindow;
@ -308,7 +308,6 @@ oc_key_code oc_label_to_key(oc_str8 label)
- (id)initWithWindowData:(oc_window_data*)window contentRect:(NSRect)rect styleMask:(uint32)style;
@end
@interface OCKeyboardLayoutListener : NSObject
@end
@ -339,11 +338,14 @@ void oc_install_keyboard_layout_listener()
@end
@implementation OCApplication
- (void)noOpThread:(id)object
{}
{
}
//This is necessary in order to receive keyUp events when we have a key combination with Cmd.
- (void)sendEvent:(NSEvent *)event {
- (void)sendEvent:(NSEvent*)event
{
if([event type] == NSEventTypeKeyUp && ([event modifierFlags] & NSEventModifierFlagCommand))
[[self keyWindow] sendEvent:event];
else
@ -386,7 +388,9 @@ void oc_install_keyboard_layout_listener()
}
- (void)applicationWillFinishLaunching:(NSNotification*)notification
{@autoreleasepool{
{
@autoreleasepool
{
//NOTE(martin): add a menu for quit, and a corresponding key equivalent.
// this allows to quit the application when there is no window
@ -395,15 +399,17 @@ void oc_install_keyboard_layout_listener()
[NSApp setMainMenu:bar];
NSMenuItem* appMenuItem =
[bar addItemWithTitle:@"" action:NULL keyEquivalent:@""];
[bar addItemWithTitle:@""
action:NULL
keyEquivalent:@""];
NSMenu* appMenu = [[NSMenu alloc] init];
[appMenuItem setSubmenu:appMenu];
[appMenu addItemWithTitle:@"Quit"
action:@selector(terminate:)
keyEquivalent:@"q"];
}}
}
}
- (void)timerElapsed:(NSTimer*)timer
{
@ -413,7 +419,9 @@ void oc_install_keyboard_layout_listener()
}
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{@autoreleasepool{
{
@autoreleasepool
{
//WARN(martin): the order of these calls seem to matter a lot for properly showing the menu bar
// with other orderings, the menu doesn't display before the application is put out of
// focus and on focus again... This is flaky undocumented behaviour, so although it is
@ -434,7 +442,8 @@ void oc_install_keyboard_layout_listener()
[NSApp postEvent:event atStart:YES];
[NSApp stop:nil];
}}
}
}
- (BOOL)application:(NSApplication*)application openFile:(NSString*)filename
{
@ -483,15 +492,18 @@ void oc_install_keyboard_layout_listener()
//---------------------------------------------------------------
@implementation OCWindow
- (id)initWithWindowData:(oc_window_data*)window contentRect:(NSRect)rect styleMask:(uint32)style
{
mpWindow = window;
return ([self initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO]);
}
- (BOOL)canBecomeKeyWindow
{
return (!(mpWindow->style & OC_WINDOW_STYLE_NO_FOCUS));
}
/*
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
@ -1071,7 +1083,6 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
{
}
@end //@implementation OCView
//***************************************************************
@ -1083,7 +1094,9 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
//---------------------------------------------------------------
void oc_init()
{@autoreleasepool {
{
@autoreleasepool
{
if(!oc_appData.init)
{
memset(&oc_appData, 0, sizeof(oc_appData));
@ -1113,9 +1126,9 @@ void oc_init()
[NSApp run];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];
}
}}
}
}
void oc_terminate()
{
@ -1157,47 +1170,61 @@ void oc_set_cursor(oc_mouse_cursor cursor)
case OC_MOUSE_CURSOR_ARROW:
{
oc_appData.osx.cursor = [NSCursor arrowCursor];
} break;
}
break;
case OC_MOUSE_CURSOR_RESIZE_0:
{
oc_appData.osx.cursor = [[NSCursor class] performSelector:@selector(_windowResizeEastWestCursor)];
} break;
}
break;
case OC_MOUSE_CURSOR_RESIZE_90:
{
oc_appData.osx.cursor = [[NSCursor class] performSelector:@selector(_windowResizeNorthSouthCursor)];
} break;
}
break;
case OC_MOUSE_CURSOR_RESIZE_45:
{
oc_appData.osx.cursor = [[NSCursor class] performSelector:@selector(_windowResizeNorthEastSouthWestCursor)];
} break;
}
break;
case OC_MOUSE_CURSOR_RESIZE_135:
{
oc_appData.osx.cursor = [[NSCursor class] performSelector:@selector(_windowResizeNorthWestSouthEastCursor)];
} break;
}
break;
case OC_MOUSE_CURSOR_TEXT:
{
oc_appData.osx.cursor = [NSCursor IBeamCursor];
} break;
}
break;
}
[oc_appData.osx.cursor set];
}
void oc_clipboard_clear()
{@autoreleasepool{
{
@autoreleasepool
{
NSPasteboard* pb = [NSPasteboard generalPasteboard];
[pb clearContents];
}}
}
}
void oc_clipboard_set_string(oc_str8 string)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* nsString = [[NSString alloc] initWithBytes:string.ptr length:string.len encoding:NSUTF8StringEncoding];
NSPasteboard* pb = [NSPasteboard generalPasteboard];
[pb writeObjects:[[NSArray alloc] initWithObjects:nsString, nil]];
}}
}
}
oc_str8 oc_clipboard_copy_string(oc_str8 backing)
{@autoreleasepool{
{
@autoreleasepool
{
//WARN(martin): maxSize includes space for a null terminator
NSPasteboard* pb = [NSPasteboard generalPasteboard];
@ -1209,10 +1236,13 @@ oc_str8 oc_clipboard_copy_string(oc_str8 backing)
oc_str8 result = oc_str8_slice(backing, 0, len);
return (result);
}}
}
}
oc_str8 oc_clipboard_get_string(oc_arena* arena)
{@autoreleasepool{
{
@autoreleasepool
{
//WARN(martin): maxSize includes space for a null terminator
NSPasteboard* pb = [NSPasteboard generalPasteboard];
@ -1220,10 +1250,13 @@ oc_str8 oc_clipboard_get_string(oc_arena* arena)
const char* cString = [nsString UTF8String];
oc_str8 result = oc_str8_push_cstring(arena, cString);
return (result);
}}
}
}
bool oc_clipboard_has_tag(const char* tag)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* tagString = [[NSString alloc] initWithUTF8String:tag];
NSArray* tagArray = [NSArray arrayWithObjects:tagString, nil];
@ -1232,10 +1265,13 @@ bool oc_clipboard_has_tag(const char* tag)
NSString* available = [pb availableTypeFromArray:tagArray];
return (available != nil);
}}
}
}
void oc_clipboard_set_data_for_tag(const char* tag, oc_str8 string)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* tagString = [[NSString alloc] initWithUTF8String:tag];
NSArray* tagArray = [NSArray arrayWithObjects:tagString, nil];
@ -1244,10 +1280,13 @@ void oc_clipboard_set_data_for_tag(const char* tag, oc_str8 string)
NSPasteboard* pb = [NSPasteboard generalPasteboard];
[pb addTypes:tagArray owner:nil];
[pb setData:nsData forType:tagString];
}}
}
}
oc_str8 oc_clipboard_get_data_for_tag(oc_arena* arena, const char* tag)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* tagString = [[NSString alloc] initWithUTF8String:tag];
@ -1255,15 +1294,17 @@ oc_str8 oc_clipboard_get_data_for_tag(oc_arena* arena, const char* tag)
NSData* nsData = [pb dataForType:tagString];
oc_str8 result = oc_str8_push_buffer(arena, [nsData length], (char*)[nsData bytes]);
return (result);
}}
}
}
//---------------------------------------------------------------
// Window public API
//---------------------------------------------------------------
oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style style)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* window = oc_window_alloc();
if(!window)
{
@ -1288,8 +1329,6 @@ oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style s
[window->osx.nsWindow setDelegate:(id)window->osx.nsWindowDelegate];
[window->osx.nsWindow setTitle:[[NSString alloc] initWithBytes:(void*)title.ptr length:title.len encoding:NSUTF8StringEncoding]];
if(style & OC_WINDOW_STYLE_NO_TITLE)
@ -1317,7 +1356,6 @@ oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style s
[window->osx.nsWindow makeFirstResponder:view];
[window->osx.nsWindow setAcceptsMouseMovedEvents:YES];
oc_window windowHandle = oc_window_handle_from_ptr(window);
return (windowHandle);
@ -1325,7 +1363,9 @@ oc_window oc_window_create(oc_rect contentRect, oc_str8 title, oc_window_style s
}
void oc_window_destroy(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
@ -1391,13 +1431,16 @@ void* oc_window_native_pointer(oc_window window)
}
void oc_window_center(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
[windowData->osx.nsWindow center];
}
}}
}
}
bool oc_window_is_hidden(oc_window window)
{
@ -1413,7 +1456,9 @@ bool oc_window_is_hidden(oc_window window)
}
bool oc_window_is_focused(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
@ -1423,45 +1468,58 @@ bool oc_window_is_focused(oc_window window)
{
return (false);
}
}}
}
}
void oc_window_hide(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
windowData->hidden = true;
[windowData->osx.nsWindow orderOut:nil];
}
}}
}
}
void oc_window_focus(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
[windowData->osx.nsWindow makeKeyWindow];
}
}}
}
}
void oc_window_send_to_back(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
[windowData->osx.nsWindow orderBack:nil];
}
}}
}
}
void oc_window_bring_to_front(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
windowData->hidden = false;
[windowData->osx.nsWindow orderFront:nil];
}
}}
}
}
void oc_window_bring_to_front_and_focus(oc_window window)
{
@ -1489,7 +1547,9 @@ oc_rect oc_window_get_frame_rect(oc_window window)
}
void oc_window_set_frame_rect(oc_window window, oc_rect rect)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
@ -1502,10 +1562,13 @@ void oc_window_set_frame_rect(oc_window window, oc_rect rect)
};
[windowData->osx.nsWindow setFrame:frameRect display:YES];
}
}}
}
}
oc_rect oc_window_get_content_rect(oc_window window)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
{
@ -1517,7 +1580,8 @@ oc_rect oc_window_get_content_rect(oc_window window)
contentRect.origin.x,
screen.frame.size.height - contentRect.origin.y - contentRect.size.height,
contentRect.size.width,
contentRect.size.height};
contentRect.size.height
};
return (rect);
}
@ -1525,10 +1589,13 @@ oc_rect oc_window_get_content_rect(oc_window window)
{
return ((oc_rect){});
}
}}
}
}
void oc_window_set_content_rect(oc_window window, oc_rect rect)
{@autoreleasepool{
{
@autoreleasepool
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
if(windowData)
@ -1544,7 +1611,8 @@ void oc_window_set_content_rect(oc_window window, oc_rect rect)
NSRect frameRect = [windowData->osx.nsWindow frameRectForContentRect:contentRect];
[windowData->osx.nsWindow setFrame:frameRect display:YES];
}
}}
}
}
//--------------------------------------------------------------------
// platform surface
@ -1556,39 +1624,56 @@ void* oc_osx_surface_native_layer(oc_surface_data* surface)
}
oc_vec2 oc_osx_surface_contents_scaling(oc_surface_data* surface)
{@autoreleasepool{
{
@autoreleasepool
{
f32 contentsScale = [surface->layer.caLayer contentsScale];
oc_vec2 res = { contentsScale, contentsScale };
return (res);
}}
}
}
oc_vec2 oc_osx_surface_get_size(oc_surface_data* surface)
{@autoreleasepool{
{
@autoreleasepool
{
CGRect bounds = surface->layer.caLayer.bounds;
oc_vec2 res = { bounds.size.width, bounds.size.height };
return (res);
}}
}
}
bool oc_osx_surface_get_hidden(oc_surface_data* surface)
{@autoreleasepool{
{
@autoreleasepool
{
return ([surface->layer.caLayer isHidden]);
}}
}
}
void oc_osx_surface_set_hidden(oc_surface_data* surface, bool hidden)
{@autoreleasepool{
{
@autoreleasepool
{
[CATransaction begin];
[CATransaction setDisableActions:YES];
[surface->layer.caLayer setHidden:hidden];
[CATransaction commit];
}}
}
}
void oc_surface_cleanup(oc_surface_data* surface)
{@autoreleasepool{
{
@autoreleasepool
{
[surface->layer.caLayer release];
}}
}
}
void oc_surface_init_for_window(oc_surface_data* surface, oc_window_data* window)
{@autoreleasepool{
{
@autoreleasepool
{
surface->nativeLayer = oc_osx_surface_native_layer;
surface->contentsScaling = oc_osx_surface_contents_scaling;
surface->getSize = oc_osx_surface_get_size;
@ -1606,7 +1691,8 @@ void oc_surface_init_for_window(oc_surface_data* surface, oc_window_data* window
surface->layer.caLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
[window->osx.nsView.layer addSublayer:surface->layer.caLayer];
}}
}
}
//------------------------------------------------------------------------------------------------
// Remote surfaces
@ -1625,7 +1711,9 @@ oc_surface_id oc_osx_surface_remote_id(oc_surface_data* surface)
}
void oc_surface_init_remote(oc_surface_data* surface, u32 width, u32 height)
{@autoreleasepool{
{
@autoreleasepool
{
surface->nativeLayer = oc_osx_surface_native_layer;
surface->contentsScaling = oc_osx_surface_contents_scaling;
@ -1643,15 +1731,21 @@ void oc_surface_init_remote(oc_surface_data* surface, u32 width, u32 height)
surface->layer.caContext = [CAContext contextWithCGSConnection:connectionID options:dict];
[surface->layer.caContext retain];
[surface->layer.caContext setLayer:surface->layer.caLayer];
}}
}
}
void oc_osx_surface_host_connect(oc_surface_data* surface, oc_surface_id remoteID)
{@autoreleasepool{
{
@autoreleasepool
{
[(CALayerHost*)surface->layer.caLayer setContextId:(CAContextID)remoteID];
}}
}
}
void oc_surface_init_host(oc_surface_data* surface, oc_window_data* window)
{@autoreleasepool{
{
@autoreleasepool
{
surface->api = OC_HOST;
surface->nativeLayer = oc_osx_surface_native_layer;
@ -1669,7 +1763,8 @@ void oc_surface_init_host(oc_surface_data* surface, oc_window_data* window)
[surface->layer.caLayer setFrame:(CGRect){ { 0, 0 }, size }];
[window->osx.nsView.layer addSublayer:surface->layer.caLayer];
}}
}
}
oc_surface_data* oc_osx_surface_create_host(oc_window windowHandle)
{
@ -1776,6 +1871,7 @@ void oc_set_target_fps(u32 fps)
[[NSRunLoop currentRunLoop] addTimer:oc_appData.osx.frameTimer forMode:NSRunLoopCommonModes];
}
/*
void oc_begin_frame()
{
@ -1815,7 +1911,6 @@ void oc_set_live_resize_callback(oc_live_resize_callback callback, void* data)
oc_appData.liveResizeData = data;
}
void oc_pump_events(f64 timeout)
{
@autoreleasepool
@ -1918,10 +2013,10 @@ oc_str8 oc_open_dialog(oc_arena* arena,
[dialog setCanChooseFiles:YES];
}
[dialog setAllowsMultipleSelection:FALSE];
NSString* nsPath = 0;;
NSString* nsPath = 0;
;
if(defaultPath.len)
{
nsPath = [[NSString alloc] initWithBytes:defaultPath.ptr length:defaultPath.len encoding:NSUTF8StringEncoding];
@ -1983,7 +2078,8 @@ oc_str8 oc_save_dialog(oc_arena* arena,
[dialog setAllowedFileTypes:fileTypesArray];
}
NSString* nsPath = 0;;
NSString* nsPath = 0;
;
if(defaultPath.len)
{
nsPath = [[NSString alloc] initWithBytes:defaultPath.ptr length:defaultPath.len encoding:NSUTF8StringEncoding];
@ -2064,13 +2160,14 @@ int oc_alert_popup(oc_str8 title,
return (result);
}
//--------------------------------------------------------------------
// file system stuff... //TODO: move elsewhere
//--------------------------------------------------------------------
int oc_file_move(oc_str8 from, oc_str8 to)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* nsFrom = [[NSString alloc] initWithBytes:from.ptr length:from.len encoding:NSUTF8StringEncoding];
NSString* nsTo = [[NSString alloc] initWithBytes:to.ptr length:to.len encoding:NSUTF8StringEncoding];
NSError* err;
@ -2082,10 +2179,13 @@ int oc_file_move(oc_str8 from, oc_str8 to)
{
return (-1);
}
}}
}
}
int oc_file_remove(oc_str8 path)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* nsPath = [[NSString alloc] initWithBytes:path.ptr length:path.len encoding:NSUTF8StringEncoding];
NSError* err;
if([[NSFileManager defaultManager] removeItemAtPath:nsPath error:&err] == YES)
@ -2096,17 +2196,21 @@ int oc_file_remove(oc_str8 path)
{
return (-1);
}
}}
}
}
int oc_directory_create(oc_str8 path)
{@autoreleasepool{
{
@autoreleasepool
{
NSString* nsPath = [[NSString alloc] initWithBytes:path.ptr length:path.len encoding:NSUTF8StringEncoding];
NSError* err;
if([[NSFileManager defaultManager] createDirectoryAtPath:nsPath
withIntermediateDirectories:YES
attributes:nil
error:&err] == YES)
error:&err]
== YES)
{
return (0);
}
@ -2114,4 +2218,5 @@ int oc_directory_create(oc_str8 path)
{
return (-1);
}
}}
}
}

View File

@ -7,9 +7,9 @@
*
*****************************************************************/
#include<dwmapi.h>
#include "app.c"
#include "platform/platform_thread.h"
#include <dwmapi.h>
void oc_init_keys()
{
@ -297,7 +297,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.window = oc_window_handle_from_ptr(mpWindow);
event.type = OC_EVENT_WINDOW_CLOSE;
oc_queue_event(&event);
} break;
}
break;
case WM_DPICHANGED:
{
@ -313,15 +314,16 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
SWP_NOACTIVATE | SWP_NOZORDER);
//TODO: send a message
} break;
}
break;
//TODO: enter/exit size & move
case WM_WINDOWPOSCHANGED:
{
oc_win32_update_child_layers(mpWindow);
result = DefWindowProc(windowHandle, message, wParam, lParam);
} break;
}
break;
case WM_SIZING:
case WM_MOVING:
@ -338,7 +340,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
oc_queue_event(&event);
oc_win32_update_child_layers(mpWindow);
} break;
}
break;
case WM_SETFOCUS:
{
@ -346,7 +349,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.window = oc_window_handle_from_ptr(mpWindow);
event.type = OC_EVENT_WINDOW_FOCUS;
oc_queue_event(&event);
} break;
}
break;
case WM_KILLFOCUS:
{
@ -354,7 +358,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.window = oc_window_handle_from_ptr(mpWindow);
event.type = OC_EVENT_WINDOW_UNFOCUS;
oc_queue_event(&event);
} break;
}
break;
case WM_SIZE:
{
@ -376,37 +381,44 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
}
oc_queue_event(&event);
}
} break;
}
break;
case WM_LBUTTONDOWN:
{
oc_win32_process_mouse_event(mpWindow, OC_KEY_PRESS, OC_MOUSE_LEFT);
} break;
}
break;
case WM_RBUTTONDOWN:
{
oc_win32_process_mouse_event(mpWindow, OC_KEY_PRESS, OC_MOUSE_RIGHT);
} break;
}
break;
case WM_MBUTTONDOWN:
{
oc_win32_process_mouse_event(mpWindow, OC_KEY_PRESS, OC_MOUSE_MIDDLE);
} break;
}
break;
case WM_LBUTTONUP:
{
oc_win32_process_mouse_event(mpWindow, OC_KEY_RELEASE, OC_MOUSE_LEFT);
} break;
}
break;
case WM_RBUTTONUP:
{
oc_win32_process_mouse_event(mpWindow, OC_KEY_RELEASE, OC_MOUSE_RIGHT);
} break;
}
break;
case WM_MBUTTONUP:
{
oc_win32_process_mouse_event(mpWindow, OC_KEY_RELEASE, OC_MOUSE_MIDDLE);
} break;
}
break;
case WM_MOUSEMOVE:
{
@ -448,7 +460,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
}
oc_queue_event(&event);
} break;
}
break;
case WM_MOUSELEAVE:
{
@ -458,17 +471,20 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.window = oc_window_handle_from_ptr(mpWindow);
event.type = OC_EVENT_MOUSE_LEAVE;
oc_queue_event(&event);
} break;
}
break;
case WM_MOUSEWHEEL:
{
oc_win32_process_wheel_event(mpWindow, 0, (float)((i16)HIWORD(wParam)));
} break;
}
break;
case WM_MOUSEHWHEEL:
{
oc_win32_process_wheel_event(mpWindow, (float)((i16)HIWORD(wParam)), 0);
} break;
}
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
@ -487,7 +503,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.key.code = oc_convert_win32_key(HIWORD(lParam) & 0x1ff);
event.key.mods = oc_get_mod_keys();
oc_queue_event(&event);
} break;
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
@ -504,7 +521,8 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.key.code = oc_convert_win32_key(HIWORD(lParam) & 0x1ff);
event.key.mods = oc_get_mod_keys();
oc_queue_event(&event);
} break;
}
break;
case WM_CHAR:
{
@ -518,35 +536,41 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
event.character.seqLen = seq.len;
oc_queue_event(&event);
}
} break;
}
break;
case WM_SETTINGCHANGE:
{
if((u32)wParam == SPI_SETWHEELSCROLLLINES)
{
u32 wheelScrollLines;
if(SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &wheelScrollLines, 0) != 0) {
if(SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &wheelScrollLines, 0) != 0)
{
oc_appData.win32.wheelScrollLines = wheelScrollLines;
}
}
} break;
}
break;
case WM_DROPFILES:
{
//TODO
} break;
}
break;
case OC_WM_USER_DISPATCH_PROC:
{
oc_dispatch_proc proc = (oc_dispatch_proc)wParam;
void* user = (void*)lParam;
result = proc(user);
} break;
}
break;
default:
{
handled = false;
} break;
}
break;
}
if(handled == false)
@ -554,7 +578,6 @@ LRESULT oc_win32_win_proc(HWND windowHandle, UINT message, WPARAM wParam, LPARAM
result = DefWindowProc(windowHandle, message, wParam, lParam);
}
return (result);
}
@ -735,7 +758,6 @@ void oc_window_cancel_close(oc_window window)
}
}
bool oc_window_is_hidden(oc_window window)
{
oc_window_data* windowData = oc_window_ptr_from_handle(window);
@ -884,7 +906,8 @@ oc_rect oc_window_get_frame_rect(oc_window window)
frame.left / scale,
frame.top / scale,
(frame.right - frame.left) / scale,
(frame.bottom - frame.top)/scale};
(frame.bottom - frame.top) / scale
};
}
}
return (rect);
@ -958,7 +981,8 @@ oc_rect oc_window_get_content_rect(oc_window window)
origin.x / scale,
origin.y / scale,
(client.right - client.left) / scale,
(client.bottom - client.top)/scale};
(client.bottom - client.top) / scale
};
}
}
return (rect);
@ -976,7 +1000,8 @@ void oc_window_set_content_rect(oc_window window, oc_rect rect)
rect.x * scale,
rect.y * scale,
(rect.x + rect.w) * scale,
(rect.y + rect.h)*scale};
(rect.y + rect.h) * scale
};
DWORD style = GetWindowLong(windowData->win32.hWnd, GWL_STYLE);
BOOL menu = (GetMenu(windowData->win32.hWnd) != NULL);
@ -1024,7 +1049,6 @@ void oc_window_center(oc_window window)
}
}
//--------------------------------------------------------------------------------
// clipboard functions
//--------------------------------------------------------------------------------
@ -1095,7 +1119,6 @@ oc_str8 oc_clipboard_copy_string(oc_str8 backing)
return ((oc_str8){ 0 });
}
//--------------------------------------------------------------------------------
// win32 surfaces
//--------------------------------------------------------------------------------
@ -1307,7 +1330,6 @@ oc_surface_data* oc_win32_surface_create_host(oc_window window)
#include <shtypes.h>
#undef interface
oc_str8 oc_open_dialog(oc_arena* arena,
oc_str8 title,
oc_str8 defaultPath,
@ -1525,8 +1547,7 @@ int oc_alert_popup(oc_str8 title,
MultiByteToWideChar(CP_UTF8, 0, message.ptr, message.len, messageWide, messageWideSize);
messageWide[messageWideSize] = '\0';
TASKDIALOGCONFIG config =
{
TASKDIALOGCONFIG config = {
.cbSize = sizeof(TASKDIALOGCONFIG),
.hwndParent = NULL,
.hInstance = NULL,

View File

@ -16,7 +16,6 @@
#define UNICODE
#include <windows.h>
typedef struct oc_win32_window_data
{
HWND hWnd;
@ -24,6 +23,7 @@ typedef struct oc_win32_window_data
} oc_win32_window_data;
typedef struct oc_window_data oc_window_data;
typedef struct oc_layer
{
oc_window_data* parent;

View File

@ -8,11 +8,11 @@
*****************************************************************/
#define EGL_EGLEXT_PROTOTYPES
#include "app/app_internal.h"
#include "gl_loader.h"
#include "graphics_surface.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include"app/app_internal.h"
#include"graphics_surface.h"
#include"gl_loader.h"
#if OC_PLATFORM_MACOS
//NOTE: EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE on osx defaults to CGL backend, which doesn't handle SwapInterval correctly
@ -30,7 +30,6 @@
#define oc_gl_load_gles oc_gl_load_gles32
#endif
typedef struct oc_egl_surface
{
oc_surface_data interface;
@ -104,7 +103,8 @@ void oc_egl_surface_init(oc_egl_surface* surface)
EGLAttrib displayAttribs[] = {
EGL_PLATFORM_ANGLE_TYPE_ANGLE, OC_EGL_PLATFORM_ANGLE_TYPE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE,
EGL_NONE};
EGL_NONE
};
surface->eglDisplay = eglGetPlatformDisplay(EGL_PLATFORM_ANGLE_ANGLE, (void*)EGL_DEFAULT_DISPLAY, displayAttribs);
eglInitialize(surface->eglDisplay, NULL, NULL);
@ -120,7 +120,8 @@ void oc_egl_surface_init(oc_egl_surface* surface)
EGL_SAMPLE_BUFFERS, 0,
EGL_SAMPLES, EGL_DONT_CARE,
EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT,
EGL_NONE };
EGL_NONE
};
int numConfigs = 0;
eglChooseConfig(surface->eglDisplay, configAttributes, &surface->eglConfig, 1, &numConfigs);
@ -138,7 +139,8 @@ void oc_egl_surface_init(oc_egl_surface* surface)
EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE,
EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE,
EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, EGL_FALSE,
EGL_NONE};
EGL_NONE
};
surface->eglContext = eglCreateContext(surface->eglDisplay, surface->eglConfig, EGL_NO_CONTEXT, contextAttributes);
eglMakeCurrent(surface->eglDisplay, surface->eglSurface, surface->eglSurface, surface->eglContext);

View File

@ -9,8 +9,8 @@
#ifndef __EGL_SURFACE_H_
#define __EGL_SURFACE_H_
#include"graphics_surface.h"
#include "app/app.h"
#include "graphics_surface.h"
oc_surface_data* oc_egl_surface_create_for_window(oc_window window);
oc_surface_data* oc_egl_surface_create_remote(u32 width, u32 height);

View File

@ -6,10 +6,10 @@
* @revision:
*
*****************************************************************/
#include "gl_api.h"
#include "glsl_shaders.h"
#include "graphics_surface.h"
#include "util/macros.h"
#include"glsl_shaders.h"
#include"gl_api.h"
typedef struct oc_gl_image
{
@ -17,10 +17,12 @@ typedef struct oc_gl_image
GLuint texture;
} oc_gl_image;
enum oc_gl_cmd_enum {
enum oc_gl_cmd_enum
{
OC_GL_FILL,
OC_GL_STROKE,
};
typedef int oc_gl_cmd;
typedef struct oc_gl_path
@ -40,6 +42,7 @@ enum oc_gl_seg_kind_enum
OC_GL_QUADRATIC,
OC_GL_CUBIC,
};
typedef int oc_gl_seg_kind;
typedef struct oc_gl_path_elt
@ -57,6 +60,7 @@ typedef struct oc_gl_dispatch_indirect_command
u32 num_groups_z;
} oc_gl_dispatch_indirect_command;
////////////////////////////////////////////////////////////
//NOTE: these are just here for the sizes...
@ -117,7 +121,8 @@ enum
OC_GL_LAYOUT_SIZE(SCREEN_TILE, SCREEN_TILE_FIRST, VEC2)
};
enum {
enum
{
OC_GL_INPUT_BUFFERS_COUNT = 3,
OC_GL_TILE_SIZE = 16,
OC_GL_MSAA_COUNT = 8,
@ -302,19 +307,22 @@ void oc_gl_canvas_encode_path(oc_gl_canvas_backend* backend, oc_primitive* primi
backend->pathScreenExtents.x,
backend->pathScreenExtents.y,
backend->pathScreenExtents.z,
backend->pathScreenExtents.w};
backend->pathScreenExtents.w
};
path->clip = (oc_vec4){
primitive->attributes.clip.x,
primitive->attributes.clip.y,
primitive->attributes.clip.x + primitive->attributes.clip.w,
primitive->attributes.clip.y + primitive->attributes.clip.h};
primitive->attributes.clip.y + primitive->attributes.clip.h
};
path->color = (oc_vec4){
primitive->attributes.color.r,
primitive->attributes.color.g,
primitive->attributes.color.b,
primitive->attributes.color.a};
primitive->attributes.color.a
};
oc_rect srcRegion = primitive->attributes.srcRegion;
@ -322,7 +330,8 @@ void oc_gl_canvas_encode_path(oc_gl_canvas_backend* backend, oc_primitive* primi
backend->pathUserExtents.x,
backend->pathUserExtents.y,
backend->pathUserExtents.z - backend->pathUserExtents.x,
backend->pathUserExtents.w - backend->pathUserExtents.y};
backend->pathUserExtents.w - backend->pathUserExtents.y
};
if(!oc_image_is_nil(primitive->attributes.image))
{
@ -330,15 +339,18 @@ void oc_gl_canvas_encode_path(oc_gl_canvas_backend* backend, oc_primitive* primi
oc_mat2x3 srcRegionToImage = {
1 / texSize.x, 0, srcRegion.x / texSize.x,
0, 1/texSize.y, srcRegion.y/texSize.y};
0, 1 / texSize.y, srcRegion.y / texSize.y
};
oc_mat2x3 destRegionToSrcRegion = {
srcRegion.w / destRegion.w, 0, 0,
0, srcRegion.h/destRegion.h, 0};
0, srcRegion.h / destRegion.h, 0
};
oc_mat2x3 userToDestRegion = {
1, 0, -destRegion.x,
0, 1, -destRegion.y};
0, 1, -destRegion.y
};
oc_mat2x3 screenToUser = oc_mat2x3_inv(primitive->attributes.transform);
@ -554,7 +566,8 @@ static void oc_cubic_split(oc_vec2 p[4], f32 t, oc_vec2 outLeft[4], oc_vec2 outR
(1 - t) * q1.y + t * q2.y };
oc_vec2 s = { (1 - t) * r0.x + t * r1.x,
(1-t)*r0.y + t*r1.y};;
(1 - t) * r0.y + t * r1.y };
;
outLeft[0] = p[0];
outLeft[1] = q0;
@ -588,7 +601,10 @@ void oc_gl_encode_stroke_line(oc_gl_canvas_backend* backend, oc_vec2* p)
oc_gl_canvas_encode_element(backend, OC_PATH_LINE, joint1);
}
enum { OC_HULL_CHECK_SAMPLE_COUNT = 5 };
enum
{
OC_HULL_CHECK_SAMPLE_COUNT = 5
};
void oc_gl_encode_stroke_quadratic(oc_gl_canvas_backend* backend, oc_vec2* p)
{
@ -1049,8 +1065,6 @@ void oc_gl_grow_buffer_if_needed(GLuint buffer, i32 wantedSize, const char* name
}
}
void oc_gl_render_batch(oc_gl_canvas_backend* backend,
oc_wgl_surface* surface,
oc_image* images,

File diff suppressed because it is too large Load Diff

View File

@ -7,12 +7,16 @@ layout(std430) buffer;
layout(binding = 0) restrict readonly buffer pathQueueBufferSSBO
{
oc_gl_path_queue elements[];
} pathQueueBuffer;
}
pathQueueBuffer;
layout(binding = 1) restrict buffer tileQueueBufferSSBO
{
oc_gl_tile_queue elements[];
} tileQueueBuffer;
}
tileQueueBuffer;
layout(location = 0) uniform int pathQueueBufferStart;

View File

@ -7,13 +7,16 @@ layout(std430) buffer;
layout(binding = 0) coherent restrict readonly buffer screenTilesCountBufferSSBO
{
int elements[];
} screenTilesCountBuffer;
}
screenTilesCountBuffer;
layout(binding = 1) coherent restrict writeonly buffer dispatchBufferSSBO
{
oc_gl_dispatch_indirect_command elements[];
} dispatchBuffer;
}
dispatchBuffer;
layout(location = 0) uniform uint maxWorkGroupCount;

View File

@ -171,14 +171,16 @@ int side_of_segment(vec2 p, oc_gl_segment seg)
vec3 ph = { p.x, p.y, 1 };
vec3 klm = seg.implicitMatrix * ph;
side = ((klm.x * klm.x - klm.y) * klm.z < 0) ? -1 : 1;
} break;
}
break;
case OC_GL_CUBIC:
{
vec3 ph = { p.x, p.y, 1 };
vec3 klm = seg.implicitMatrix * ph;
side = (seg.sign * (klm.x * klm.x * klm.x - klm.y * klm.z) < 0) ? -1 : 1;
} break;
}
break;
}
}
}

View File

@ -7,38 +7,51 @@ layout(std430) buffer;
layout(binding = 0) restrict readonly buffer pathBufferSSBO
{
oc_gl_path elements[];
} pathBuffer;
}
pathBuffer;
layout(binding = 1) restrict readonly buffer pathQueueBufferSSBO
{
oc_gl_path_queue elements[];
} pathQueueBuffer;
}
pathQueueBuffer;
layout(binding = 2) restrict readonly buffer tileQueueBufferSSBO
{
oc_gl_tile_queue elements[];
} tileQueueBuffer;
}
tileQueueBuffer;
layout(binding = 3) coherent restrict buffer tileOpCountBufferSSBO
{
int elements[];
} tileOpCountBuffer;
}
tileOpCountBuffer;
layout(binding = 4) restrict buffer tileOpBufferSSBO
{
oc_gl_tile_op elements[];
} tileOpBuffer;
}
tileOpBuffer;
layout(binding = 5) restrict writeonly buffer screenTilesBufferSSBO
{
oc_gl_screen_tile elements[];
} screenTilesBuffer;
}
screenTilesBuffer;
layout(binding = 6) coherent restrict buffer screenTilesCountBufferSSBO
{
int elements[];
} screenTilesCountBuffer;
}
screenTilesCountBuffer;
layout(location = 0) uniform int tileSize;
layout(location = 1) uniform float scale;

View File

@ -7,22 +7,30 @@ layout(std430) buffer;
layout(binding = 0) restrict readonly buffer pathBufferSSBO
{
oc_gl_path elements[];
} pathBuffer;
}
pathBuffer;
layout(binding = 1) restrict writeonly buffer pathQueueBufferSSBO
{
oc_gl_path_queue elements[];
} pathQueueBuffer;
}
pathQueueBuffer;
layout(binding = 2) coherent restrict buffer tileQueueCountBufferSSBO
{
int elements[];
} tileQueueCountBuffer;
}
tileQueueCountBuffer;
layout(binding = 3) restrict writeonly buffer tileQueueBufferSSBO
{
oc_gl_tile_queue elements[];
} tileQueueBuffer;
}
tileQueueBuffer;
layout(location = 0) uniform int tileSize;
layout(location = 1) uniform float scale;

View File

@ -7,28 +7,37 @@ layout(std430) buffer;
layout(binding = 0) restrict readonly buffer pathBufferSSBO
{
oc_gl_path elements[];
} pathBuffer;
}
pathBuffer;
layout(binding = 1) restrict readonly buffer segmentBufferSSBO
{
oc_gl_segment elements[];
} segmentBuffer;
}
segmentBuffer;
layout(binding = 2) restrict readonly buffer tileOpBufferSSBO
{
oc_gl_tile_op elements[];
} tileOpBuffer;
}
tileOpBuffer;
layout(binding = 3) restrict readonly buffer screenTilesBufferSSBO
{
oc_gl_screen_tile elements[];
} screenTilesBuffer;
}
screenTilesBuffer;
layout(binding = 4) restrict readonly buffer screenTilesCountBufferSSBO
{
int elements[];
} screenTilesCountBuffer;
}
screenTilesCountBuffer;
layout(location = 0) uniform float scale;
layout(location = 1) uniform int msaaSampleCount;
@ -91,7 +100,8 @@ void main()
centerCoord + vec2(-0.25, 0.25),
centerCoord + vec2(+0.25, +0.25),
centerCoord + vec2(+0.25, -0.25),
centerCoord + vec2(-0.25, +0.25)};
centerCoord + vec2(-0.25, +0.25)
};
vec4 color = vec4(0);
int winding[OC_GL_MAX_SAMPLE_COUNT];

View File

@ -7,37 +7,51 @@ layout(std430) buffer;
layout(binding = 0) restrict readonly buffer elementBufferSSBO
{
oc_gl_path_elt elements[];
} elementBuffer;
}
elementBuffer;
layout(binding = 1) coherent restrict buffer segmentCountBufferSSBO
{
int elements[];
} segmentCountBuffer;
}
segmentCountBuffer;
layout(binding = 2) restrict buffer segmentBufferSSBO
{
oc_gl_segment elements[];
} segmentBuffer;
}
segmentBuffer;
layout(binding = 3) restrict buffer pathQueueBufferSSBO
{
oc_gl_path_queue elements[];
} pathQueueBuffer;
}
pathQueueBuffer;
layout(binding = 4) coherent restrict buffer tileQueueBufferSSBO
{
oc_gl_tile_queue elements[];
} tileQueueBuffer;
}
tileQueueBuffer;
layout(binding = 5) coherent restrict buffer tileOpCountBufferSSBO
{
int elements[];
} tileOpCountBuffer;
}
tileOpCountBuffer;
layout(binding = 6) restrict buffer tileOpBufferSSBO
{
oc_gl_tile_op elements[];
} tileOpBuffer;
}
tileOpBuffer;
layout(location = 0) uniform float scale;
layout(location = 1) uniform uint tileSize;
@ -63,7 +77,8 @@ void bin_to_tiles(int segIndex)
vec4 tileBox = vec4(float(x + pathArea.x),
float(y + pathArea.y),
float(x + pathArea.x + 1),
float(y + pathArea.y + 1)) * float(tileSize);
float(y + pathArea.y + 1))
* float(tileSize);
vec2 bl = { tileBox.x, tileBox.y };
vec2 br = { tileBox.z, tileBox.y };
@ -174,7 +189,8 @@ int push_segment(in vec2 p[4], int kind, int pathIndex)
c = p[1];
}
e = p[3];
} break;
}
break;
}
bool goingUp = e.y >= s.y;
@ -319,13 +335,13 @@ void quadratic_emit(vec2 p[4], int pathIndex)
float f = p[0].x * p[1].y - p[1].x * p[0].y;
float flip = (segmentBuffer.elements[segIndex].config == OC_GL_TL
|| segmentBuffer.elements[segIndex].config == OC_GL_BL)? -1 : 1;
|| segmentBuffer.elements[segIndex].config == OC_GL_BL)
? -1
: 1;
float g = flip * (p[2].x * (p[0].y - p[1].y) + p[0].x * (p[1].y - p[2].y) + p[1].x * (p[2].y - p[0].y));
segmentBuffer.elements[segIndex].implicitMatrix = (1/det)*mat3(a, d, 0.,
b, e, 0.,
c, f, g);
segmentBuffer.elements[segIndex].implicitMatrix = (1 / det) * mat3(a, d, 0., b, e, 0., c, f, g);
segmentBuffer.elements[segIndex].hullVertex = p[1];
bin_to_tiles(segIndex);
@ -748,7 +764,8 @@ void cubic_setup(vec2 p[4], int pathIndex)
p[0],
3.0 * (p[1] - p[0]),
3.0 * (p[0] + p[2] - 2 * p[1]),
3.0*(p[1] - p[2]) + p[3] - p[0]};
3.0 * (p[1] - p[2]) + p[3] - p[0]
};
//NOTE: get classification, implicit matrix, double points and inflection points
cubic_info curve = cubic_classify(c);
@ -847,19 +864,22 @@ void main()
{
vec2 p[4] = { elt.p[0] * scale, elt.p[1] * scale, vec2(0), vec2(0) };
line_setup(p, elt.pathIndex);
} break;
}
break;
case OC_GL_QUADRATIC:
{
vec2 p[4] = { elt.p[0] * scale, elt.p[1] * scale, elt.p[2] * scale, vec2(0) };
quadratic_setup(p, elt.pathIndex);
} break;
}
break;
case OC_GL_CUBIC:
{
vec2 p[4] = { elt.p[0] * scale, elt.p[1] * scale, elt.p[2] * scale, elt.p[3] * scale };
cubic_setup(p, elt.pathIndex);
} break;
}
break;
default:
break;

View File

@ -9,21 +9,23 @@
#ifndef __GRAPHICS_H_
#define __GRAPHICS_H_
#include"util/typedefs.h"
#include"platform/platform.h"
#include "app/app.h"
#include "platform/platform.h"
#include "util/typedefs.h"
//------------------------------------------------------------------------------------------
//NOTE(martin): backends selection
//------------------------------------------------------------------------------------------
typedef enum {
typedef enum
{
OC_NONE,
OC_METAL,
OC_GL,
OC_GLES,
OC_CANVAS,
OC_HOST } oc_surface_api;
OC_HOST
} oc_surface_api;
//NOTE: these macros are used to select which backend to include when building milepost
// they can be overridden by passing them to the compiler command line
@ -92,7 +94,10 @@ ORCA_API bool oc_is_surface_api_available(oc_surface_api api);
//------------------------------------------------------------------------------------------
//NOTE(martin): graphics surface
//------------------------------------------------------------------------------------------
typedef struct oc_surface { u64 h; } oc_surface;
typedef struct oc_surface
{
u64 h;
} oc_surface;
ORCA_API oc_surface oc_surface_nil(void);
ORCA_API bool oc_surface_is_nil(oc_surface surface);
@ -121,9 +126,20 @@ ORCA_API void oc_surface_host_connect(oc_surface surface, oc_surface_id remoteId
//------------------------------------------------------------------------------------------
//NOTE(martin): graphics canvas structs
//------------------------------------------------------------------------------------------
typedef struct oc_canvas { u64 h; } oc_canvas;
typedef struct oc_font { u64 h; } oc_font;
typedef struct oc_image { u64 h; } oc_image;
typedef struct oc_canvas
{
u64 h;
} oc_canvas;
typedef struct oc_font
{
u64 h;
} oc_font;
typedef struct oc_image
{
u64 h;
} oc_image;
typedef struct oc_color
{
@ -136,16 +152,23 @@ typedef struct oc_color
f32 b;
f32 a;
};
f32 c[4];
};
} oc_color;
typedef enum {OC_JOINT_MITER = 0,
typedef enum
{
OC_JOINT_MITER = 0,
OC_JOINT_BEVEL,
OC_JOINT_NONE } oc_joint_type;
OC_JOINT_NONE
} oc_joint_type;
typedef enum {OC_CAP_NONE = 0,
OC_CAP_SQUARE } oc_cap_type;
typedef enum
{
OC_CAP_NONE = 0,
OC_CAP_SQUARE
} oc_cap_type;
typedef struct oc_font_extents
{

View File

@ -8,8 +8,8 @@
*****************************************************************/
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include<math.h>
#include "platform/platform.h"
#include <math.h>
#define STB_IMAGE_IMPLEMENTATION
#if OC_PLATFORM_ORCA
@ -21,10 +21,9 @@
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb/stb_truetype.h"
#include"platform/platform_debug.h"
#include "graphics_common.h"
#include "platform/platform_debug.h"
#include "util/algebra.h"
#include"graphics_common.h"
typedef struct oc_glyph_map_entry
{
@ -89,7 +88,10 @@ typedef struct oc_graphics_handle_slot
} oc_graphics_handle_slot;
enum { OC_GRAPHICS_HANDLES_MAX_COUNT = 512 };
enum
{
OC_GRAPHICS_HANDLES_MAX_COUNT = 512
};
typedef struct oc_graphics_data
{
@ -136,7 +138,6 @@ typedef struct oc_canvas_data
static oc_graphics_data oc_graphicsData = { 0 };
void oc_graphics_init()
{
if(!oc_graphicsData.init)
@ -346,6 +347,7 @@ void oc_path_push_element(oc_canvas_data* canvas, oc_path_elt elt)
//------------------------------------------------------------------------------------------
oc_font oc_font_nil() { return ((oc_font){ .h = 0 }); }
bool oc_font_is_nil(oc_font font) { return (font.h == 0); }
oc_font oc_font_handle_alloc(oc_font_data* font)
@ -520,7 +522,8 @@ oc_font oc_font_create_from_memory(oc_str8 mem, u32 rangeCount, oc_unicode_range
elements[vertIndex].type = OC_PATH_QUADRATIC;
elements[vertIndex].p[0] = (oc_vec2){ cx, cy };
elements[vertIndex].p[1] = (oc_vec2){ x, y };
} break;
}
break;
case STBTT_vcubic:
elements[vertIndex].type = OC_PATH_CUBIC;
@ -652,7 +655,6 @@ oc_font_extents oc_font_get_scaled_extents(oc_font font, f32 emSize)
return (extents);
}
f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize)
{
oc_font_data* fontData = oc_font_data_from_handle(font);
@ -807,6 +809,7 @@ oc_rect oc_text_bounding_box(oc_font font, f32 fontSize, oc_str8 text)
//------------------------------------------------------------------------------------------
oc_canvas oc_canvas_nil() { return ((oc_canvas){ .h = 0 }); }
bool oc_canvas_is_nil(oc_canvas canvas) { return (canvas.h == 0); }
oc_canvas oc_canvas_handle_alloc(oc_canvas_data* canvas)
@ -1536,6 +1539,7 @@ void oc_arc(f32 x, f32 y, f32 r, f32 arcAngle, f32 startAngle)
//------------------------------------------------------------------------------------------
oc_image oc_image_nil() { return ((oc_image){ .h = 0 }); }
bool oc_image_is_nil(oc_image image) { return (image.h == 0); }
oc_image oc_image_create_from_rgba8(oc_surface surface, u32 width, u32 height, u8* pixels)
@ -1593,7 +1597,6 @@ oc_image oc_image_create_from_file(oc_surface surface, oc_str8 path, bool flip)
#endif // !OC_PLATFORM_ORCA
void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion)
{
oc_canvas_data* canvas = __mgCurrentCanvas;

View File

@ -13,10 +13,13 @@
//------------------------------------------------------------------------
// canvas structs
//------------------------------------------------------------------------
typedef enum { OC_PATH_MOVE,
typedef enum
{
OC_PATH_MOVE,
OC_PATH_LINE,
OC_PATH_QUADRATIC,
OC_PATH_CUBIC } oc_path_elt_type;
OC_PATH_CUBIC
} oc_path_elt_type;
typedef struct oc_path_elt
{
@ -53,7 +56,9 @@ typedef struct oc_attributes
} oc_attributes;
typedef enum { OC_CMD_FILL,
typedef enum
{
OC_CMD_FILL,
OC_CMD_STROKE,
OC_CMD_JUMP
} oc_primitive_cmd;

View File

@ -99,6 +99,7 @@ bool oc_is_surface_backend_available(oc_surface_api api)
}
oc_surface oc_surface_nil() { return ((oc_surface){ .h = 0 }); }
bool oc_surface_is_nil(oc_surface surface) { return (surface.h == 0); }
oc_surface oc_surface_create_for_window(oc_window window, oc_surface_api api)

View File

@ -8,11 +8,12 @@
#ifndef __GRAPHICS_SURFACE_H_
#define __GRAPHICS_SURFACE_H_
#include"graphics_common.h"
#include "app/app_internal.h"
#include "graphics_common.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
//---------------------------------------------------------------

View File

@ -11,7 +11,8 @@
#include <simd/simd.h>
typedef enum {
typedef enum
{
OC_MTL_FILL,
OC_MTL_STROKE,
} oc_mtl_cmd;
@ -26,7 +27,8 @@ typedef struct oc_mtl_path
int texture;
} oc_mtl_path;
typedef enum {
typedef enum
{
OC_MTL_LINE = 1,
OC_MTL_QUADRATIC,
OC_MTL_CUBIC,
@ -39,7 +41,8 @@ typedef struct oc_mtl_path_elt
vector_float2 p[4];
} oc_mtl_path_elt;
typedef enum {
typedef enum
{
OC_MTL_BL, // curve on bottom left
OC_MTL_BR, // curve on bottom right
OC_MTL_TL, // curve on top left
@ -70,17 +73,21 @@ typedef struct oc_mtl_path_queue
using namespace metal;
#endif
typedef enum { OC_MTL_OP_FILL,
typedef enum
{
OC_MTL_OP_FILL,
OC_MTL_OP_CLIP_FILL,
OC_MTL_OP_START,
OC_MTL_OP_END,
OC_MTL_OP_SEGMENT } oc_mtl_tile_op_kind;
OC_MTL_OP_SEGMENT
} oc_mtl_tile_op_kind;
typedef struct oc_mtl_tile_op
{
oc_mtl_tile_op_kind kind;
int index;
int next;
union
{
bool crossRight;
@ -104,7 +111,8 @@ typedef struct oc_mtl_screen_tile
} oc_mtl_screen_tile;
enum {
enum
{
OC_MTL_MAX_IMAGES_PER_BATCH = 30
};

View File

@ -10,9 +10,9 @@
#import <QuartzCore/CAMetalLayer.h>
#include <simd/simd.h>
#include "app/osx_app.h"
#include "graphics_surface.h"
#include "util/macros.h"
#include"app/osx_app.h"
#include "mtl_renderer.h"
@ -182,7 +182,6 @@ void oc_mtl_canvas_encode_element(oc_mtl_canvas_backend* backend, oc_path_elt_ty
}
}
void oc_mtl_encode_path(oc_mtl_canvas_backend* backend, oc_primitive* primitive, float scale)
{
int bufferIndex = backend->bufferIndex;
@ -251,7 +250,6 @@ void oc_mtl_encode_path(oc_mtl_canvas_backend* backend, oc_primitive* primitive,
path->uvTransform = simd_matrix(simd_make_float3(uvTransform.m[0] / scale, uvTransform.m[3] / scale, 0),
simd_make_float3(uvTransform.m[1] / scale, uvTransform.m[4] / scale, 0),
simd_make_float3(uvTransform.m[2], uvTransform.m[5], 1));
}
path->texture = backend->currentImageIndex;
@ -441,7 +439,8 @@ static void oc_cubic_split(oc_vec2 p[4], f32 t, oc_vec2 outLeft[4], oc_vec2 outR
(1 - t) * q1.y + t * q2.y };
oc_vec2 s = { (1 - t) * r0.x + t * r1.x,
(1-t)*r0.y + t*r1.y};;
(1 - t) * r0.y + t * r1.y };
;
outLeft[0] = p[0];
outLeft[1] = q0;
@ -918,7 +917,6 @@ void oc_mtl_render_stroke(oc_mtl_canvas_backend* backend,
}
}
void oc_mtl_grow_buffer_if_needed(oc_mtl_canvas_backend* backend, id<MTLBuffer>* buffer, u64 wantedSize)
{
u64 bufferSize = [(*buffer) length];
@ -1346,8 +1344,7 @@ void oc_mtl_canvas_render(oc_canvas_backend* interface,
@autoreleasepool
{
//NOTE: finalize
[surface->commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer)
{
[surface->commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> commandBuffer) {
oc_mtl_print_log(backend->bufferIndex, backend->logBuffer[backend->bufferIndex], backend->logOffsetBuffer[backend->bufferIndex]);
dispatch_semaphore_signal(backend->bufferSemaphore);
}];
@ -1432,14 +1429,17 @@ void oc_mtl_canvas_image_destroy(oc_canvas_backend* backendInterface, oc_image_d
}
void oc_mtl_canvas_image_upload_region(oc_canvas_backend* backendInterface, oc_image_data* imageInterface, oc_rect region, u8* pixels)
{@autoreleasepool{
{
@autoreleasepool
{
oc_mtl_image_data* image = (oc_mtl_image_data*)imageInterface;
MTLRegion mtlRegion = MTLRegionMake2D(region.x, region.y, region.w, region.h);
[image->texture replaceRegion:mtlRegion
mipmapLevel:0
withBytes:(void*)pixels
bytesPerRow:4 * region.w];
}}
}
}
const u32 OC_MTL_DEFAULT_PATH_BUFFER_LEN = (4 << 10),
OC_MTL_DEFAULT_ELT_BUFFER_LEN = (4 << 10),
@ -1466,7 +1466,8 @@ oc_canvas_backend* oc_mtl_canvas_backend_create(oc_mtl_surface* surface)
backend->interface.imageDestroy = oc_mtl_canvas_image_destroy;
backend->interface.imageUploadRegion = oc_mtl_canvas_image_upload_region;
@autoreleasepool{
@autoreleasepool
{
//NOTE: load metal library
oc_str8 shaderPath = oc_path_executable_relative(oc_scratch(), OC_STR8("mtl_renderer.metallib"));
NSString* metalFileName = [[NSString alloc] initWithBytes:shaderPath.ptr length:shaderPath.len encoding:NSUTF8StringEncoding];

View File

@ -1,13 +1,12 @@
#include <metal_simdgroup>
#include <metal_stdlib>
#include <simd/simd.h>
#include<metal_simdgroup>
#include "mtl_renderer.h"
using namespace metal;
typedef struct mtl_log_context
{
device char* buffer;
@ -204,7 +203,6 @@ void log_quadratic_bezier(thread float2* p, mtl_log_context logCtx)
mtl_log(logCtx, ")\n");
}
void log_cubic_bezier(thread float2* p, mtl_log_context logCtx)
{
mtl_log(logCtx, "(");
@ -238,7 +236,6 @@ kernel void mtl_path_setup(constant int* pathCount [[buffer(0)]],
{
const device oc_mtl_path* path = &pathBuffer[pathIndex];
//NOTE: we don't clip on the right, since we need those tiles to accurately compute
// the prefix sum of winding increments in the backprop pass.
float4 clippedBox = { max(path->box.x, path->clip.x),
@ -357,21 +354,22 @@ int mtl_side_of_segment(float2 p, const device oc_mtl_segment* seg, mtl_log_cont
float3 ph = { p.x, p.y, 1 };
float3 klm = seg->implicitMatrix * ph;
side = ((klm.x * klm.x - klm.y) * klm.z < 0) ? -1 : 1;
} break;
}
break;
case OC_MTL_CUBIC:
{
float3 ph = { p.x, p.y, 1 };
float3 klm = seg->implicitMatrix * ph;
side = (seg->sign * (klm.x * klm.x * klm.x - klm.y * klm.z) < 0) ? -1 : 1;
} break;
}
break;
}
}
}
return (side);
}
typedef struct mtl_segment_setup_context
{
device atomic_int* segmentCount;
@ -410,7 +408,8 @@ void mtl_segment_bin_to_tiles(thread mtl_segment_setup_context* context, device
float4 tileBox = (float4){ float(x + pathArea.x),
float(y + pathArea.y),
float(x + pathArea.x + 1),
float(y + pathArea.y + 1)} * float(tileSize);
float(y + pathArea.y + 1) }
* float(tileSize);
float2 bl = { tileBox.x, tileBox.y };
float2 br = { tileBox.z, tileBox.y };
@ -521,7 +520,8 @@ device oc_mtl_segment* mtl_segment_push(thread mtl_segment_setup_context* contex
c = p[1];
}
e = p[3];
} break;
}
break;
}
device oc_mtl_segment* seg = 0;
@ -676,9 +676,7 @@ void mtl_quadratic_emit(thread mtl_segment_setup_context* context,
float flip = (seg->config == OC_MTL_TL || seg->config == OC_MTL_BL) ? -1 : 1;
float g = flip * (p[2].x * (p[0].y - p[1].y) + p[0].x * (p[1].y - p[2].y) + p[1].x * (p[2].y - p[0].y));
seg->implicitMatrix = (1/det)*matrix_float3x3({a, d, 0.},
{b, e, 0.},
{c, f, g});
seg->implicitMatrix = (1 / det) * matrix_float3x3({ a, d, 0. }, { b, e, 0. }, { c, f, g });
seg->hullVertex = p[1];
@ -805,7 +803,8 @@ void mtl_cubic_slice(float2 p[4], float s0, float s1, float2 sp[4])
sp[3] = (s1 == 1) ? p[3] : mtl_cubic_blossom(p, s1, s1, s1);
}
typedef enum {
typedef enum
{
MTL_CUBIC_ERROR,
MTL_CUBIC_SERPENTINE,
MTL_CUBIC_CUSP,
@ -1154,7 +1153,8 @@ void mtl_cubic_setup(thread mtl_segment_setup_context* context, float2 p[4])
p[0],
3.0 * (p[1] - p[0]),
3.0 * (p[0] + p[2] - 2 * p[1]),
3.0*(p[1] - p[2]) + p[3] - p[0]};
3.0 * (p[1] - p[2]) + p[3] - p[0]
};
/*
mtl_log(context->log, "bezier basis: ");
@ -1247,7 +1247,6 @@ void mtl_cubic_setup(thread mtl_segment_setup_context* context, float2 p[4])
mtl_log(context->log, " ): ");
log_cubic_bezier(sp, context->log);
mtl_cubic_emit(context, curve, p, s0, s1, sp);
}
}
@ -1273,7 +1272,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
const device oc_mtl_path_queue* pathQueue = &pathQueueBuffer[elt->pathIndex];
device oc_mtl_tile_queue* tileQueues = &tileQueueBuffer[pathQueue->tileQueues];
mtl_segment_setup_context setupCtx = {.pathIndex = elt->pathIndex,
mtl_segment_setup_context setupCtx = {
.pathIndex = elt->pathIndex,
.segmentCount = segmentCount,
.segmentBuffer = segmentBuffer,
.pathQueue = pathQueue,
@ -1285,7 +1285,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
.tileSize = tileSize[0],
.log.buffer = logBuffer,
.log.offset = logOffsetBuffer,
.log.enabled = false,};
.log.enabled = false,
};
switch(elt->kind)
{
@ -1295,7 +1296,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
mtl_log(setupCtx.log, "line: ");
log_line(p, setupCtx.log);
mtl_line_setup(&setupCtx, p);
} break;
}
break;
case OC_MTL_QUADRATIC:
{
@ -1303,7 +1305,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
mtl_log(setupCtx.log, "quadratic: ");
log_quadratic_bezier(p, setupCtx.log);
mtl_quadratic_setup(&setupCtx, p);
} break;
}
break;
case OC_MTL_CUBIC:
{
@ -1311,8 +1314,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
mtl_log(setupCtx.log, "cubic: ");
log_cubic_bezier(p, setupCtx.log);
mtl_cubic_setup(&setupCtx, p);
} break;
}
break;
}
}
@ -1483,7 +1486,6 @@ kernel void mtl_merge(constant int* pathCount [[buffer(0)]],
*nextLink = firstOpIndex;
nextLink = &lastOp->next;
//NOTE: add path end op
int endOpIndex = atomic_fetch_add_explicit(tileOpCount, 1, memory_order_relaxed);
if(endOpIndex >= tileOpMax[0])
@ -1558,7 +1560,8 @@ kernel void mtl_raster(const device oc_mtl_screen_tile* screenTilesBuffer [[buff
centerCoord + float2(-0.25, 0.25),
centerCoord + float2(+0.25, +0.25),
centerCoord + float2(+0.25, -0.25),
centerCoord + float2(-0.25, +0.25)};
centerCoord + float2(-0.25, +0.25)
};
float4 color = { 0 };
int winding[OC_MTL_MAX_SAMPLE_COUNT] = { 0 };

View File

@ -7,13 +7,13 @@
*
*****************************************************************/
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
#import <QuartzCore/CAMetalLayer.h>
#import <QuartzCore/QuartzCore.h>
#include <simd/simd.h>
#include "app/osx_app.h"
#include "graphics_surface.h"
#include "util/macros.h"
#include"app/osx_app.h"
typedef struct oc_mtl_surface
{
@ -61,7 +61,9 @@ void oc_mtl_surface_acquire_command_buffer(oc_mtl_surface* surface)
}
void oc_mtl_surface_acquire_drawable(oc_mtl_surface* surface)
{@autoreleasepool{
{
@autoreleasepool
{
/*WARN(martin):
//TODO: we should stop trying to render if we detect that the app is in the background
or occluded
@ -79,7 +81,8 @@ void oc_mtl_surface_acquire_drawable(oc_mtl_surface* surface)
[surface->drawable retain];
}
}
}}
}
}
void oc_mtl_surface_prepare(oc_surface_data* interface)
{
@ -138,7 +141,6 @@ void oc_mtl_surface_set_frame(oc_surface_data* interface, oc_rect frame)
}
*/
//TODO fix that according to real scaling, depending on the monitor settings
static const f32 OC_MTL_SURFACE_CONTENTS_SCALING = 2;
@ -201,7 +203,6 @@ oc_surface_data* oc_mtl_surface_create_for_window(oc_window window)
[surface->mtlLayer retain];
surface->mtlLayer.device = surface->device;
[surface->mtlLayer setOpaque:NO];
surface->mtlLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
[surface->interface.layer.caLayer addSublayer:(CALayer*)surface->mtlLayer];

View File

@ -7,17 +7,17 @@
*
*****************************************************************/
#include "app/win32_app.h"
#include"graphics_surface.h"
#include "gl_loader.h"
#include "graphics_surface.h"
#include<GL/wglext.h>
#include "util/macros.h"
#include <GL/wglext.h>
#define OC_WGL_PROC_LIST \
OC_WGL_PROC(WGLCHOOSEPIXELFORMATARB, wglChoosePixelFormatARB) \
OC_WGL_PROC(WGLCREATECONTEXTATTRIBSARB, wglCreateContextAttribsARB) \
OC_WGL_PROC(WGLMAKECONTEXTCURRENTARB, wglMakeContextCurrentARB) \
OC_WGL_PROC(WGLSWAPINTERVALEXT, wglSwapIntervalEXT) \
OC_WGL_PROC(WGLSWAPINTERVALEXT, wglSwapIntervalEXT)
//NOTE: wgl function pointers declarations
@ -68,8 +68,7 @@ static void oc_wgl_init()
}
oc_wglDummyContext.hDC = GetDC(oc_wglDummyContext.hWnd);
PIXELFORMATDESCRIPTOR pixelFormatDesc =
{
PIXELFORMATDESCRIPTOR pixelFormatDesc = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
@ -110,7 +109,6 @@ static void oc_wgl_init()
#undef OC_WGL_PROC_LIST
typedef struct oc_wgl_surface
{
oc_surface_data interface;
@ -207,8 +205,7 @@ oc_surface_data* oc_wgl_surface_create_for_window(oc_window window)
surface->hDC = GetDC(surface->interface.layer.hWnd);
//NOTE(martin): create the pixel format and gl context
PIXELFORMATDESCRIPTOR pixelFormatDesc =
{
PIXELFORMATDESCRIPTOR pixelFormatDesc = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
@ -240,7 +237,8 @@ oc_surface_data* oc_wgl_surface_create_for_window(oc_window window)
WGL_ALPHA_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
0};
0
};
u32 numFormats = 0;
int pixelFormat = 0;
@ -257,7 +255,8 @@ oc_surface_data* oc_wgl_surface_create_for_window(oc_window window)
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 4,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0};
0
};
surface->glContext = wglCreateContextAttribsARB(surface->hDC, oc_wglDummyContext.glContext, contextAttrs);

View File

@ -1,5 +1,5 @@
#include <features.h>
#include "platform/platform_debug.h"
#include <features.h>
#undef assert

View File

@ -2,7 +2,8 @@
#define _ERRNO_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#include <features.h>
@ -12,7 +13,8 @@ extern "C" {
#ifdef __GNUC__
__attribute__((const))
#endif
int *__errno_location(void);
int*
__errno_location(void);
#define errno (*__errno_location())
#ifdef _GNU_SOURCE
@ -24,4 +26,3 @@ extern char *program_invocation_short_name, *program_invocation_name;
#endif
#endif

View File

@ -2,7 +2,8 @@
#define _FLOAT_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
int __flt_rounds(void);

View File

@ -2,7 +2,8 @@
#define _MATH_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
// NOTE(orca): not doing anything fancy for float_t and double_t
@ -24,31 +25,39 @@ int __fpclassifyl(long double);
static __inline unsigned __FLOAT_BITS(float __f)
{
union {float __f; unsigned __i;} __u;
union
{
float __f;
unsigned __i;
} __u;
__u.__f = __f;
return __u.__i;
}
static __inline unsigned long long __DOUBLE_BITS(double __f)
{
union {double __f; unsigned long long __i;} __u;
union
{
double __f;
unsigned long long __i;
} __u;
__u.__f = __f;
return __u.__i;
}
#define fpclassify(x) ( \
sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \
sizeof(x) == sizeof(double) ? __fpclassify(x) : \
__fpclassifyl(x) )
sizeof(x) == sizeof(float) ? __fpclassifyf(x) : sizeof(x) == sizeof(double) ? __fpclassify(x) \
: __fpclassifyl(x))
#define isinf(x) ( \
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \
__fpclassifyl(x) == FP_INFINITE)
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL >> 1) == 0x7ffULL << 52 \
: __fpclassifyl(x) == FP_INFINITE)
#define isnan(x) ( \
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \
__fpclassifyl(x) == FP_NAN)
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL >> 1) > 0x7ffULL << 52 \
: __fpclassifyl(x) == FP_NAN)
double acos(double);

View File

@ -2,7 +2,8 @@
#define _STDLIB_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#define abort(...) OC_ABORT(__VA_ARGS__)

View File

@ -48,7 +48,12 @@ pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
/* caller must handle the case when reduction is not needed: |x| ~<= pi/4 */
int __rem_pio2(double x, double* y)
{
union {double f; uint64_t i;} u = {x};
union
{
double f;
uint64_t i;
} u = { x };
double_t z, w, t, r, fn;
double tx[3], ty[2];
uint32_t ix;
@ -56,28 +61,38 @@ int __rem_pio2(double x, double *y)
sign = u.i >> 63;
ix = u.i >> 32 & 0x7fffffff;
if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */
if(ix <= 0x400f6a7a)
{ /* |x| ~<= 5pi/4 */
if((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */
goto medium; /* cancellation -- use medium case */
if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
if (!sign) {
if(ix <= 0x4002d97c)
{ /* |x| ~<= 3pi/4 */
if(!sign)
{
z = x - pio2_1; /* one round good to 85 bits */
y[0] = z - pio2_1t;
y[1] = (z - y[0]) - pio2_1t;
return 1;
} else {
}
else
{
z = x + pio2_1;
y[0] = z + pio2_1t;
y[1] = (z - y[0]) + pio2_1t;
return -1;
}
} else {
if (!sign) {
}
else
{
if(!sign)
{
z = x - 2 * pio2_1;
y[0] = z - 2 * pio2_1t;
y[1] = (z - y[0]) - 2 * pio2_1t;
return 2;
} else {
}
else
{
z = x + 2 * pio2_1;
y[0] = z + 2 * pio2_1t;
y[1] = (z - y[0]) + 2 * pio2_1t;
@ -85,30 +100,40 @@ int __rem_pio2(double x, double *y)
}
}
}
if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */
if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
if(ix <= 0x401c463b)
{ /* |x| ~<= 9pi/4 */
if(ix <= 0x4015fdbc)
{ /* |x| ~<= 7pi/4 */
if(ix == 0x4012d97c) /* |x| ~= 3pi/2 */
goto medium;
if (!sign) {
if(!sign)
{
z = x - 3 * pio2_1;
y[0] = z - 3 * pio2_1t;
y[1] = (z - y[0]) - 3 * pio2_1t;
return 3;
} else {
}
else
{
z = x + 3 * pio2_1;
y[0] = z + 3 * pio2_1t;
y[1] = (z - y[0]) + 3 * pio2_1t;
return -3;
}
} else {
}
else
{
if(ix == 0x401921fb) /* |x| ~= 4pi/2 */
goto medium;
if (!sign) {
if(!sign)
{
z = x - 4 * pio2_1;
y[0] = z - 4 * pio2_1t;
y[1] = (z - y[0]) - 4 * pio2_1t;
return 4;
} else {
}
else
{
z = x + 4 * pio2_1;
y[0] = z + 4 * pio2_1t;
y[1] = (z - y[0]) + 4 * pio2_1t;
@ -116,7 +141,8 @@ int __rem_pio2(double x, double *y)
}
}
}
if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
if(ix < 0x413921fb)
{ /* |x| ~< 2^20*(pi/2), medium size */
medium:
/* rint(x/(pi/2)) */
fn = (double_t)x * invpio2 + toint - toint;
@ -124,12 +150,15 @@ medium:
r = x - fn * pio2_1;
w = fn * pio2_1t; /* 1st round, good to 85 bits */
/* Matters with directed rounding. */
if (predict_false(r - w < -pio4)) {
if(predict_false(r - w < -pio4))
{
n--;
fn--;
r = x - fn * pio2_1;
w = fn * pio2_1t;
} else if (predict_false(r - w > pio4)) {
}
else if(predict_false(r - w > pio4))
{
n++;
fn++;
r = x - fn * pio2_1;
@ -139,7 +168,8 @@ medium:
u.f = y[0];
ey = u.i >> 52 & 0x7ff;
ex = ix >> 20;
if (ex - ey > 16) { /* 2nd round, good to 118 bits */
if(ex - ey > 16)
{ /* 2nd round, good to 118 bits */
t = r;
w = fn * pio2_2;
r = t - w;
@ -147,7 +177,8 @@ medium:
y[0] = r - w;
u.f = y[0];
ey = u.i >> 52 & 0x7ff;
if (ex - ey > 49) { /* 3rd round, good to 151 bits, covers all cases */
if(ex - ey > 49)
{ /* 3rd round, good to 151 bits, covers all cases */
t = r;
w = fn * pio2_3;
r = t - w;
@ -161,7 +192,8 @@ medium:
/*
* all other (large) arguments
*/
if (ix >= 0x7ff00000) { /* x is inf or NaN */
if(ix >= 0x7ff00000)
{ /* x is inf or NaN */
y[0] = y[1] = x - x;
return 0;
}
@ -170,7 +202,8 @@ medium:
u.i &= (uint64_t)-1 >> 12;
u.i |= (uint64_t)(0x3ff + 23) << 52;
z = u.f;
for (i=0; i < 2; i++) {
for(i = 0; i < 2; i++)
{
tx[i] = (double)(int32_t)z;
z = (z - tx[i]) * 0x1p24;
}
@ -179,7 +212,8 @@ medium:
while(tx[i] == 0.0)
i--;
n = __rem_pio2_large(tx, ty, (int)(ix >> 20) - (0x3ff + 23), i + 1, 1);
if (sign) {
if(sign)
{
y[0] = -ty[0];
y[1] = -ty[1];
return -n;

File diff suppressed because it is too large Load Diff

View File

@ -42,7 +42,12 @@ pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */
int __rem_pio2f(float x, double* y)
{
union {float f; uint32_t i;} u = {x};
union
{
float f;
uint32_t i;
} u = { x };
double tx[1], ty[1];
double_t fn;
uint32_t ix;
@ -50,24 +55,29 @@ int __rem_pio2f(float x, double *y)
ix = u.i & 0x7fffffff;
/* 25+53 bit pi is good enough for medium size */
if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */
if(ix < 0x4dc90fdb)
{ /* |x| ~< 2^28*(pi/2), medium size */
/* Use a specialized rint() to get fn. */
fn = (double_t)x * invpio2 + toint - toint;
n = (int32_t)fn;
*y = x - fn * pio2_1 - fn * pio2_1t;
/* Matters with directed rounding. */
if (predict_false(*y < -pio4)) {
if(predict_false(*y < -pio4))
{
n--;
fn--;
*y = x - fn * pio2_1 - fn * pio2_1t;
} else if (predict_false(*y > pio4)) {
}
else if(predict_false(*y > pio4))
{
n++;
fn++;
*y = x - fn * pio2_1 - fn * pio2_1t;
}
return n;
}
if(ix>=0x7f800000) { /* x is inf or NaN */
if(ix >= 0x7f800000)
{ /* x is inf or NaN */
*y = x - x;
return 0;
}
@ -77,7 +87,8 @@ int __rem_pio2f(float x, double *y)
u.i = ix - (e0 << 23);
tx[0] = u.f;
n = __rem_pio2_large(tx, ty, e0, 1, 0);
if (sign) {
if(sign)
{
*y = -ty[0];
return -n;
}

View File

@ -65,11 +65,13 @@ double acos(double x)
GET_HIGH_WORD(hx, x);
ix = hx & 0x7fffffff;
/* |x| >= 1 or nan */
if (ix >= 0x3ff00000) {
if(ix >= 0x3ff00000)
{
uint32_t lx;
GET_LOW_WORD(lx, x);
if ((ix-0x3ff00000 | lx) == 0) {
if((ix - 0x3ff00000 | lx) == 0)
{
/* acos(1)=0, acos(-1)=pi */
if(hx >> 31)
return 2 * pio2_hi + 0x1p-120f;
@ -78,13 +80,15 @@ double acos(double x)
return 0 / (x - x);
}
/* |x| < 0.5 */
if (ix < 0x3fe00000) {
if(ix < 0x3fe00000)
{
if(ix <= 0x3c600000) /* |x| < 2**-57 */
return pio2_hi + 0x1p-120f;
return pio2_hi - (x - (pio2_lo - x * R(x * x)));
}
/* x < -0.5 */
if (hx >> 31) {
if(hx >> 31)
{
z = (1.0 + x) * 0.5;
s = sqrt(z);
w = R(z) * s - pio2_lo;

View File

@ -9,7 +9,12 @@ static const double_t toint = 1/EPS;
double ceil(double x)
{
union {double f; uint64_t i;} u = {x};
union
{
double f;
uint64_t i;
} u = { x };
int e = u.i >> 52 & 0x7ff;
double_t y;
@ -21,7 +26,8 @@ double ceil(double x)
else
y = x + toint - toint - x;
/* special case because of non-nearest rounding modes */
if (e <= 0x3ff-1) {
if(e <= 0x3ff - 1)
{
FORCE_EVAL(y);
return u.i >> 63 ? -0.0 : 1;
}

View File

@ -52,8 +52,10 @@ double cos(double x)
ix &= 0x7fffffff;
/* |x| ~< pi/4 */
if (ix <= 0x3fe921fb) {
if (ix < 0x3e46a09e) { /* |x| < 2**-27 * sqrt(2) */
if(ix <= 0x3fe921fb)
{
if(ix < 0x3e46a09e)
{ /* |x| < 2**-27 * sqrt(2) */
/* raise inexact if x!=0 */
FORCE_EVAL(x + 0x1p120f);
return 1.0;
@ -67,10 +69,14 @@ double cos(double x)
/* argument reduction */
n = __rem_pio2(x, y);
switch (n&3) {
case 0: return __cos(y[0], y[1]);
case 1: return -__sin(y[0], y[1], 1);
case 2: return -__cos(y[0], y[1]);
switch(n & 3)
{
case 0:
return __cos(y[0], y[1]);
case 1:
return -__sin(y[0], y[1], 1);
case 2:
return -__cos(y[0], y[1]);
default:
return __sin(y[0], y[1], 1);
}

View File

@ -33,28 +33,34 @@ float cosf(float x)
sign = ix >> 31;
ix &= 0x7fffffff;
if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
if (ix < 0x39800000) { /* |x| < 2**-12 */
if(ix <= 0x3f490fda)
{ /* |x| ~<= pi/4 */
if(ix < 0x39800000)
{ /* |x| < 2**-12 */
/* raise inexact if x != 0 */
FORCE_EVAL(x + 0x1p120f);
return 1.0f;
}
return __cosdf(x);
}
if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
if(ix <= 0x407b53d1)
{ /* |x| ~<= 5*pi/4 */
if(ix > 0x4016cbe3) /* |x| ~> 3*pi/4 */
return -__cosdf(sign ? x + c2pio2 : x - c2pio2);
else {
else
{
if(sign)
return __sindf(x + c1pio2);
else
return __sindf(c1pio2 - x);
}
}
if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
if(ix <= 0x40e231d5)
{ /* |x| ~<= 9*pi/4 */
if(ix > 0x40afeddf) /* |x| ~> 7*pi/4 */
return __cosdf(sign ? x + c4pio2 : x - c4pio2);
else {
else
{
if(sign)
return __sindf(-x - c3pio2);
else
@ -68,10 +74,14 @@ float cosf(float x)
/* general argument reduction needed */
n = __rem_pio2f(x, &y);
switch (n&3) {
case 0: return __cosdf(y);
case 1: return __sindf(-y);
case 2: return -__cosdf(y);
switch(n & 3)
{
case 0:
return __cosdf(y);
case 1:
return __sindf(-y);
case 2:
return -__cosdf(y);
default:
return __sindf(y);
}

View File

@ -12,7 +12,9 @@
#define EXP_POLY_ORDER 5
#define EXP_USE_TOINT_NARROW 0
#define EXP2_POLY_ORDER 5
extern const struct exp_data {
extern const struct exp_data
{
double invln2N;
double shift;
double negln2hiN;

View File

@ -3,7 +3,12 @@
double fabs(double x)
{
union {double f; uint64_t i;} u = {x};
union
{
double f;
uint64_t i;
} u = { x };
u.i &= -1ULL / 2;
return u.f;
}

View File

@ -9,7 +9,12 @@ static const double_t toint = 1/EPS;
double floor(double x)
{
union {double f; uint64_t i;} u = {x};
union
{
double f;
uint64_t i;
} u = { x };
int e = u.i >> 52 & 0x7ff;
double_t y;
@ -21,7 +26,8 @@ double floor(double x)
else
y = x + toint - toint - x;
/* special case because of non-nearest rounding modes */
if (e <= 0x3ff-1) {
if(e <= 0x3ff - 1)
{
FORCE_EVAL(y);
return u.i >> 63 ? -1 : 0;
}

View File

@ -3,7 +3,12 @@
double fmod(double x, double y)
{
union {double f; uint64_t i;} ux = {x}, uy = {y};
union
{
double f;
uint64_t i;
} ux = { x }, uy = { y };
int ex = ux.i >> 52 & 0x7ff;
int ey = uy.i >> 52 & 0x7ff;
int sx = ux.i >> 63;
@ -15,32 +20,43 @@ double fmod(double x, double y)
if(uy.i << 1 == 0 || isnan(y) || ex == 0x7ff)
return (x * y) / (x * y);
if (uxi<<1 <= uy.i<<1) {
if(uxi << 1 <= uy.i << 1)
{
if(uxi << 1 == uy.i << 1)
return 0 * x;
return x;
}
/* normalize x and y */
if (!ex) {
for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1);
if(!ex)
{
for(i = uxi << 12; i >> 63 == 0; ex--, i <<= 1)
;
uxi <<= -ex + 1;
} else {
}
else
{
uxi &= -1ULL >> 12;
uxi |= 1ULL << 52;
}
if (!ey) {
for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1);
if(!ey)
{
for(i = uy.i << 12; i >> 63 == 0; ey--, i <<= 1)
;
uy.i <<= -ey + 1;
} else {
}
else
{
uy.i &= -1ULL >> 12;
uy.i |= 1ULL << 52;
}
/* x mod y */
for (; ex > ey; ex--) {
for(; ex > ey; ex--)
{
i = uxi - uy.i;
if (i >> 63 == 0) {
if(i >> 63 == 0)
{
if(i == 0)
return 0 * x;
uxi = i;
@ -48,18 +64,23 @@ double fmod(double x, double y)
uxi <<= 1;
}
i = uxi - uy.i;
if (i >> 63 == 0) {
if(i >> 63 == 0)
{
if(i == 0)
return 0 * x;
uxi = i;
}
for (; uxi>>52 == 0; uxi <<= 1, ex--);
for(; uxi >> 52 == 0; uxi <<= 1, ex--)
;
/* scale result */
if (ex > 0) {
if(ex > 0)
{
uxi -= 1ULL << 52;
uxi |= (uint64_t)ex << 52;
} else {
}
else
{
uxi >>= -ex + 1;
}
uxi |= (uint64_t)sx << 63;

View File

@ -1,6 +1,6 @@
#include <stdint.h>
#include <float.h>
#include <math.h>
#include <stdint.h>
#define WANT_ROUNDING 1
@ -40,6 +40,7 @@ static inline double eval_as_double(double x)
#ifndef fp_force_evalf
#define fp_force_evalf fp_force_evalf
static inline void fp_force_evalf(float x)
{
volatile float y;
@ -49,6 +50,7 @@ static inline void fp_force_evalf(float x)
#ifndef fp_force_eval
#define fp_force_eval fp_force_eval
static inline void fp_force_eval(double x)
{
volatile double y;
@ -58,6 +60,7 @@ static inline void fp_force_eval(double x)
#ifndef fp_force_evall
#define fp_force_evall fp_force_evall
static inline void fp_force_evall(long double x)
{
volatile long double y;
@ -65,12 +68,19 @@ static inline void fp_force_evall(long double x)
}
#endif
#define FORCE_EVAL(x) do { \
if (sizeof(x) == sizeof(float)) { \
#define FORCE_EVAL(x) \
do \
{ \
if(sizeof(x) == sizeof(float)) \
{ \
fp_force_evalf(x); \
} else if (sizeof(x) == sizeof(double)) { \
} \
else if(sizeof(x) == sizeof(double)) \
{ \
fp_force_eval(x); \
} else { \
} \
else \
{ \
fp_force_evall(x); \
} \
} while(0)
@ -81,24 +91,28 @@ static inline void fp_force_evall(long double x)
#define asdouble(i) ((union {uint64_t _i; double _f; }){ i })._f
#define EXTRACT_WORDS(hi, lo, d) \
do { \
do \
{ \
uint64_t __u = asuint64(d); \
(hi) = __u >> 32; \
(lo) = (uint32_t)__u; \
} while(0)
#define GET_HIGH_WORD(hi, d) \
do { \
do \
{ \
(hi) = asuint64(d) >> 32; \
} while(0)
#define GET_LOW_WORD(lo, d) \
do { \
do \
{ \
(lo) = (uint32_t)asuint64(d); \
} while(0)
#define INSERT_WORDS(d, hi, lo) \
do { \
do \
{ \
(d) = asdouble(((uint64_t)(hi) << 32) | (uint32_t)(lo)); \
} while(0)
@ -109,12 +123,14 @@ do { \
INSERT_WORDS(d, asuint64(d) >> 32, lo)
#define GET_FLOAT_WORD(w, d) \
do { \
do \
{ \
(w) = asuint(d); \
} while(0)
#define SET_FLOAT_WORD(d, w) \
do { \
do \
{ \
(d) = asfloat(w); \
} while(0)

View File

@ -5,11 +5,11 @@
* SPDX-License-Identifier: MIT
*/
#include "exp_data.h"
#include "libm.h"
#include "pow_data.h"
#include <math.h>
#include <stdint.h>
#include "libm.h"
#include "exp_data.h"
#include "pow_data.h"
/*
Worst-case error: 0.54 ULP (~= ulperr_exp + 1024*Ln2*relerr_log*2^53)
@ -92,8 +92,7 @@ static inline double_t log_inline(uint64_t ix, double_t *tail)
lo4 = t2 - hi + arhi2;
#endif
/* p = log1p(r) - r - A[0]*r*r. */
p = (ar3 * (A[1] + r * A[2] +
ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6]))));
p = (ar3 * (A[1] + r * A[2] + ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6]))));
lo = lo1 + lo2 + lo3 + lo4 + p;
y = hi + lo;
*tail = hi - y + lo;
@ -125,7 +124,8 @@ static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki)
{
double_t scale, y;
if ((ki & 0x80000000) == 0) {
if((ki & 0x80000000) == 0)
{
/* k > 0, the exponent of scale might have overflowed by <= 460. */
sbits -= 1009ull << 52;
scale = asdouble(sbits);
@ -137,7 +137,8 @@ static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki)
/* Note: sbits is signed scale. */
scale = asdouble(sbits);
y = scale + scale * tmp;
if (fabs(y) < 1.0) {
if(fabs(y) < 1.0)
{
/* Round y to the right precision before scaling it into the subnormal
range to avoid double rounding that can cause 0.5+E/2 ulp error where
E is the worst-case ulp error outside the subnormal range. So this
@ -172,15 +173,17 @@ static inline double exp_inline(double_t x, double_t xtail, uint32_t sign_bias)
double_t kd, z, r, r2, scale, tail, tmp;
abstop = top12(x) & 0x7ff;
if (predict_false(abstop - top12(0x1p-54) >=
top12(512.0) - top12(0x1p-54))) {
if (abstop - top12(0x1p-54) >= 0x80000000) {
if(predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54)))
{
if(abstop - top12(0x1p-54) >= 0x80000000)
{
/* Avoid spurious underflow for tiny x. */
/* Note: 0 is common input. */
double_t one = WANT_ROUNDING ? 1.0 + x : 1.0;
return sign_bias ? -one : one;
}
if (abstop >= top12(1024.0)) {
if(abstop >= top12(1024.0))
{
/* Note: inf and nan are already handled. */
if(asuint64(x) >> 63)
return __math_uflow(sign_bias);
@ -263,19 +266,19 @@ double pow(double x, double y)
iy = asuint64(y);
topx = top12(x);
topy = top12(y);
if (predict_false(topx - 0x001 >= 0x7ff - 0x001 ||
(topy & 0x7ff) - 0x3be >= 0x43e - 0x3be)) {
if(predict_false(topx - 0x001 >= 0x7ff - 0x001 || (topy & 0x7ff) - 0x3be >= 0x43e - 0x3be))
{
/* Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0
and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1. */
/* Special cases: (x < 0x1p-126 or inf or nan) or
(|y| < 0x1p-65 or |y| >= 0x1p63 or nan). */
if (predict_false(zeroinfnan(iy))) {
if(predict_false(zeroinfnan(iy)))
{
if(2 * iy == 0)
return issignaling_inline(x) ? x + y : 1.0;
if(ix == asuint64(1.0))
return issignaling_inline(y) ? x + y : 1.0;
if (2 * ix > 2 * asuint64(INFINITY) ||
2 * iy > 2 * asuint64(INFINITY))
if(2 * ix > 2 * asuint64(INFINITY) || 2 * iy > 2 * asuint64(INFINITY))
return x + y;
if(2 * ix == 2 * asuint64(1.0))
return 1.0;
@ -283,7 +286,8 @@ double pow(double x, double y)
return 0.0; /* |x|<1 && y==inf or |x|>1 && y==-inf. */
return y * y;
}
if (predict_false(zeroinfnan(ix))) {
if(predict_false(zeroinfnan(ix)))
{
double_t x2 = x * x;
if(ix >> 63 && checkint(iy) == 1)
x2 = -x2;
@ -294,7 +298,8 @@ double pow(double x, double y)
return iy >> 63 ? (1 / x2) : x2;
}
/* Here x and y are non-zero finite. */
if (ix >> 63) {
if(ix >> 63)
{
/* Finite x < 0. */
int yint = checkint(iy);
if(yint == 0)
@ -304,23 +309,23 @@ double pow(double x, double y)
ix &= 0x7fffffffffffffff;
topx &= 0x7ff;
}
if ((topy & 0x7ff) - 0x3be >= 0x43e - 0x3be) {
if((topy & 0x7ff) - 0x3be >= 0x43e - 0x3be)
{
/* Note: sign_bias == 0 here because y is not odd. */
if(ix == asuint64(1.0))
return 1.0;
if ((topy & 0x7ff) < 0x3be) {
if((topy & 0x7ff) < 0x3be)
{
/* |y| < 2^-65, x^y ~= 1 + y*log(x). */
if(WANT_ROUNDING)
return ix > asuint64(1.0) ? 1.0 + y :
1.0 - y;
return ix > asuint64(1.0) ? 1.0 + y : 1.0 - y;
else
return 1.0;
}
return (ix > asuint64(1.0)) == (topy < 0x800) ?
__math_oflow(0) :
__math_uflow(0);
return (ix > asuint64(1.0)) == (topy < 0x800) ? __math_oflow(0) : __math_uflow(0);
}
if (topx == 0) {
if(topx == 0)
{
/* Normalize subnormal x so exponent becomes negative. */
ix = asuint64(x * 0x1p52);
ix &= 0x7fffffffffffffff;

View File

@ -9,12 +9,16 @@
#define POW_LOG_TABLE_BITS 7
#define POW_LOG_POLY_ORDER 8
extern const struct pow_log_data {
extern const struct pow_log_data
{
double ln2hi;
double ln2lo;
double poly[POW_LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
/* Note: the pad field is unused, but allows slightly faster indexing. */
struct {
struct
{
double invc, pad, logc, logctail;
} tab[1 << POW_LOG_TABLE_BITS];
} __pow_log_data;

View File

@ -3,24 +3,34 @@
double scalbn(double x, int n)
{
union {double f; uint64_t i;} u;
union
{
double f;
uint64_t i;
} u;
double_t y = x;
if (n > 1023) {
if(n > 1023)
{
y *= 0x1p1023;
n -= 1023;
if (n > 1023) {
if(n > 1023)
{
y *= 0x1p1023;
n -= 1023;
if(n > 1023)
n = 1023;
}
} else if (n < -1022) {
}
else if(n < -1022)
{
/* make sure final n < -53 to avoid double
rounding in the subnormal range */
y *= 0x1p-1022 * 0x1p53;
n += 1022 - 53;
if (n < -1022) {
if(n < -1022)
{
y *= 0x1p-1022 * 0x1p53;
n += 1022 - 53;
if(n < -1022)

View File

@ -53,8 +53,10 @@ double sin(double x)
ix &= 0x7fffffff;
/* |x| ~< pi/4 */
if (ix <= 0x3fe921fb) {
if (ix < 0x3e500000) { /* |x| < 2**-26 */
if(ix <= 0x3fe921fb)
{
if(ix < 0x3e500000)
{ /* |x| < 2**-26 */
/* raise inexact if x != 0 and underflow if subnormal*/
FORCE_EVAL(ix < 0x00100000 ? x / 0x1p120f : x + 0x1p120f);
return x;
@ -68,10 +70,14 @@ double sin(double x)
/* argument reduction needed */
n = __rem_pio2(x, y);
switch (n&3) {
case 0: return __sin(y[0], y[1], 1);
case 1: return __cos(y[0], y[1]);
case 2: return -__sin(y[0], y[1], 1);
switch(n & 3)
{
case 0:
return __sin(y[0], y[1], 1);
case 1:
return __cos(y[0], y[1]);
case 2:
return -__sin(y[0], y[1], 1);
default:
return -__cos(y[0], y[1]);
}

View File

@ -33,16 +33,20 @@ float sinf(float x)
sign = ix >> 31;
ix &= 0x7fffffff;
if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */
if (ix < 0x39800000) { /* |x| < 2**-12 */
if(ix <= 0x3f490fda)
{ /* |x| ~<= pi/4 */
if(ix < 0x39800000)
{ /* |x| < 2**-12 */
/* raise inexact if x!=0 and underflow if subnormal */
FORCE_EVAL(ix < 0x00800000 ? x / 0x1p120f : x + 0x1p120f);
return x;
}
return __sindf(x);
}
if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */
if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */
if(ix <= 0x407b53d1)
{ /* |x| ~<= 5*pi/4 */
if(ix <= 0x4016cbe3)
{ /* |x| ~<= 3pi/4 */
if(sign)
return -__cosdf(x + s1pio2);
else
@ -50,8 +54,10 @@ float sinf(float x)
}
return __sindf(sign ? -(x + s2pio2) : -(x - s2pio2));
}
if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */
if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */
if(ix <= 0x40e231d5)
{ /* |x| ~<= 9*pi/4 */
if(ix <= 0x40afeddf)
{ /* |x| ~<= 7*pi/4 */
if(sign)
return __cosdf(x + s3pio2);
else
@ -66,10 +72,14 @@ float sinf(float x)
/* general argument reduction needed */
n = __rem_pio2f(x, &y);
switch (n&3) {
case 0: return __sindf(y);
case 1: return __cosdf(y);
case 2: return __sindf(-y);
switch(n & 3)
{
case 0:
return __sindf(y);
case 1:
return __cosdf(y);
case 2:
return __sindf(-y);
default:
return -__cosdf(y);
}

View File

@ -1,7 +1,7 @@
#include <stdint.h>
#include <math.h>
#include "libm.h"
#include "sqrt_data.h"
#include <math.h>
#include <stdint.h>
#define FENV_SUPPORT 1
@ -28,7 +28,8 @@ double sqrt(double x)
/* special case handling. */
ix = asuint64(x);
top = ix >> 52;
if (predict_false(top - 0x001 >= 0x7ff - 0x001)) {
if(predict_false(top - 0x001 >= 0x7ff - 0x001))
{
/* x < 0x1p-1022 or inf or nan. */
if(ix * 2 == 0)
return x;
@ -48,7 +49,8 @@ double sqrt(double x)
2^e is the exponent part of the result. */
int even = top & 1;
m = (ix << 11) | 0x8000000000000000;
if (even) m >>= 1;
if(even)
m >>= 1;
top = (top + 0x3ff) >> 1;
/* approximate r ~ 1/sqrt(m) and s ~ sqrt(m) when m in [1,4)
@ -145,7 +147,8 @@ double sqrt(double x)
s &= 0x000fffffffffffff;
s |= top << 52;
y = asdouble(s);
if (FENV_SUPPORT) {
if(FENV_SUPPORT)
{
/* handle rounding modes and inexact exception:
only (s+1)^2 == 2^42 m case is exact otherwise
add a tiny value to cause the fenv effects. */

View File

@ -1,19 +1,131 @@
#include "sqrt_data.h"
const uint16_t __rsqrt_tab[128] = {
0xb451,0xb2f0,0xb196,0xb044,0xaef9,0xadb6,0xac79,0xab43,
0xaa14,0xa8eb,0xa7c8,0xa6aa,0xa592,0xa480,0xa373,0xa26b,
0xa168,0xa06a,0x9f70,0x9e7b,0x9d8a,0x9c9d,0x9bb5,0x9ad1,
0x99f0,0x9913,0x983a,0x9765,0x9693,0x95c4,0x94f8,0x9430,
0x936b,0x92a9,0x91ea,0x912e,0x9075,0x8fbe,0x8f0a,0x8e59,
0x8daa,0x8cfe,0x8c54,0x8bac,0x8b07,0x8a64,0x89c4,0x8925,
0x8889,0x87ee,0x8756,0x86c0,0x862b,0x8599,0x8508,0x8479,
0x83ec,0x8361,0x82d8,0x8250,0x81c9,0x8145,0x80c2,0x8040,
0xff02,0xfd0e,0xfb25,0xf947,0xf773,0xf5aa,0xf3ea,0xf234,
0xf087,0xeee3,0xed47,0xebb3,0xea27,0xe8a3,0xe727,0xe5b2,
0xe443,0xe2dc,0xe17a,0xe020,0xdecb,0xdd7d,0xdc34,0xdaf1,
0xd9b3,0xd87b,0xd748,0xd61a,0xd4f1,0xd3cd,0xd2ad,0xd192,
0xd07b,0xcf69,0xce5b,0xcd51,0xcc4a,0xcb48,0xca4a,0xc94f,
0xc858,0xc764,0xc674,0xc587,0xc49d,0xc3b7,0xc2d4,0xc1f4,
0xc116,0xc03c,0xbf65,0xbe90,0xbdbe,0xbcef,0xbc23,0xbb59,
0xba91,0xb9cc,0xb90a,0xb84a,0xb78c,0xb6d0,0xb617,0xb560,
0xb451,
0xb2f0,
0xb196,
0xb044,
0xaef9,
0xadb6,
0xac79,
0xab43,
0xaa14,
0xa8eb,
0xa7c8,
0xa6aa,
0xa592,
0xa480,
0xa373,
0xa26b,
0xa168,
0xa06a,
0x9f70,
0x9e7b,
0x9d8a,
0x9c9d,
0x9bb5,
0x9ad1,
0x99f0,
0x9913,
0x983a,
0x9765,
0x9693,
0x95c4,
0x94f8,
0x9430,
0x936b,
0x92a9,
0x91ea,
0x912e,
0x9075,
0x8fbe,
0x8f0a,
0x8e59,
0x8daa,
0x8cfe,
0x8c54,
0x8bac,
0x8b07,
0x8a64,
0x89c4,
0x8925,
0x8889,
0x87ee,
0x8756,
0x86c0,
0x862b,
0x8599,
0x8508,
0x8479,
0x83ec,
0x8361,
0x82d8,
0x8250,
0x81c9,
0x8145,
0x80c2,
0x8040,
0xff02,
0xfd0e,
0xfb25,
0xf947,
0xf773,
0xf5aa,
0xf3ea,
0xf234,
0xf087,
0xeee3,
0xed47,
0xebb3,
0xea27,
0xe8a3,
0xe727,
0xe5b2,
0xe443,
0xe2dc,
0xe17a,
0xe020,
0xdecb,
0xdd7d,
0xdc34,
0xdaf1,
0xd9b3,
0xd87b,
0xd748,
0xd61a,
0xd4f1,
0xd3cd,
0xd2ad,
0xd192,
0xd07b,
0xcf69,
0xce5b,
0xcd51,
0xcc4a,
0xcb48,
0xca4a,
0xc94f,
0xc858,
0xc764,
0xc674,
0xc587,
0xc49d,
0xc3b7,
0xc2d4,
0xc1f4,
0xc116,
0xc03c,
0xbf65,
0xbe90,
0xbdbe,
0xbcef,
0xbc23,
0xbb59,
0xba91,
0xb9cc,
0xb90a,
0xb84a,
0xb78c,
0xb6d0,
0xb617,
0xb560,
};

View File

@ -1,7 +1,7 @@
#include <stdint.h>
#include <math.h>
#include "libm.h"
#include "sqrt_data.h"
#include <math.h>
#include <stdint.h>
#define FENV_SUPPORT 1
@ -17,7 +17,8 @@ float sqrtf(float x)
uint32_t ix, m, m1, m0, even, ey;
ix = asuint(x);
if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) {
if(predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000))
{
/* x < 0x1p-126 or inf or nan. */
if(ix * 2 == 0)
return x;
@ -72,7 +73,8 @@ float sqrtf(float x)
s &= 0x007fffff;
s |= ey;
y = asfloat(s);
if (FENV_SUPPORT) {
if(FENV_SUPPORT)
{
/* handle rounding and inexact exception. */
uint32_t tiny = predict_false(d2 == 0) ? 0 : 0x01000000;
tiny |= (d1 ^ d2) & 0x80000000;

View File

@ -27,7 +27,6 @@ int memcmp(const void *s1, const void *s2, size_t n)
return (__builtin_memcmp(s1, s2, n));
}
#define STB_SPRINTF_IMPLEMENTATION
#include "stb/stb_sprintf.h"

View File

@ -57,12 +57,12 @@
//---------------------------------------------------------------
// utilities implementations
//---------------------------------------------------------------
#include "util/algebra.c"
#include "util/hash.c"
#include "util/memory.c"
#include "util/ringbuffer.c"
#include "util/strings.c"
#include "util/utf8.c"
#include"util/hash.c"
#include"util/ringbuffer.c"
#include"util/algebra.c"
//---------------------------------------------------------------
// app/graphics layer

View File

@ -9,20 +9,20 @@
#ifndef __ORCA_H_
#define __ORCA_H_
#include"util/typedefs.h"
#include"util/macros.h"
#include "util/algebra.h"
#include "util/debug.h"
#include "util/hash.h"
#include "util/lists.h"
#include "util/macros.h"
#include "util/memory.h"
#include "util/strings.h"
#include "util/typedefs.h"
#include "util/utf8.h"
#include"util/hash.h"
#include"util/algebra.h"
#include "platform/platform.h"
#include "platform/platform_clock.h"
#include"platform/platform_path.h"
#include "platform/platform_io.h"
#include "platform/platform_path.h"
#if !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
#include "platform/platform_thread.h"

View File

@ -7,10 +7,10 @@
*
*****************************************************************/
#include"platform/osx_path.m"
#include "app/osx_app.m"
#include "graphics/graphics_common.c"
#include "graphics/graphics_surface.c"
#include "platform/osx_path.m"
#if OC_COMPILE_METAL
#include "graphics/mtl_surface.m"

View File

@ -24,12 +24,14 @@
static const char* OC_LOG_HEADINGS[OC_LOG_LEVEL_COUNT] = {
"Error",
"Warning",
"Info"};
"Info"
};
static const char* OC_LOG_FORMATS[OC_LOG_LEVEL_COUNT] = {
"\033[38;5;9m\033[1m",
"\033[38;5;13m\033[1m",
"\033[38;5;10m\033[1m"};
"\033[38;5;10m\033[1m"
};
static const char* OC_LOG_FORMAT_STOP = "\033[m";

View File

@ -1,4 +1,4 @@
#include"util/typedefs.h"
#include "platform_clock.h"
#include "util/typedefs.h"
f64 ORCA_IMPORT(oc_clock_time)(oc_clock_kind clock);

View File

@ -10,7 +10,6 @@
#include "platform_debug.c"
#include "util/strings.h"
//----------------------------------------------------------------
// stb sprintf callback and user struct
//----------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -7,20 +7,19 @@
*
*****************************************************************/
#include<math.h> //fabs()
#include<time.h>
#include<sys/time.h> // gettimeofday()
#include <Availability.h> // availability macros
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include<mach/clock.h>
#include<Availability.h> // availability macros
#include <math.h> //fabs()
#include <sys/time.h> // gettimeofday()
#include <time.h>
#include<sys/types.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include "platform_clock.h"
typedef struct timeval timeval;
typedef struct timespec timespec;
@ -97,7 +96,8 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
u64 noff = OSXGetMonotonicNanoseconds();
u64 foff = (u64)(noff * 1e-9 * CLK_TIMESTAMPS_PER_SECOND);
ts = __initialTimestamp__ + foff;
} break;
}
break;
case OC_CLOCK_UPTIME:
{
@ -106,7 +106,8 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
u64 noff = OSXGetUptimeNanoseconds();
u64 foff = (u64)(noff * 1e-9 * CLK_TIMESTAMPS_PER_SECOND);
ts = __initialTimestamp__ + foff;
} break;
}
break;
case OC_CLOCK_DATE:
{
@ -115,7 +116,8 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
gettimeofday(&tv, 0);
ts = (((u64)tv.tv_sec + CLK_JAN_1970) << 32)
+ (u64)(tv.tv_usec * 1e-6 * CLK_TIMESTAMPS_PER_SECOND);
} break;
}
break;
}
/*
@ -129,7 +131,6 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
return (ts);
}
f64 oc_clock_time(oc_clock_kind clock)
{
switch(clock)
@ -139,7 +140,8 @@ f64 oc_clock_time(oc_clock_kind clock)
//NOTE(martin): compute monotonic offset and add it to bootup timestamp
u64 noff = OSXGetMonotonicNanoseconds();
return ((f64)noff * 1e-9);
} break;
}
break;
case OC_CLOCK_UPTIME:
{
@ -147,7 +149,8 @@ f64 oc_clock_time(oc_clock_kind clock)
//NOTE(martin): compute uptime offset and add it to bootup timestamp
u64 noff = OSXGetUptimeNanoseconds();
return ((f64)noff * 1e-9);
} break;
}
break;
case OC_CLOCK_DATE:
{
@ -157,6 +160,7 @@ f64 oc_clock_time(oc_clock_kind clock)
timeval tv;
gettimeofday(&tv, 0);
return (((f64)tv.tv_sec + CLK_JAN_1970) + ((f64)tv.tv_usec * 1e-6));
} break;
}
break;
}
}

View File

@ -18,7 +18,9 @@ bool oc_path_is_absolute(oc_str8 path)
}
oc_str8 oc_path_executable(oc_arena* arena)
{@autoreleasepool{
{
@autoreleasepool
{
oc_str8 result = {};
u32 size = 0;
_NSGetExecutablePath(0, &size);
@ -27,7 +29,8 @@ oc_str8 oc_path_executable(oc_arena* arena)
_NSGetExecutablePath(result.ptr, &size);
result.ptr[result.len] = '\0';
return (result);
}}
}
}
oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path)
{

View File

@ -9,14 +9,16 @@
#ifndef __PLATFORM_CLOCK_H_
#define __PLATFORM_CLOCK_H_
#include"util/typedefs.h"
#include "platform.h"
#include "util/typedefs.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif // __cplusplus
typedef enum {
typedef enum
{
OC_CLOCK_MONOTONIC, // clock that increment monotonically
OC_CLOCK_UPTIME, // clock that increment monotonically during uptime
OC_CLOCK_DATE // clock that is driven by the platform time
@ -30,5 +32,4 @@ ORCA_API f64 oc_clock_time(oc_clock_kind clock);
} // extern "C"
#endif // __cplusplus
#endif //__PLATFORM_CLOCK_H_

View File

@ -21,10 +21,13 @@ ORCA_API _Noreturn void oc_assert_fail(const char* file, const char* function, i
// Logging
//----------------------------------------------------------------
typedef enum { OC_LOG_LEVEL_ERROR,
typedef enum
{
OC_LOG_LEVEL_ERROR,
OC_LOG_LEVEL_WARNING,
OC_LOG_LEVEL_INFO,
OC_LOG_LEVEL_COUNT } oc_log_level;
OC_LOG_LEVEL_COUNT
} oc_log_level;
typedef struct oc_log_output oc_log_output;
@ -39,5 +42,4 @@ ORCA_API void oc_log_ext(oc_log_level level,
const char* fmt,
...);
#endif //__PLATFORM_DEBUG_H_

View File

@ -8,16 +8,20 @@
#ifndef __PLATFORM_IO_H_
#define __PLATFORM_IO_H_
#include"util/typedefs.h"
#include "util/strings.h"
#include "util/typedefs.h"
//----------------------------------------------------------------
// IO API
//----------------------------------------------------------------
typedef struct { u64 h; } oc_file;
typedef struct
{
u64 h;
} oc_file;
typedef u16 oc_file_open_flags;
enum oc_file_open_flags_enum
{
OC_FILE_OPEN_NONE = 0,
@ -32,6 +36,7 @@ enum oc_file_open_flags_enum
};
typedef u16 oc_file_access;
enum oc_file_access_enum
{
OC_FILE_ACCESS_NONE = 0,
@ -39,12 +44,17 @@ enum oc_file_access_enum
OC_FILE_ACCESS_WRITE = 1 << 2,
};
typedef enum { OC_FILE_SEEK_SET, OC_FILE_SEEK_END, OC_FILE_SEEK_CURRENT } oc_file_whence;
typedef enum
{
OC_FILE_SEEK_SET,
OC_FILE_SEEK_END,
OC_FILE_SEEK_CURRENT
} oc_file_whence;
typedef u64 oc_io_req_id;
typedef u32 oc_io_op;
enum oc_io_op_enum
{
OC_IO_OPEN_AT = 0,
@ -68,6 +78,7 @@ typedef struct oc_io_req
i64 offset;
u64 size;
union
{
char* buffer;
@ -88,7 +99,9 @@ typedef struct oc_io_req
} oc_io_req;
typedef i32 oc_io_error;
enum oc_io_error_enum {
enum oc_io_error_enum
{
OC_IO_OK = 0,
OC_IO_ERR_UNKNOWN,
OC_IO_ERR_OP, // unsupported operation
@ -173,6 +186,7 @@ typedef enum oc_file_type
} oc_file_type;
typedef u16 oc_file_perm;
enum oc_file_perm
{
OC_FILE_OTHER_EXEC = 1 << 0,
@ -208,5 +222,4 @@ ORCA_API u64 oc_file_size(oc_file file);
//TODO: Complete as needed...
#endif //__PLATFORM_IO_H_

View File

@ -7,6 +7,7 @@
*****************************************************************/
#include "platform_io.h"
//------------------------------------------------------------------------------
// File stream read/write API
//------------------------------------------------------------------------------
@ -38,12 +39,14 @@ oc_file oc_file_open(oc_str8 path, oc_file_access rights, oc_file_open_flags fla
oc_file oc_file_open_at(oc_file dir, oc_str8 path, oc_file_access rights, oc_file_open_flags flags)
{
oc_io_req req = {.op = OC_IO_OPEN_AT,
oc_io_req req = {
.op = OC_IO_OPEN_AT,
.handle = dir,
.size = path.len,
.buffer = path.ptr,
.open.rights = rights,
.open.flags = flags,};
.open.flags = flags,
};
oc_io_cmp cmp = oc_io_wait_single_req(&req);
return (cmp.handle);

View File

@ -102,7 +102,6 @@ typedef struct oc_io_open_restrict_result
oc_file_desc fd;
} oc_io_open_restrict_result;
oc_io_open_restrict_result oc_io_open_restrict(oc_file_desc dirFd, oc_str8 path, oc_file_access accessRights, oc_file_open_flags openFlags)
{
oc_arena_scope scratch = oc_scratch_begin();
@ -281,7 +280,6 @@ oc_io_cmp oc_io_open_at(oc_file_slot* atSlot, oc_io_req* req, oc_file_table* tab
slot->fd = oc_file_desc_nil();
cmp.handle = oc_file_from_slot(table, slot);
oc_str8 path = oc_str8_from_buffer(req->size, req->buffer);
if(!path.len)

View File

@ -8,8 +8,8 @@
#ifndef __PLATFORM_IO_INTERNAL_H_
#define __PLATFORM_IO_INTERNAL_H_
#include"platform_io.h"
#include "platform.h"
#include "platform_io.h"
#if OC_PLATFORM_MACOS || PLATFORM_LINUX
typedef int oc_file_desc;
@ -53,7 +53,6 @@ oc_file_slot* oc_file_slot_from_handle(oc_file_table* table, oc_file handle);
ORCA_API oc_io_cmp oc_io_wait_single_req_with_table(oc_io_req* req, oc_file_table* table);
//-----------------------------------------------------------------------
// raw io primitives
//-----------------------------------------------------------------------

View File

@ -9,11 +9,12 @@
#ifndef __PLATFORM_MEMORY_H_
#define __PLATFORM_MEMORY_H_
#include"util/typedefs.h"
#include "platform.h"
#include "util/typedefs.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
//--------------------------------------------------------------------------------

View File

@ -19,7 +19,8 @@
#endif
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif // __cplusplus
//---------------------------------------------------------------

View File

@ -8,9 +8,9 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include<limits.h>
#include "platform_io_common.c"
#include "platform_io_internal.c"

View File

@ -6,9 +6,9 @@
* @revision:
*
*****************************************************************/
#include<stdlib.h>
#include <pthread.h>
#include <signal.h> //needed for pthread_kill() on linux
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h> // nanosleep()
@ -126,7 +126,6 @@ int oc_thread_detach(oc_thread* thread)
return (0);
}
struct oc_mutex
{
pthread_mutex_t pmutex;
@ -178,7 +177,8 @@ void oc_ticket_init(oc_ticket* mutex)
void oc_ticket_lock(oc_ticket* mutex)
{
u64 ticket = atomic_fetch_add(&mutex->nextTicket, 1ULL);
while(ticket != mutex->serving); //spin
while(ticket != mutex->serving)
; //spin
}
void oc_ticket_unlock(oc_ticket* mutex)
@ -186,7 +186,6 @@ void oc_ticket_unlock(oc_ticket* mutex)
atomic_fetch_add(&mutex->serving, 1ULL);
}
struct oc_condition
{
pthread_cond_t pcond;
@ -249,7 +248,6 @@ int oc_condition_broadcast(oc_condition* cond)
return (pthread_cond_broadcast(&cond->pcond));
}
void oc_sleep_nano(u64 nanoseconds)
{
timespec rqtp;

View File

@ -6,8 +6,8 @@
* @revision:
*
*****************************************************************/
#include<sys/mman.h>
#include "platform_memory.h"
#include <sys/mman.h>
/*NOTE(martin):
Linux and MacOS don't make a distinction between reserved and committed memory, contrary to Windows

View File

@ -8,11 +8,12 @@
*****************************************************************/
#include <profileapi.h>
#include"util/typedefs.h"
#include "platform_clock.h"
#include "util/typedefs.h"
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
static u64 __performanceCounterFreq = 0;

View File

@ -11,9 +11,9 @@
#include <shlwapi.h>
#include <winioctl.h>
#include"win32_string_helpers.h"
#include"platform_io_internal.c"
#include "platform_io_common.c"
#include "platform_io_internal.c"
#include "win32_string_helpers.h"
oc_io_error oc_io_raw_last_error()
{
@ -316,6 +316,7 @@ typedef struct
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union
{
struct

Some files were not shown because too many files have changed in this diff Show More