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 AllowAllArgumentsOnNextLine: false
BreakBeforeBraces: Allman BreakBeforeBraces: Allman
ColumnLimit: 0
Cpp11BracedListStyle: false Cpp11BracedListStyle: false
ColumnLimit: 0
BreakBeforeBinaryOperators: NonAssignment
AlignOperands: AlignAfterOperator
IndentPPDirectives: BeforeHash IndentPPDirectives: BeforeHash
IndentCaseLabels: true
IndentWidth: 4 IndentWidth: 4
TabWidth: 4
UseTab: Never
LineEnding: LF LineEnding: LF
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1
PointerAlignment: Left PointerAlignment: Left
SeparateDefinitionBlocks: Always SeparateDefinitionBlocks: Always
SpaceBeforeParens: Never SpaceBeforeParens: Never
TabWidth: 4
UseTab: Never
ReflowComments: false 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 "glsl_shaders.h"
#include "math.h"
#include "orca.h"
//---------------------------------------------------------------- //----------------------------------------------------------------
//NOTE(martin): GL vertex struct and identifiers //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 typedef struct advect_program
{ {
@ -156,7 +159,6 @@ GLuint compile_shader(const char* vs, const char* fs)
glAttachShader(prog, fragmentShader); glAttachShader(prog, fragmentShader);
glLinkProgram(prog); glLinkProgram(prog);
//TODO errors //TODO errors
int status = 0; int status = 0;
glGetProgramiv(prog, GL_LINK_STATUS, &status); glGetProgramiv(prog, GL_LINK_STATUS, &status);
@ -284,7 +286,6 @@ void init_blit_residue(blit_residue_program* program)
program->bTex = glGetUniformLocation(program->prog, "bTex"); program->bTex = glGetUniformLocation(program->prog, "bTex");
} }
GLuint create_texture(int width, int height, GLenum internalFormat, GLenum format, GLenum type, char* initData) GLuint create_texture(int width, int height, GLenum internalFormat, GLenum format, GLenum type, char* initData)
{ {
GLuint texture; GLuint texture;
@ -406,7 +407,6 @@ mouse_input mouseInput = {0};
int frameWidth = 800; int frameWidth = 800;
int frameHeight = 600; int frameHeight = 600;
ORCA_EXPORT void oc_on_mouse_down(int button) ORCA_EXPORT void oc_on_mouse_down(int button)
{ {
mouseInput.down = true; mouseInput.down = true;
@ -454,7 +454,6 @@ void init_velocity_vortex()
float y = 2 * i / (float)texWidth - 1; float y = 2 * i / (float)texWidth - 1;
velocityInitData[i][j][0] = sinf(2 * M_PI * y); velocityInitData[i][j][0] = sinf(2 * M_PI * y);
velocityInitData[i][j][1] = sinf(2 * M_PI * x); 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); glDrawArrays(GL_TRIANGLES, 0, 6);
frame_buffer_swap(&colorBuffer); frame_buffer_swap(&colorBuffer);
} }
void jacobi_solve(frame_buffer* x, frame_buffer* b, float invGridSize, int iterationCount) 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 // init vertex buffer
static Vertex vertices[6] = static Vertex vertices[6] = {
{
{ -1, -1 }, { -1, -1 },
{ 1, -1 }, { 1, -1 },
{ 1, 1 }, { 1, 1 },
@ -672,7 +669,6 @@ ORCA_EXPORT void oc_on_init()
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(blitProgram.pos, 2, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(blitProgram.pos, 2, GL_FLOAT, GL_FALSE, 0, 0);
for(int i = 0; i < texWidth / 2; i++) for(int i = 0; i < texWidth / 2; i++)
{ {
for(int j = 0; j < texHeight / 2; j++) for(int j = 0; j < texHeight / 2; j++)
@ -772,7 +768,6 @@ ORCA_EXPORT void oc_on_frame_refresh()
input_splat(t); input_splat(t);
//NOTE: compute divergence of advected velocity //NOTE: compute divergence of advected velocity
glUseProgram(divProgram.prog); glUseProgram(divProgram.prog);
glBindFramebuffer(GL_FRAMEBUFFER, divBuffer[0].fbos[1]); glBindFramebuffer(GL_FRAMEBUFFER, divBuffer[0].fbos[1]);
@ -815,9 +810,6 @@ ORCA_EXPORT void oc_on_frame_refresh()
} }
#endif #endif
//NOTE: subtract pressure gradient to advected velocity //NOTE: subtract pressure gradient to advected velocity
glUseProgram(subtractProgram.prog); glUseProgram(subtractProgram.prog);
glBindFramebuffer(GL_FRAMEBUFFER, velocityBuffer.fbos[1]); glBindFramebuffer(GL_FRAMEBUFFER, velocityBuffer.fbos[1]);
@ -865,7 +857,8 @@ ORCA_EXPORT void oc_on_frame_refresh()
1 / aspectRatio, 0, 0, 0, 1 / aspectRatio, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 0, 1 }; 0, 0, 0, 1
};
/* /*
glUseProgram(blitResidueProgram.prog); glUseProgram(blitResidueProgram.prog);

View File

@ -14,15 +14,24 @@ vec3 color_map(float v)
float f = floor(logv + 7.0); float f = floor(logv + 7.0);
float i = floor(4.0 * (logv + 7.0 - f)); float i = floor(4.0 * (logv + 7.0 - f));
if(f < 0.0) return vec3(0.0); if(f < 0.0)
if(f < 1.0) return mix(vec3(1.0, 0.0, 0.0), vec3(1.0), i/4.0); return vec3(0.0);
if(f < 2.0) return mix(vec3(0.0, 1.0, 0.0), vec3(1.0), i/4.0); if(f < 1.0)
if(f < 3.0) return mix(vec3(0.0, 0.0, 1.0), vec3(1.0), i/4.0); return mix(vec3(1.0, 0.0, 0.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 < 2.0)
if(f < 5.0) return mix(vec3(1.0, 0.0, 1.0), vec3(1.0), i/4.0); return mix(vec3(0.0, 1.0, 0.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 < 3.0)
if(f < 7.0) return mix(vec3(1.0, 0.5, 0.0), vec3(1.0), i/4.0); return mix(vec3(0.0, 0.0, 1.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 < 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); return vec3(1.0);
} }

View File

@ -39,15 +39,24 @@ vec3 color_map(float v)
float f = floor(logv + 7.0); float f = floor(logv + 7.0);
float i = floor(4.0 * (logv + 7.0 - f)); float i = floor(4.0 * (logv + 7.0 - f));
if(f < 0.0) return vec3(0.0); if(f < 0.0)
if(f < 1.0) return mix(vec3(1.0, 0.0, 0.0), vec3(1.0), i/4.0); return vec3(0.0);
if(f < 2.0) return mix(vec3(0.0, 1.0, 0.0), vec3(1.0), i/4.0); if(f < 1.0)
if(f < 3.0) return mix(vec3(0.0, 0.0, 1.0), vec3(1.0), i/4.0); return mix(vec3(1.0, 0.0, 0.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 < 2.0)
if(f < 5.0) return mix(vec3(1.0, 0.0, 1.0), vec3(1.0), i/4.0); return mix(vec3(0.0, 1.0, 0.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 < 3.0)
if(f < 7.0) return mix(vec3(1.0, 0.5, 0.0), vec3(1.0), i/4.0); return mix(vec3(0.0, 0.0, 1.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 < 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); return vec3(1.0);
} }

View File

@ -63,9 +63,9 @@ ORCA_EXPORT void oc_on_init(void)
glLinkProgram(program); glLinkProgram(program);
glUseProgram(program); glUseProgram(program);
GLfloat vertices[] = { 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; GLuint buffer;
glGenBuffers(1, &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_box_begin(str, OC_UI_FLAG_DRAW_BORDER);
oc_ui_label(str); oc_ui_label(str);
} }
void widget_end_view(void) void widget_end_view(void)
@ -217,7 +216,6 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
.size.height = { OC_UI_SIZE_PARENT, 1 } }, .size.height = { OC_UI_SIZE_PARENT, 1 } },
OC_UI_STYLE_SIZE); OC_UI_STYLE_SIZE);
oc_ui_pattern pattern = { 0 }; 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_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, oc_ui_style_match_after(pattern,
@ -385,13 +383,11 @@ ORCA_EXPORT void oc_on_frame_refresh(void)
} }
} }
} }
} }
} }
} }
} }
oc_canvas_set_current(canvas); oc_canvas_set_current(canvas);
oc_surface_select(surface); oc_surface_select(surface);
oc_ui_draw(); oc_ui_draw();

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
#include<stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#define MG_INCLUDE_GL_API 1 #define MG_INCLUDE_GL_API 1
#include "milepost.h" #include "milepost.h"
@ -64,7 +64,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE: case MP_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); mp_request_quit();
} break; }
break;
default: default:
break; 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 " "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."; "sit amet, malesuada enim. Mauris ultricies nibh orci.";
mg_font create_font(const char* path) mg_font create_font(const char* path)
{ {
//NOTE(martin): create font //NOTE(martin): create font
@ -92,7 +91,10 @@ mg_font create_font(const char* path)
return (font); return (font);
} }
enum { FONT_COUNT = 3 }; enum
{
FONT_COUNT = 3
};
int main() int main()
{ {
@ -175,7 +177,8 @@ int main()
case MP_EVENT_WINDOW_CLOSE: case MP_EVENT_WINDOW_CLOSE:
{ {
mp_request_quit(); mp_request_quit();
} break; }
break;
case MP_EVENT_MOUSE_BUTTON: case MP_EVENT_MOUSE_BUTTON:
{ {
@ -193,7 +196,8 @@ int main()
tracked = false; tracked = false;
} }
} }
} break; }
break;
case MP_EVENT_MOUSE_WHEEL: case MP_EVENT_MOUSE_WHEEL:
{ {
@ -206,7 +210,8 @@ int main()
startX = mousePos.x / zoom - trackX; startX = mousePos.x / zoom - trackX;
startY = mousePos.y / zoom - trackY; startY = mousePos.y / zoom - trackY;
} break; }
break;
case MP_EVENT_KEYBOARD_KEY: case MP_EVENT_KEYBOARD_KEY:
{ {
@ -214,7 +219,8 @@ int main()
{ {
fontIndex = (fontIndex + 1) % FONT_COUNT; fontIndex = (fontIndex + 1) % FONT_COUNT;
} }
} break; }
break;
default: default:
break; break;
@ -294,7 +300,6 @@ int main()
mg_text_outlines(text); mg_text_outlines(text);
mg_fill(); mg_fill();
f64 startFlushTime = mp_get_time(MP_CLOCK_MONOTONIC); f64 startFlushTime = mp_get_time(MP_CLOCK_MONOTONIC);
mg_surface_prepare(surface); mg_surface_prepare(surface);
@ -318,7 +323,6 @@ int main()
mem_arena_clear(mem_scratch()); mem_arena_clear(mem_scratch());
} }
for(int i = 0; i < FONT_COUNT; i++) for(int i = 0; i < FONT_COUNT; i++)
{ {
mg_font_destroy(fonts[i]); mg_font_destroy(fonts[i]);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,27 +9,34 @@
#ifndef __APP_H_ #ifndef __APP_H_
#define __APP_H_ #define __APP_H_
#include"util/typedefs.h"
#include"util/utf8.h"
#include "util/lists.h" #include "util/lists.h"
#include "util/memory.h" #include "util/memory.h"
#include "util/typedefs.h"
#include "util/utf8.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// Typedefs, enums and constants // 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_0,
OC_MOUSE_CURSOR_RESIZE_90, OC_MOUSE_CURSOR_RESIZE_90,
OC_MOUSE_CURSOR_RESIZE_45, OC_MOUSE_CURSOR_RESIZE_45,
OC_MOUSE_CURSOR_RESIZE_135, OC_MOUSE_CURSOR_RESIZE_135,
OC_MOUSE_CURSOR_TEXT } oc_mouse_cursor; OC_MOUSE_CURSOR_TEXT
} oc_mouse_cursor;
typedef i32 oc_window_style; typedef i32 oc_window_style;
static const oc_window_style OC_WINDOW_STYLE_NO_TITLE = 0x01 << 0, 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_POPUPMENU = 0x01 << 6,
OC_WINDOW_STYLE_NO_BUTTONS = 0x01 << 7; 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_MODS, //TODO: remove, keep only key?
OC_EVENT_KEYBOARD_KEY, OC_EVENT_KEYBOARD_KEY,
OC_EVENT_KEYBOARD_CHAR, OC_EVENT_KEYBOARD_CHAR,
@ -59,14 +68,20 @@ typedef enum { OC_EVENT_NONE,
OC_EVENT_WINDOW_CLOSE, OC_EVENT_WINDOW_CLOSE,
OC_EVENT_PATHDROP, OC_EVENT_PATHDROP,
OC_EVENT_FRAME, 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_PRESS,
OC_KEY_RELEASE, 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_SPACE = 32,
OC_KEY_APOSTROPHE = 39, /* ' */ OC_KEY_APOSTROPHE = 39, /* ' */
OC_KEY_COMMA = 44, /* , */ OC_KEY_COMMA = 44, /* , */
@ -187,23 +202,28 @@ typedef enum { OC_KEY_UNKNOWN = 0,
OC_KEY_RIGHT_ALT = 346, OC_KEY_RIGHT_ALT = 346,
OC_KEY_RIGHT_SUPER = 347, OC_KEY_RIGHT_SUPER = 347,
OC_KEY_MENU = 348, 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_NONE = 0x00,
OC_KEYMOD_ALT = 0x01, OC_KEYMOD_ALT = 0x01,
OC_KEYMOD_SHIFT = 0x02, OC_KEYMOD_SHIFT = 0x02,
OC_KEYMOD_CTRL = 0x04, OC_KEYMOD_CTRL = 0x04,
OC_KEYMOD_CMD = 0x08, 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_LEFT = 0x00,
OC_MOUSE_RIGHT = 0x01, OC_MOUSE_RIGHT = 0x01,
OC_MOUSE_MIDDLE = 0x02, OC_MOUSE_MIDDLE = 0x02,
OC_MOUSE_EXT1 = 0x03, OC_MOUSE_EXT1 = 0x03,
OC_MOUSE_EXT2 = 0x04, 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 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 message,
oc_str8_list options); oc_str8_list options);
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// file system stuff... //TODO: move elsewhere // 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); ORCA_API int oc_directory_create(oc_str8 path);
#endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA) #endif // !defined(OC_PLATFORM_ORCA) || !(OC_PLATFORM_ORCA)
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
#endif //__APP_H_ #endif //__APP_H_

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,8 @@
#ifndef __EGL_SURFACE_H_ #ifndef __EGL_SURFACE_H_
#define __EGL_SURFACE_H_ #define __EGL_SURFACE_H_
#include"graphics_surface.h"
#include "app/app.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_for_window(oc_window window);
oc_surface_data* oc_egl_surface_create_remote(u32 width, u32 height); oc_surface_data* oc_egl_surface_create_remote(u32 width, u32 height);

View File

@ -6,10 +6,10 @@
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/
#include "gl_api.h"
#include "glsl_shaders.h"
#include "graphics_surface.h" #include "graphics_surface.h"
#include "util/macros.h" #include "util/macros.h"
#include"glsl_shaders.h"
#include"gl_api.h"
typedef struct oc_gl_image typedef struct oc_gl_image
{ {
@ -17,10 +17,12 @@ typedef struct oc_gl_image
GLuint texture; GLuint texture;
} oc_gl_image; } oc_gl_image;
enum oc_gl_cmd_enum { enum oc_gl_cmd_enum
{
OC_GL_FILL, OC_GL_FILL,
OC_GL_STROKE, OC_GL_STROKE,
}; };
typedef int oc_gl_cmd; typedef int oc_gl_cmd;
typedef struct oc_gl_path typedef struct oc_gl_path
@ -40,6 +42,7 @@ enum oc_gl_seg_kind_enum
OC_GL_QUADRATIC, OC_GL_QUADRATIC,
OC_GL_CUBIC, OC_GL_CUBIC,
}; };
typedef int oc_gl_seg_kind; typedef int oc_gl_seg_kind;
typedef struct oc_gl_path_elt typedef struct oc_gl_path_elt
@ -57,6 +60,7 @@ typedef struct oc_gl_dispatch_indirect_command
u32 num_groups_z; u32 num_groups_z;
} oc_gl_dispatch_indirect_command; } oc_gl_dispatch_indirect_command;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//NOTE: these are just here for the sizes... //NOTE: these are just here for the sizes...
@ -117,7 +121,8 @@ enum
OC_GL_LAYOUT_SIZE(SCREEN_TILE, SCREEN_TILE_FIRST, VEC2) OC_GL_LAYOUT_SIZE(SCREEN_TILE, SCREEN_TILE_FIRST, VEC2)
}; };
enum { enum
{
OC_GL_INPUT_BUFFERS_COUNT = 3, OC_GL_INPUT_BUFFERS_COUNT = 3,
OC_GL_TILE_SIZE = 16, OC_GL_TILE_SIZE = 16,
OC_GL_MSAA_COUNT = 8, 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.x,
backend->pathScreenExtents.y, backend->pathScreenExtents.y,
backend->pathScreenExtents.z, backend->pathScreenExtents.z,
backend->pathScreenExtents.w}; backend->pathScreenExtents.w
};
path->clip = (oc_vec4){ path->clip = (oc_vec4){
primitive->attributes.clip.x, primitive->attributes.clip.x,
primitive->attributes.clip.y, primitive->attributes.clip.y,
primitive->attributes.clip.x + primitive->attributes.clip.w, 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){ path->color = (oc_vec4){
primitive->attributes.color.r, primitive->attributes.color.r,
primitive->attributes.color.g, primitive->attributes.color.g,
primitive->attributes.color.b, primitive->attributes.color.b,
primitive->attributes.color.a}; primitive->attributes.color.a
};
oc_rect srcRegion = primitive->attributes.srcRegion; 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.x,
backend->pathUserExtents.y, backend->pathUserExtents.y,
backend->pathUserExtents.z - backend->pathUserExtents.x, 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)) 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 = { oc_mat2x3 srcRegionToImage = {
1 / texSize.x, 0, srcRegion.x / texSize.x, 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 = { oc_mat2x3 destRegionToSrcRegion = {
srcRegion.w / destRegion.w, 0, 0, srcRegion.w / destRegion.w, 0, 0,
0, srcRegion.h/destRegion.h, 0}; 0, srcRegion.h / destRegion.h, 0
};
oc_mat2x3 userToDestRegion = { oc_mat2x3 userToDestRegion = {
1, 0, -destRegion.x, 1, 0, -destRegion.x,
0, 1, -destRegion.y}; 0, 1, -destRegion.y
};
oc_mat2x3 screenToUser = oc_mat2x3_inv(primitive->attributes.transform); 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 }; (1 - t) * q1.y + t * q2.y };
oc_vec2 s = { (1 - t) * r0.x + t * r1.x, 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[0] = p[0];
outLeft[1] = q0; 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); 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) 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, void oc_gl_render_batch(oc_gl_canvas_backend* backend,
oc_wgl_surface* surface, oc_wgl_surface* surface,
oc_image* images, 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 layout(binding = 0) restrict readonly buffer pathQueueBufferSSBO
{ {
oc_gl_path_queue elements[]; oc_gl_path_queue elements[];
} pathQueueBuffer; }
pathQueueBuffer;
layout(binding = 1) restrict buffer tileQueueBufferSSBO layout(binding = 1) restrict buffer tileQueueBufferSSBO
{ {
oc_gl_tile_queue elements[]; oc_gl_tile_queue elements[];
} tileQueueBuffer; }
tileQueueBuffer;
layout(location = 0) uniform int pathQueueBufferStart; layout(location = 0) uniform int pathQueueBufferStart;

View File

@ -7,13 +7,16 @@ layout(std430) buffer;
layout(binding = 0) coherent restrict readonly buffer screenTilesCountBufferSSBO layout(binding = 0) coherent restrict readonly buffer screenTilesCountBufferSSBO
{ {
int elements[]; int elements[];
} screenTilesCountBuffer; }
screenTilesCountBuffer;
layout(binding = 1) coherent restrict writeonly buffer dispatchBufferSSBO layout(binding = 1) coherent restrict writeonly buffer dispatchBufferSSBO
{ {
oc_gl_dispatch_indirect_command elements[]; oc_gl_dispatch_indirect_command elements[];
} dispatchBuffer; }
dispatchBuffer;
layout(location = 0) uniform uint maxWorkGroupCount; 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 ph = { p.x, p.y, 1 };
vec3 klm = seg.implicitMatrix * ph; vec3 klm = seg.implicitMatrix * ph;
side = ((klm.x * klm.x - klm.y) * klm.z < 0) ? -1 : 1; side = ((klm.x * klm.x - klm.y) * klm.z < 0) ? -1 : 1;
} break; }
break;
case OC_GL_CUBIC: case OC_GL_CUBIC:
{ {
vec3 ph = { p.x, p.y, 1 }; vec3 ph = { p.x, p.y, 1 };
vec3 klm = seg.implicitMatrix * ph; vec3 klm = seg.implicitMatrix * ph;
side = (seg.sign * (klm.x * klm.x * klm.x - klm.y * klm.z) < 0) ? -1 : 1; 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 layout(binding = 0) restrict readonly buffer pathBufferSSBO
{ {
oc_gl_path elements[]; oc_gl_path elements[];
} pathBuffer; }
pathBuffer;
layout(binding = 1) restrict readonly buffer pathQueueBufferSSBO layout(binding = 1) restrict readonly buffer pathQueueBufferSSBO
{ {
oc_gl_path_queue elements[]; oc_gl_path_queue elements[];
} pathQueueBuffer; }
pathQueueBuffer;
layout(binding = 2) restrict readonly buffer tileQueueBufferSSBO layout(binding = 2) restrict readonly buffer tileQueueBufferSSBO
{ {
oc_gl_tile_queue elements[]; oc_gl_tile_queue elements[];
} tileQueueBuffer; }
tileQueueBuffer;
layout(binding = 3) coherent restrict buffer tileOpCountBufferSSBO layout(binding = 3) coherent restrict buffer tileOpCountBufferSSBO
{ {
int elements[]; int elements[];
} tileOpCountBuffer; }
tileOpCountBuffer;
layout(binding = 4) restrict buffer tileOpBufferSSBO layout(binding = 4) restrict buffer tileOpBufferSSBO
{ {
oc_gl_tile_op elements[]; oc_gl_tile_op elements[];
} tileOpBuffer; }
tileOpBuffer;
layout(binding = 5) restrict writeonly buffer screenTilesBufferSSBO layout(binding = 5) restrict writeonly buffer screenTilesBufferSSBO
{ {
oc_gl_screen_tile elements[]; oc_gl_screen_tile elements[];
} screenTilesBuffer; }
screenTilesBuffer;
layout(binding = 6) coherent restrict buffer screenTilesCountBufferSSBO layout(binding = 6) coherent restrict buffer screenTilesCountBufferSSBO
{ {
int elements[]; int elements[];
} screenTilesCountBuffer; }
screenTilesCountBuffer;
layout(location = 0) uniform int tileSize; layout(location = 0) uniform int tileSize;
layout(location = 1) uniform float scale; layout(location = 1) uniform float scale;

View File

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

View File

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

View File

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

View File

@ -9,21 +9,23 @@
#ifndef __GRAPHICS_H_ #ifndef __GRAPHICS_H_
#define __GRAPHICS_H_ #define __GRAPHICS_H_
#include"util/typedefs.h"
#include"platform/platform.h"
#include "app/app.h" #include "app/app.h"
#include "platform/platform.h"
#include "util/typedefs.h"
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
//NOTE(martin): backends selection //NOTE(martin): backends selection
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
typedef enum { typedef enum
{
OC_NONE, OC_NONE,
OC_METAL, OC_METAL,
OC_GL, OC_GL,
OC_GLES, OC_GLES,
OC_CANVAS, 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 //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 // 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 //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 oc_surface oc_surface_nil(void);
ORCA_API bool oc_surface_is_nil(oc_surface surface); 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 //NOTE(martin): graphics canvas structs
//------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------
typedef struct oc_canvas { u64 h; } oc_canvas; typedef struct oc_canvas
typedef struct oc_font { u64 h; } oc_font; {
typedef struct oc_image { u64 h; } oc_image; u64 h;
} oc_canvas;
typedef struct oc_font
{
u64 h;
} oc_font;
typedef struct oc_image
{
u64 h;
} oc_image;
typedef struct oc_color typedef struct oc_color
{ {
@ -136,16 +152,23 @@ typedef struct oc_color
f32 b; f32 b;
f32 a; f32 a;
}; };
f32 c[4]; f32 c[4];
}; };
} oc_color; } oc_color;
typedef enum {OC_JOINT_MITER = 0, typedef enum
{
OC_JOINT_MITER = 0,
OC_JOINT_BEVEL, OC_JOINT_BEVEL,
OC_JOINT_NONE } oc_joint_type; OC_JOINT_NONE
} oc_joint_type;
typedef enum {OC_CAP_NONE = 0, typedef enum
OC_CAP_SQUARE } oc_cap_type; {
OC_CAP_NONE = 0,
OC_CAP_SQUARE
} oc_cap_type;
typedef struct oc_font_extents typedef struct oc_font_extents
{ {

View File

@ -8,8 +8,8 @@
*****************************************************************/ *****************************************************************/
#define _USE_MATH_DEFINES //NOTE: necessary for MSVC #define _USE_MATH_DEFINES //NOTE: necessary for MSVC
#include<math.h>
#include "platform/platform.h" #include "platform/platform.h"
#include <math.h>
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#if OC_PLATFORM_ORCA #if OC_PLATFORM_ORCA
@ -21,10 +21,9 @@
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION
#include "stb/stb_truetype.h" #include "stb/stb_truetype.h"
#include"platform/platform_debug.h" #include "graphics_common.h"
#include "platform/platform_debug.h" #include "platform/platform_debug.h"
#include "util/algebra.h" #include "util/algebra.h"
#include"graphics_common.h"
typedef struct oc_glyph_map_entry typedef struct oc_glyph_map_entry
{ {
@ -89,7 +88,10 @@ typedef struct oc_graphics_handle_slot
} 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 typedef struct oc_graphics_data
{ {
@ -136,7 +138,6 @@ typedef struct oc_canvas_data
static oc_graphics_data oc_graphicsData = { 0 }; static oc_graphics_data oc_graphicsData = { 0 };
void oc_graphics_init() void oc_graphics_init()
{ {
if(!oc_graphicsData.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 }); } oc_font oc_font_nil() { return ((oc_font){ .h = 0 }); }
bool oc_font_is_nil(oc_font font) { return (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) 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].type = OC_PATH_QUADRATIC;
elements[vertIndex].p[0] = (oc_vec2){ cx, cy }; elements[vertIndex].p[0] = (oc_vec2){ cx, cy };
elements[vertIndex].p[1] = (oc_vec2){ x, y }; elements[vertIndex].p[1] = (oc_vec2){ x, y };
} break; }
break;
case STBTT_vcubic: case STBTT_vcubic:
elements[vertIndex].type = OC_PATH_CUBIC; 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); return (extents);
} }
f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize) f32 oc_font_get_scale_for_em_pixels(oc_font font, f32 emSize)
{ {
oc_font_data* fontData = oc_font_data_from_handle(font); 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 }); } oc_canvas oc_canvas_nil() { return ((oc_canvas){ .h = 0 }); }
bool oc_canvas_is_nil(oc_canvas canvas) { return (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) 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 }); } oc_image oc_image_nil() { return ((oc_image){ .h = 0 }); }
bool oc_image_is_nil(oc_image image) { return (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) 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 #endif // !OC_PLATFORM_ORCA
void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion) void oc_image_draw_region(oc_image image, oc_rect srcRegion, oc_rect dstRegion)
{ {
oc_canvas_data* canvas = __mgCurrentCanvas; oc_canvas_data* canvas = __mgCurrentCanvas;

View File

@ -13,10 +13,13 @@
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// canvas structs // canvas structs
//------------------------------------------------------------------------ //------------------------------------------------------------------------
typedef enum { OC_PATH_MOVE, typedef enum
{
OC_PATH_MOVE,
OC_PATH_LINE, OC_PATH_LINE,
OC_PATH_QUADRATIC, OC_PATH_QUADRATIC,
OC_PATH_CUBIC } oc_path_elt_type; OC_PATH_CUBIC
} oc_path_elt_type;
typedef struct oc_path_elt typedef struct oc_path_elt
{ {
@ -53,7 +56,9 @@ typedef struct oc_attributes
} oc_attributes; } oc_attributes;
typedef enum { OC_CMD_FILL, typedef enum
{
OC_CMD_FILL,
OC_CMD_STROKE, OC_CMD_STROKE,
OC_CMD_JUMP OC_CMD_JUMP
} oc_primitive_cmd; } 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 }); } oc_surface oc_surface_nil() { return ((oc_surface){ .h = 0 }); }
bool oc_surface_is_nil(oc_surface surface) { return (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) oc_surface oc_surface_create_for_window(oc_window window, oc_surface_api api)

View File

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

View File

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

View File

@ -10,9 +10,9 @@
#import <QuartzCore/CAMetalLayer.h> #import <QuartzCore/CAMetalLayer.h>
#include <simd/simd.h> #include <simd/simd.h>
#include "app/osx_app.h"
#include "graphics_surface.h" #include "graphics_surface.h"
#include "util/macros.h" #include "util/macros.h"
#include"app/osx_app.h"
#include "mtl_renderer.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) void oc_mtl_encode_path(oc_mtl_canvas_backend* backend, oc_primitive* primitive, float scale)
{ {
int bufferIndex = backend->bufferIndex; 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), 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[1] / scale, uvTransform.m[4] / scale, 0),
simd_make_float3(uvTransform.m[2], uvTransform.m[5], 1)); simd_make_float3(uvTransform.m[2], uvTransform.m[5], 1));
} }
path->texture = backend->currentImageIndex; 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 }; (1 - t) * q1.y + t * q2.y };
oc_vec2 s = { (1 - t) * r0.x + t * r1.x, 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[0] = p[0];
outLeft[1] = q0; 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) void oc_mtl_grow_buffer_if_needed(oc_mtl_canvas_backend* backend, id<MTLBuffer>* buffer, u64 wantedSize)
{ {
u64 bufferSize = [(*buffer) length]; u64 bufferSize = [(*buffer) length];
@ -1346,8 +1344,7 @@ void oc_mtl_canvas_render(oc_canvas_backend* interface,
@autoreleasepool @autoreleasepool
{ {
//NOTE: finalize //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]); oc_mtl_print_log(backend->bufferIndex, backend->logBuffer[backend->bufferIndex], backend->logOffsetBuffer[backend->bufferIndex]);
dispatch_semaphore_signal(backend->bufferSemaphore); 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) 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; oc_mtl_image_data* image = (oc_mtl_image_data*)imageInterface;
MTLRegion mtlRegion = MTLRegionMake2D(region.x, region.y, region.w, region.h); MTLRegion mtlRegion = MTLRegionMake2D(region.x, region.y, region.w, region.h);
[image->texture replaceRegion:mtlRegion [image->texture replaceRegion:mtlRegion
mipmapLevel:0 mipmapLevel:0
withBytes:(void*)pixels withBytes:(void*)pixels
bytesPerRow:4 * region.w]; bytesPerRow:4 * region.w];
}} }
}
const u32 OC_MTL_DEFAULT_PATH_BUFFER_LEN = (4 << 10), const u32 OC_MTL_DEFAULT_PATH_BUFFER_LEN = (4 << 10),
OC_MTL_DEFAULT_ELT_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.imageDestroy = oc_mtl_canvas_image_destroy;
backend->interface.imageUploadRegion = oc_mtl_canvas_image_upload_region; backend->interface.imageUploadRegion = oc_mtl_canvas_image_upload_region;
@autoreleasepool{ @autoreleasepool
{
//NOTE: load metal library //NOTE: load metal library
oc_str8 shaderPath = oc_path_executable_relative(oc_scratch(), OC_STR8("mtl_renderer.metallib")); 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]; 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 <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
#include<metal_simdgroup>
#include "mtl_renderer.h" #include "mtl_renderer.h"
using namespace metal; using namespace metal;
typedef struct mtl_log_context typedef struct mtl_log_context
{ {
device char* buffer; device char* buffer;
@ -204,7 +203,6 @@ void log_quadratic_bezier(thread float2* p, mtl_log_context logCtx)
mtl_log(logCtx, ")\n"); mtl_log(logCtx, ")\n");
} }
void log_cubic_bezier(thread float2* p, mtl_log_context logCtx) void log_cubic_bezier(thread float2* p, mtl_log_context logCtx)
{ {
mtl_log(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]; const device oc_mtl_path* path = &pathBuffer[pathIndex];
//NOTE: we don't clip on the right, since we need those tiles to accurately compute //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. // the prefix sum of winding increments in the backprop pass.
float4 clippedBox = { max(path->box.x, path->clip.x), 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 ph = { p.x, p.y, 1 };
float3 klm = seg->implicitMatrix * ph; float3 klm = seg->implicitMatrix * ph;
side = ((klm.x * klm.x - klm.y) * klm.z < 0) ? -1 : 1; side = ((klm.x * klm.x - klm.y) * klm.z < 0) ? -1 : 1;
} break; }
break;
case OC_MTL_CUBIC: case OC_MTL_CUBIC:
{ {
float3 ph = { p.x, p.y, 1 }; float3 ph = { p.x, p.y, 1 };
float3 klm = seg->implicitMatrix * ph; float3 klm = seg->implicitMatrix * ph;
side = (seg->sign * (klm.x * klm.x * klm.x - klm.y * klm.z) < 0) ? -1 : 1; side = (seg->sign * (klm.x * klm.x * klm.x - klm.y * klm.z) < 0) ? -1 : 1;
} break; }
break;
} }
} }
} }
return (side); return (side);
} }
typedef struct mtl_segment_setup_context typedef struct mtl_segment_setup_context
{ {
device atomic_int* segmentCount; 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), float4 tileBox = (float4){ float(x + pathArea.x),
float(y + pathArea.y), float(y + pathArea.y),
float(x + pathArea.x + 1), 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 bl = { tileBox.x, tileBox.y };
float2 br = { tileBox.z, 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]; c = p[1];
} }
e = p[3]; e = p[3];
} break; }
break;
} }
device oc_mtl_segment* seg = 0; 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 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)); 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.}, seg->implicitMatrix = (1 / det) * matrix_float3x3({ a, d, 0. }, { b, e, 0. }, { c, f, g });
{b, e, 0.},
{c, f, g});
seg->hullVertex = p[1]; 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); sp[3] = (s1 == 1) ? p[3] : mtl_cubic_blossom(p, s1, s1, s1);
} }
typedef enum { typedef enum
{
MTL_CUBIC_ERROR, MTL_CUBIC_ERROR,
MTL_CUBIC_SERPENTINE, MTL_CUBIC_SERPENTINE,
MTL_CUBIC_CUSP, MTL_CUBIC_CUSP,
@ -1154,7 +1153,8 @@ void mtl_cubic_setup(thread mtl_segment_setup_context* context, float2 p[4])
p[0], p[0],
3.0 * (p[1] - p[0]), 3.0 * (p[1] - p[0]),
3.0 * (p[0] + p[2] - 2 * p[1]), 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: "); 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, " ): "); mtl_log(context->log, " ): ");
log_cubic_bezier(sp, context->log); log_cubic_bezier(sp, context->log);
mtl_cubic_emit(context, curve, p, s0, s1, sp); 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]; const device oc_mtl_path_queue* pathQueue = &pathQueueBuffer[elt->pathIndex];
device oc_mtl_tile_queue* tileQueues = &tileQueueBuffer[pathQueue->tileQueues]; 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, .segmentCount = segmentCount,
.segmentBuffer = segmentBuffer, .segmentBuffer = segmentBuffer,
.pathQueue = pathQueue, .pathQueue = pathQueue,
@ -1285,7 +1285,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
.tileSize = tileSize[0], .tileSize = tileSize[0],
.log.buffer = logBuffer, .log.buffer = logBuffer,
.log.offset = logOffsetBuffer, .log.offset = logOffsetBuffer,
.log.enabled = false,}; .log.enabled = false,
};
switch(elt->kind) switch(elt->kind)
{ {
@ -1295,7 +1296,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
mtl_log(setupCtx.log, "line: "); mtl_log(setupCtx.log, "line: ");
log_line(p, setupCtx.log); log_line(p, setupCtx.log);
mtl_line_setup(&setupCtx, p); mtl_line_setup(&setupCtx, p);
} break; }
break;
case OC_MTL_QUADRATIC: case OC_MTL_QUADRATIC:
{ {
@ -1303,7 +1305,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
mtl_log(setupCtx.log, "quadratic: "); mtl_log(setupCtx.log, "quadratic: ");
log_quadratic_bezier(p, setupCtx.log); log_quadratic_bezier(p, setupCtx.log);
mtl_quadratic_setup(&setupCtx, p); mtl_quadratic_setup(&setupCtx, p);
} break; }
break;
case OC_MTL_CUBIC: case OC_MTL_CUBIC:
{ {
@ -1311,8 +1314,8 @@ kernel void mtl_segment_setup(constant int* elementCount [[buffer(0)]],
mtl_log(setupCtx.log, "cubic: "); mtl_log(setupCtx.log, "cubic: ");
log_cubic_bezier(p, setupCtx.log); log_cubic_bezier(p, setupCtx.log);
mtl_cubic_setup(&setupCtx, p); mtl_cubic_setup(&setupCtx, p);
}
} break; break;
} }
} }
@ -1483,7 +1486,6 @@ kernel void mtl_merge(constant int* pathCount [[buffer(0)]],
*nextLink = firstOpIndex; *nextLink = firstOpIndex;
nextLink = &lastOp->next; nextLink = &lastOp->next;
//NOTE: add path end op //NOTE: add path end op
int endOpIndex = atomic_fetch_add_explicit(tileOpCount, 1, memory_order_relaxed); int endOpIndex = atomic_fetch_add_explicit(tileOpCount, 1, memory_order_relaxed);
if(endOpIndex >= tileOpMax[0]) 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), centerCoord + float2(+0.25, -0.25),
centerCoord + float2(-0.25, +0.25)}; centerCoord + float2(-0.25, +0.25)
};
float4 color = { 0 }; float4 color = { 0 };
int winding[OC_MTL_MAX_SAMPLE_COUNT] = { 0 }; int winding[OC_MTL_MAX_SAMPLE_COUNT] = { 0 };

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,8 @@
#define _STDLIB_H #define _STDLIB_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
#define abort(...) OC_ABORT(__VA_ARGS__) #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 */ /* caller must handle the case when reduction is not needed: |x| ~<= pi/4 */
int __rem_pio2(double x, double* y) 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_t z, w, t, r, fn;
double tx[3], ty[2]; double tx[3], ty[2];
uint32_t ix; uint32_t ix;
@ -56,28 +61,38 @@ int __rem_pio2(double x, double *y)
sign = u.i >> 63; sign = u.i >> 63;
ix = u.i >> 32 & 0x7fffffff; 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 */ if((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */
goto medium; /* cancellation -- use medium case */ goto medium; /* cancellation -- use medium case */
if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ if(ix <= 0x4002d97c)
if (!sign) { { /* |x| ~<= 3pi/4 */
if(!sign)
{
z = x - pio2_1; /* one round good to 85 bits */ z = x - pio2_1; /* one round good to 85 bits */
y[0] = z - pio2_1t; y[0] = z - pio2_1t;
y[1] = (z - y[0]) - pio2_1t; y[1] = (z - y[0]) - pio2_1t;
return 1; return 1;
} else { }
else
{
z = x + pio2_1; z = x + pio2_1;
y[0] = z + pio2_1t; y[0] = z + pio2_1t;
y[1] = (z - y[0]) + pio2_1t; y[1] = (z - y[0]) + pio2_1t;
return -1; return -1;
} }
} else { }
if (!sign) { else
{
if(!sign)
{
z = x - 2 * pio2_1; z = x - 2 * pio2_1;
y[0] = z - 2 * pio2_1t; y[0] = z - 2 * pio2_1t;
y[1] = (z - y[0]) - 2 * pio2_1t; y[1] = (z - y[0]) - 2 * pio2_1t;
return 2; return 2;
} else { }
else
{
z = x + 2 * pio2_1; z = x + 2 * pio2_1;
y[0] = z + 2 * pio2_1t; y[0] = z + 2 * pio2_1t;
y[1] = (z - y[0]) + 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 <= 0x401c463b)
if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ { /* |x| ~<= 9pi/4 */
if(ix <= 0x4015fdbc)
{ /* |x| ~<= 7pi/4 */
if(ix == 0x4012d97c) /* |x| ~= 3pi/2 */ if(ix == 0x4012d97c) /* |x| ~= 3pi/2 */
goto medium; goto medium;
if (!sign) { if(!sign)
{
z = x - 3 * pio2_1; z = x - 3 * pio2_1;
y[0] = z - 3 * pio2_1t; y[0] = z - 3 * pio2_1t;
y[1] = (z - y[0]) - 3 * pio2_1t; y[1] = (z - y[0]) - 3 * pio2_1t;
return 3; return 3;
} else { }
else
{
z = x + 3 * pio2_1; z = x + 3 * pio2_1;
y[0] = z + 3 * pio2_1t; y[0] = z + 3 * pio2_1t;
y[1] = (z - y[0]) + 3 * pio2_1t; y[1] = (z - y[0]) + 3 * pio2_1t;
return -3; return -3;
} }
} else { }
else
{
if(ix == 0x401921fb) /* |x| ~= 4pi/2 */ if(ix == 0x401921fb) /* |x| ~= 4pi/2 */
goto medium; goto medium;
if (!sign) { if(!sign)
{
z = x - 4 * pio2_1; z = x - 4 * pio2_1;
y[0] = z - 4 * pio2_1t; y[0] = z - 4 * pio2_1t;
y[1] = (z - y[0]) - 4 * pio2_1t; y[1] = (z - y[0]) - 4 * pio2_1t;
return 4; return 4;
} else { }
else
{
z = x + 4 * pio2_1; z = x + 4 * pio2_1;
y[0] = z + 4 * pio2_1t; y[0] = z + 4 * pio2_1t;
y[1] = (z - y[0]) + 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: medium:
/* rint(x/(pi/2)) */ /* rint(x/(pi/2)) */
fn = (double_t)x * invpio2 + toint - toint; fn = (double_t)x * invpio2 + toint - toint;
@ -124,12 +150,15 @@ medium:
r = x - fn * pio2_1; r = x - fn * pio2_1;
w = fn * pio2_1t; /* 1st round, good to 85 bits */ w = fn * pio2_1t; /* 1st round, good to 85 bits */
/* Matters with directed rounding. */ /* Matters with directed rounding. */
if (predict_false(r - w < -pio4)) { if(predict_false(r - w < -pio4))
{
n--; n--;
fn--; fn--;
r = x - fn * pio2_1; r = x - fn * pio2_1;
w = fn * pio2_1t; w = fn * pio2_1t;
} else if (predict_false(r - w > pio4)) { }
else if(predict_false(r - w > pio4))
{
n++; n++;
fn++; fn++;
r = x - fn * pio2_1; r = x - fn * pio2_1;
@ -139,7 +168,8 @@ medium:
u.f = y[0]; u.f = y[0];
ey = u.i >> 52 & 0x7ff; ey = u.i >> 52 & 0x7ff;
ex = ix >> 20; 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; t = r;
w = fn * pio2_2; w = fn * pio2_2;
r = t - w; r = t - w;
@ -147,7 +177,8 @@ medium:
y[0] = r - w; y[0] = r - w;
u.f = y[0]; u.f = y[0];
ey = u.i >> 52 & 0x7ff; 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; t = r;
w = fn * pio2_3; w = fn * pio2_3;
r = t - w; r = t - w;
@ -161,7 +192,8 @@ medium:
/* /*
* all other (large) arguments * 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; y[0] = y[1] = x - x;
return 0; return 0;
} }
@ -170,7 +202,8 @@ medium:
u.i &= (uint64_t)-1 >> 12; u.i &= (uint64_t)-1 >> 12;
u.i |= (uint64_t)(0x3ff + 23) << 52; u.i |= (uint64_t)(0x3ff + 23) << 52;
z = u.f; z = u.f;
for (i=0; i < 2; i++) { for(i = 0; i < 2; i++)
{
tx[i] = (double)(int32_t)z; tx[i] = (double)(int32_t)z;
z = (z - tx[i]) * 0x1p24; z = (z - tx[i]) * 0x1p24;
} }
@ -179,7 +212,8 @@ medium:
while(tx[i] == 0.0) while(tx[i] == 0.0)
i--; i--;
n = __rem_pio2_large(tx, ty, (int)(ix >> 20) - (0x3ff + 23), i + 1, 1); n = __rem_pio2_large(tx, ty, (int)(ix >> 20) - (0x3ff + 23), i + 1, 1);
if (sign) { if(sign)
{
y[0] = -ty[0]; y[0] = -ty[0];
y[1] = -ty[1]; y[1] = -ty[1];
return -n; 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) 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 tx[1], ty[1];
double_t fn; double_t fn;
uint32_t ix; uint32_t ix;
@ -50,24 +55,29 @@ int __rem_pio2f(float x, double *y)
ix = u.i & 0x7fffffff; ix = u.i & 0x7fffffff;
/* 25+53 bit pi is good enough for medium size */ /* 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. */ /* Use a specialized rint() to get fn. */
fn = (double_t)x * invpio2 + toint - toint; fn = (double_t)x * invpio2 + toint - toint;
n = (int32_t)fn; n = (int32_t)fn;
*y = x - fn * pio2_1 - fn * pio2_1t; *y = x - fn * pio2_1 - fn * pio2_1t;
/* Matters with directed rounding. */ /* Matters with directed rounding. */
if (predict_false(*y < -pio4)) { if(predict_false(*y < -pio4))
{
n--; n--;
fn--; fn--;
*y = x - fn * pio2_1 - fn * pio2_1t; *y = x - fn * pio2_1 - fn * pio2_1t;
} else if (predict_false(*y > pio4)) { }
else if(predict_false(*y > pio4))
{
n++; n++;
fn++; fn++;
*y = x - fn * pio2_1 - fn * pio2_1t; *y = x - fn * pio2_1 - fn * pio2_1t;
} }
return n; return n;
} }
if(ix>=0x7f800000) { /* x is inf or NaN */ if(ix >= 0x7f800000)
{ /* x is inf or NaN */
*y = x - x; *y = x - x;
return 0; return 0;
} }
@ -77,7 +87,8 @@ int __rem_pio2f(float x, double *y)
u.i = ix - (e0 << 23); u.i = ix - (e0 << 23);
tx[0] = u.f; tx[0] = u.f;
n = __rem_pio2_large(tx, ty, e0, 1, 0); n = __rem_pio2_large(tx, ty, e0, 1, 0);
if (sign) { if(sign)
{
*y = -ty[0]; *y = -ty[0];
return -n; return -n;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,11 +5,11 @@
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include "exp_data.h"
#include "libm.h"
#include "pow_data.h"
#include <math.h> #include <math.h>
#include <stdint.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) 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; lo4 = t2 - hi + arhi2;
#endif #endif
/* p = log1p(r) - r - A[0]*r*r. */ /* p = log1p(r) - r - A[0]*r*r. */
p = (ar3 * (A[1] + r * A[2] + p = (ar3 * (A[1] + r * A[2] + ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6]))));
ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6]))));
lo = lo1 + lo2 + lo3 + lo4 + p; lo = lo1 + lo2 + lo3 + lo4 + p;
y = hi + lo; y = hi + lo;
*tail = hi - y + 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; double_t scale, y;
if ((ki & 0x80000000) == 0) { if((ki & 0x80000000) == 0)
{
/* k > 0, the exponent of scale might have overflowed by <= 460. */ /* k > 0, the exponent of scale might have overflowed by <= 460. */
sbits -= 1009ull << 52; sbits -= 1009ull << 52;
scale = asdouble(sbits); 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. */ /* Note: sbits is signed scale. */
scale = asdouble(sbits); scale = asdouble(sbits);
y = scale + scale * tmp; 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 /* 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 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 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; double_t kd, z, r, r2, scale, tail, tmp;
abstop = top12(x) & 0x7ff; abstop = top12(x) & 0x7ff;
if (predict_false(abstop - top12(0x1p-54) >= if(predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54)))
top12(512.0) - top12(0x1p-54))) { {
if (abstop - top12(0x1p-54) >= 0x80000000) { if(abstop - top12(0x1p-54) >= 0x80000000)
{
/* Avoid spurious underflow for tiny x. */ /* Avoid spurious underflow for tiny x. */
/* Note: 0 is common input. */ /* Note: 0 is common input. */
double_t one = WANT_ROUNDING ? 1.0 + x : 1.0; double_t one = WANT_ROUNDING ? 1.0 + x : 1.0;
return sign_bias ? -one : one; return sign_bias ? -one : one;
} }
if (abstop >= top12(1024.0)) { if(abstop >= top12(1024.0))
{
/* Note: inf and nan are already handled. */ /* Note: inf and nan are already handled. */
if(asuint64(x) >> 63) if(asuint64(x) >> 63)
return __math_uflow(sign_bias); return __math_uflow(sign_bias);
@ -263,19 +266,19 @@ double pow(double x, double y)
iy = asuint64(y); iy = asuint64(y);
topx = top12(x); topx = top12(x);
topy = top12(y); topy = top12(y);
if (predict_false(topx - 0x001 >= 0x7ff - 0x001 || if(predict_false(topx - 0x001 >= 0x7ff - 0x001 || (topy & 0x7ff) - 0x3be >= 0x43e - 0x3be))
(topy & 0x7ff) - 0x3be >= 0x43e - 0x3be)) { {
/* Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0 /* 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. */ and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1. */
/* Special cases: (x < 0x1p-126 or inf or nan) or /* Special cases: (x < 0x1p-126 or inf or nan) or
(|y| < 0x1p-65 or |y| >= 0x1p63 or nan). */ (|y| < 0x1p-65 or |y| >= 0x1p63 or nan). */
if (predict_false(zeroinfnan(iy))) { if(predict_false(zeroinfnan(iy)))
{
if(2 * iy == 0) if(2 * iy == 0)
return issignaling_inline(x) ? x + y : 1.0; return issignaling_inline(x) ? x + y : 1.0;
if(ix == asuint64(1.0)) if(ix == asuint64(1.0))
return issignaling_inline(y) ? x + y : 1.0; return issignaling_inline(y) ? x + y : 1.0;
if (2 * ix > 2 * asuint64(INFINITY) || if(2 * ix > 2 * asuint64(INFINITY) || 2 * iy > 2 * asuint64(INFINITY))
2 * iy > 2 * asuint64(INFINITY))
return x + y; return x + y;
if(2 * ix == 2 * asuint64(1.0)) if(2 * ix == 2 * asuint64(1.0))
return 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 0.0; /* |x|<1 && y==inf or |x|>1 && y==-inf. */
return y * y; return y * y;
} }
if (predict_false(zeroinfnan(ix))) { if(predict_false(zeroinfnan(ix)))
{
double_t x2 = x * x; double_t x2 = x * x;
if(ix >> 63 && checkint(iy) == 1) if(ix >> 63 && checkint(iy) == 1)
x2 = -x2; x2 = -x2;
@ -294,7 +298,8 @@ double pow(double x, double y)
return iy >> 63 ? (1 / x2) : x2; return iy >> 63 ? (1 / x2) : x2;
} }
/* Here x and y are non-zero finite. */ /* Here x and y are non-zero finite. */
if (ix >> 63) { if(ix >> 63)
{
/* Finite x < 0. */ /* Finite x < 0. */
int yint = checkint(iy); int yint = checkint(iy);
if(yint == 0) if(yint == 0)
@ -304,23 +309,23 @@ double pow(double x, double y)
ix &= 0x7fffffffffffffff; ix &= 0x7fffffffffffffff;
topx &= 0x7ff; topx &= 0x7ff;
} }
if ((topy & 0x7ff) - 0x3be >= 0x43e - 0x3be) { if((topy & 0x7ff) - 0x3be >= 0x43e - 0x3be)
{
/* Note: sign_bias == 0 here because y is not odd. */ /* Note: sign_bias == 0 here because y is not odd. */
if(ix == asuint64(1.0)) if(ix == asuint64(1.0))
return 1.0; return 1.0;
if ((topy & 0x7ff) < 0x3be) { if((topy & 0x7ff) < 0x3be)
{
/* |y| < 2^-65, x^y ~= 1 + y*log(x). */ /* |y| < 2^-65, x^y ~= 1 + y*log(x). */
if(WANT_ROUNDING) if(WANT_ROUNDING)
return ix > asuint64(1.0) ? 1.0 + y : return ix > asuint64(1.0) ? 1.0 + y : 1.0 - y;
1.0 - y;
else else
return 1.0; return 1.0;
} }
return (ix > asuint64(1.0)) == (topy < 0x800) ? return (ix > asuint64(1.0)) == (topy < 0x800) ? __math_oflow(0) : __math_uflow(0);
__math_oflow(0) :
__math_uflow(0);
} }
if (topx == 0) { if(topx == 0)
{
/* Normalize subnormal x so exponent becomes negative. */ /* Normalize subnormal x so exponent becomes negative. */
ix = asuint64(x * 0x1p52); ix = asuint64(x * 0x1p52);
ix &= 0x7fffffffffffffff; ix &= 0x7fffffffffffffff;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,19 +1,131 @@
#include "sqrt_data.h" #include "sqrt_data.h"
const uint16_t __rsqrt_tab[128] = { const uint16_t __rsqrt_tab[128] = {
0xb451,0xb2f0,0xb196,0xb044,0xaef9,0xadb6,0xac79,0xab43, 0xb451,
0xaa14,0xa8eb,0xa7c8,0xa6aa,0xa592,0xa480,0xa373,0xa26b, 0xb2f0,
0xa168,0xa06a,0x9f70,0x9e7b,0x9d8a,0x9c9d,0x9bb5,0x9ad1, 0xb196,
0x99f0,0x9913,0x983a,0x9765,0x9693,0x95c4,0x94f8,0x9430, 0xb044,
0x936b,0x92a9,0x91ea,0x912e,0x9075,0x8fbe,0x8f0a,0x8e59, 0xaef9,
0x8daa,0x8cfe,0x8c54,0x8bac,0x8b07,0x8a64,0x89c4,0x8925, 0xadb6,
0x8889,0x87ee,0x8756,0x86c0,0x862b,0x8599,0x8508,0x8479, 0xac79,
0x83ec,0x8361,0x82d8,0x8250,0x81c9,0x8145,0x80c2,0x8040, 0xab43,
0xff02,0xfd0e,0xfb25,0xf947,0xf773,0xf5aa,0xf3ea,0xf234, 0xaa14,
0xf087,0xeee3,0xed47,0xebb3,0xea27,0xe8a3,0xe727,0xe5b2, 0xa8eb,
0xe443,0xe2dc,0xe17a,0xe020,0xdecb,0xdd7d,0xdc34,0xdaf1, 0xa7c8,
0xd9b3,0xd87b,0xd748,0xd61a,0xd4f1,0xd3cd,0xd2ad,0xd192, 0xa6aa,
0xd07b,0xcf69,0xce5b,0xcd51,0xcc4a,0xcb48,0xca4a,0xc94f, 0xa592,
0xc858,0xc764,0xc674,0xc587,0xc49d,0xc3b7,0xc2d4,0xc1f4, 0xa480,
0xc116,0xc03c,0xbf65,0xbe90,0xbdbe,0xbcef,0xbc23,0xbb59, 0xa373,
0xba91,0xb9cc,0xb90a,0xb84a,0xb78c,0xb6d0,0xb617,0xb560, 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 "libm.h"
#include "sqrt_data.h" #include "sqrt_data.h"
#include <math.h>
#include <stdint.h>
#define FENV_SUPPORT 1 #define FENV_SUPPORT 1
@ -17,7 +17,8 @@ float sqrtf(float x)
uint32_t ix, m, m1, m0, even, ey; uint32_t ix, m, m1, m0, even, ey;
ix = asuint(x); ix = asuint(x);
if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) { if(predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000))
{
/* x < 0x1p-126 or inf or nan. */ /* x < 0x1p-126 or inf or nan. */
if(ix * 2 == 0) if(ix * 2 == 0)
return x; return x;
@ -72,7 +73,8 @@ float sqrtf(float x)
s &= 0x007fffff; s &= 0x007fffff;
s |= ey; s |= ey;
y = asfloat(s); y = asfloat(s);
if (FENV_SUPPORT) { if(FENV_SUPPORT)
{
/* handle rounding and inexact exception. */ /* handle rounding and inexact exception. */
uint32_t tiny = predict_false(d2 == 0) ? 0 : 0x01000000; uint32_t tiny = predict_false(d2 == 0) ? 0 : 0x01000000;
tiny |= (d1 ^ d2) & 0x80000000; 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)); return (__builtin_memcmp(s1, s2, n));
} }
#define STB_SPRINTF_IMPLEMENTATION #define STB_SPRINTF_IMPLEMENTATION
#include "stb/stb_sprintf.h" #include "stb/stb_sprintf.h"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,6 @@
#include "platform_debug.c" #include "platform_debug.c"
#include "util/strings.h" #include "util/strings.h"
//---------------------------------------------------------------- //----------------------------------------------------------------
// stb sprintf callback and user struct // 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 <Availability.h> // availability macros
#include<time.h> #include <mach/clock.h>
#include<sys/time.h> // gettimeofday()
#include <mach/mach.h> #include <mach/mach.h>
#include <mach/mach_time.h> #include <mach/mach_time.h>
#include<mach/clock.h> #include <math.h> //fabs()
#include<Availability.h> // availability macros #include <sys/time.h> // gettimeofday()
#include <time.h>
#include<sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/types.h>
#include "platform_clock.h" #include "platform_clock.h"
typedef struct timeval timeval; typedef struct timeval timeval;
typedef struct timespec timespec; typedef struct timespec timespec;
@ -97,7 +96,8 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
u64 noff = OSXGetMonotonicNanoseconds(); u64 noff = OSXGetMonotonicNanoseconds();
u64 foff = (u64)(noff * 1e-9 * CLK_TIMESTAMPS_PER_SECOND); u64 foff = (u64)(noff * 1e-9 * CLK_TIMESTAMPS_PER_SECOND);
ts = __initialTimestamp__ + foff; ts = __initialTimestamp__ + foff;
} break; }
break;
case OC_CLOCK_UPTIME: case OC_CLOCK_UPTIME:
{ {
@ -106,7 +106,8 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
u64 noff = OSXGetUptimeNanoseconds(); u64 noff = OSXGetUptimeNanoseconds();
u64 foff = (u64)(noff * 1e-9 * CLK_TIMESTAMPS_PER_SECOND); u64 foff = (u64)(noff * 1e-9 * CLK_TIMESTAMPS_PER_SECOND);
ts = __initialTimestamp__ + foff; ts = __initialTimestamp__ + foff;
} break; }
break;
case OC_CLOCK_DATE: case OC_CLOCK_DATE:
{ {
@ -115,7 +116,8 @@ u64 oc_clock_timestamp(oc_clock_kind clock)
gettimeofday(&tv, 0); gettimeofday(&tv, 0);
ts = (((u64)tv.tv_sec + CLK_JAN_1970) << 32) ts = (((u64)tv.tv_sec + CLK_JAN_1970) << 32)
+ (u64)(tv.tv_usec * 1e-6 * CLK_TIMESTAMPS_PER_SECOND); + (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); return (ts);
} }
f64 oc_clock_time(oc_clock_kind clock) f64 oc_clock_time(oc_clock_kind clock)
{ {
switch(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 //NOTE(martin): compute monotonic offset and add it to bootup timestamp
u64 noff = OSXGetMonotonicNanoseconds(); u64 noff = OSXGetMonotonicNanoseconds();
return ((f64)noff * 1e-9); return ((f64)noff * 1e-9);
} break; }
break;
case OC_CLOCK_UPTIME: 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 //NOTE(martin): compute uptime offset and add it to bootup timestamp
u64 noff = OSXGetUptimeNanoseconds(); u64 noff = OSXGetUptimeNanoseconds();
return ((f64)noff * 1e-9); return ((f64)noff * 1e-9);
} break; }
break;
case OC_CLOCK_DATE: case OC_CLOCK_DATE:
{ {
@ -157,6 +160,7 @@ f64 oc_clock_time(oc_clock_kind clock)
timeval tv; timeval tv;
gettimeofday(&tv, 0); gettimeofday(&tv, 0);
return (((f64)tv.tv_sec + CLK_JAN_1970) + ((f64)tv.tv_usec * 1e-6)); 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) oc_str8 oc_path_executable(oc_arena* arena)
{@autoreleasepool{ {
@autoreleasepool
{
oc_str8 result = {}; oc_str8 result = {};
u32 size = 0; u32 size = 0;
_NSGetExecutablePath(0, &size); _NSGetExecutablePath(0, &size);
@ -27,7 +29,8 @@ oc_str8 oc_path_executable(oc_arena* arena)
_NSGetExecutablePath(result.ptr, &size); _NSGetExecutablePath(result.ptr, &size);
result.ptr[result.len] = '\0'; result.ptr[result.len] = '\0';
return (result); return (result);
}} }
}
oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path) oc_str8 oc_path_canonical(oc_arena* arena, oc_str8 path)
{ {

View File

@ -9,14 +9,16 @@
#ifndef __PLATFORM_CLOCK_H_ #ifndef __PLATFORM_CLOCK_H_
#define __PLATFORM_CLOCK_H_ #define __PLATFORM_CLOCK_H_
#include"util/typedefs.h"
#include "platform.h" #include "platform.h"
#include "util/typedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif // __cplusplus #endif // __cplusplus
typedef enum { typedef enum
{
OC_CLOCK_MONOTONIC, // clock that increment monotonically OC_CLOCK_MONOTONIC, // clock that increment monotonically
OC_CLOCK_UPTIME, // clock that increment monotonically during uptime OC_CLOCK_UPTIME, // clock that increment monotonically during uptime
OC_CLOCK_DATE // clock that is driven by the platform time 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" } // extern "C"
#endif // __cplusplus #endif // __cplusplus
#endif //__PLATFORM_CLOCK_H_ #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 // Logging
//---------------------------------------------------------------- //----------------------------------------------------------------
typedef enum { OC_LOG_LEVEL_ERROR, typedef enum
{
OC_LOG_LEVEL_ERROR,
OC_LOG_LEVEL_WARNING, OC_LOG_LEVEL_WARNING,
OC_LOG_LEVEL_INFO, 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; 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, const char* fmt,
...); ...);
#endif //__PLATFORM_DEBUG_H_ #endif //__PLATFORM_DEBUG_H_

View File

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

View File

@ -7,6 +7,7 @@
*****************************************************************/ *****************************************************************/
#include "platform_io.h" #include "platform_io.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// File stream read/write API // 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_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, .handle = dir,
.size = path.len, .size = path.len,
.buffer = path.ptr, .buffer = path.ptr,
.open.rights = rights, .open.rights = rights,
.open.flags = flags,}; .open.flags = flags,
};
oc_io_cmp cmp = oc_io_wait_single_req(&req); oc_io_cmp cmp = oc_io_wait_single_req(&req);
return (cmp.handle); return (cmp.handle);

View File

@ -102,7 +102,6 @@ typedef struct oc_io_open_restrict_result
oc_file_desc fd; oc_file_desc fd;
} oc_io_open_restrict_result; } 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_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(); 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(); slot->fd = oc_file_desc_nil();
cmp.handle = oc_file_from_slot(table, slot); cmp.handle = oc_file_from_slot(table, slot);
oc_str8 path = oc_str8_from_buffer(req->size, req->buffer); oc_str8 path = oc_str8_from_buffer(req->size, req->buffer);
if(!path.len) if(!path.len)

View File

@ -8,8 +8,8 @@
#ifndef __PLATFORM_IO_INTERNAL_H_ #ifndef __PLATFORM_IO_INTERNAL_H_
#define __PLATFORM_IO_INTERNAL_H_ #define __PLATFORM_IO_INTERNAL_H_
#include"platform_io.h"
#include "platform.h" #include "platform.h"
#include "platform_io.h"
#if OC_PLATFORM_MACOS || PLATFORM_LINUX #if OC_PLATFORM_MACOS || PLATFORM_LINUX
typedef int oc_file_desc; 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); ORCA_API oc_io_cmp oc_io_wait_single_req_with_table(oc_io_req* req, oc_file_table* table);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// raw io primitives // raw io primitives
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

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

View File

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

View File

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

View File

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

View File

@ -6,8 +6,8 @@
* @revision: * @revision:
* *
*****************************************************************/ *****************************************************************/
#include<sys/mman.h>
#include "platform_memory.h" #include "platform_memory.h"
#include <sys/mman.h>
/*NOTE(martin): /*NOTE(martin):
Linux and MacOS don't make a distinction between reserved and committed memory, contrary to Windows 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 <profileapi.h>
#include"util/typedefs.h"
#include "platform_clock.h" #include "platform_clock.h"
#include "util/typedefs.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif #endif
static u64 __performanceCounterFreq = 0; static u64 __performanceCounterFreq = 0;

View File

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

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