In Progress: working on the new opengl back end and font rasterizer

This commit is contained in:
Allen Webster 2019-07-21 11:16:34 -07:00
parent 8c54e8345e
commit 55d064cf61
45 changed files with 1873 additions and 1030 deletions

View File

@ -24,6 +24,21 @@ round32(f32 v){
return(floor32(v + 0.5f));
}
static f32
f32_ceil32(f32 v){
return((f32)ceil32(v));
}
static f32
f32_floor32(f32 v){
return((f32)floor32(v));
}
static f32
f32_round32(f32 v){
return((f32)round32(v));
}
static i8
round_up_i8(i8 x, i8 b){
x += b - 1;
@ -3342,6 +3357,59 @@ string_find_last(String_Const_u32 str, u32 c){
return(i);
}
static umem
string_find_first_whitespace(String_Const_char str){
umem i = 0;
for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1);
return(i);
}
static umem
string_find_first_whitespace(String_Const_u8 str){
umem i = 0;
for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1);
return(i);
}
static umem
string_find_first_whitespace(String_Const_u16 str){
umem i = 0;
for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1);
return(i);
}
static umem
string_find_first_whitespace(String_Const_u32 str){
umem i = 0;
for (;i < str.size && !character_is_whitespace(str.str[i]); i += 1);
return(i);
}
static imem
string_find_last_whitespace(String_Const_char str){
imem size = (imem)str.size;
imem i = size - 1;
for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1);
return(i);
}
static imem
string_find_last_whitespace(String_Const_u8 str){
imem size = (imem)str.size;
imem i = size - 1;
for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1);
return(i);
}
static imem
string_find_last_whitespace(String_Const_u16 str){
imem size = (imem)str.size;
imem i = size - 1;
for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1);
return(i);
}
static imem
string_find_last_whitespace(String_Const_u32 str){
imem size = (imem)str.size;
imem i = size - 1;
for (;i >= 0 && !character_is_whitespace(str.str[i]); i -= 1);
return(i);
}
static umem
string_find_first_non_whitespace(String_Const_char str){
umem i = 0;

View File

@ -102,6 +102,10 @@
#define OS_MAC 0
#endif
#if !defined(SHIP_MODE)
#define SHIP_MODE 0
#endif
////////////////////////////////
#if COMPILER_CL
@ -160,6 +164,8 @@ typedef i64 imem;
typedef float f32;
typedef double f64;
typedef void Void_Func(void);
#define glue_(a,b) a##b
#define glue(a,b) glue_(a,b)
@ -183,6 +189,7 @@ typedef double f64;
#define Member(S,m) (((S*)0)->m)
#define NullMember(S,m) (&Member(S,m))
#define OffsetOfMember(S,m) PtrAsInt(&Member(S,m))
#define OffsetOfMemberStruct(s,m) PtrDif(&(s)->m, (s))
#define SizeAfterMember(S,m) (sizeof(S) - OffsetOfMember(S,m))
#define CastFromMember(S,m,ptr) (S*)( (u8*)(ptr) - OffsetOfMember(S,m) )
#define IntAsPtr(a) (void*)(((u8*)0) + a)

View File

@ -139,8 +139,6 @@ struct Application_Links;
#define TRY_CREATE_NEW_FACE_SIG(n) Face_ID n(Application_Links *app, Face_Description *description)
#define TRY_MODIFY_FACE_SIG(n) b32 n(Application_Links *app, Face_ID id, Face_Description *description)
#define TRY_RELEASE_FACE_SIG(n) b32 n(Application_Links *app, Face_ID id, Face_ID replacement_id)
#define GET_AVAILABLE_FONT_COUNT_SIG(n) i32 n(Application_Links *app)
#define GET_AVAILABLE_FONT_SIG(n) Available_Font n(Application_Links *app, i32 index)
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, i32 count)
#define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, i32 count)
#define FINALIZE_COLOR_SIG(n) argb_color n(Application_Links *app, int_color color)
@ -320,8 +318,6 @@ typedef GET_FACE_ID_SIG(Get_Face_ID_Function);
typedef TRY_CREATE_NEW_FACE_SIG(Try_Create_New_Face_Function);
typedef TRY_MODIFY_FACE_SIG(Try_Modify_Face_Function);
typedef TRY_RELEASE_FACE_SIG(Try_Release_Face_Function);
typedef GET_AVAILABLE_FONT_COUNT_SIG(Get_Available_Font_Count_Function);
typedef GET_AVAILABLE_FONT_SIG(Get_Available_Font_Function);
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
typedef GET_THEME_COLORS_SIG(Get_Theme_Colors_Function);
typedef FINALIZE_COLOR_SIG(Finalize_Color_Function);
@ -503,8 +499,6 @@ Get_Face_ID_Function *get_face_id;
Try_Create_New_Face_Function *try_create_new_face;
Try_Modify_Face_Function *try_modify_face;
Try_Release_Face_Function *try_release_face;
Get_Available_Font_Count_Function *get_available_font_count;
Get_Available_Font_Function *get_available_font;
Set_Theme_Colors_Function *set_theme_colors;
Get_Theme_Colors_Function *get_theme_colors;
Finalize_Color_Function *finalize_color;
@ -685,8 +679,6 @@ Get_Face_ID_Function *get_face_id_;
Try_Create_New_Face_Function *try_create_new_face_;
Try_Modify_Face_Function *try_modify_face_;
Try_Release_Face_Function *try_release_face_;
Get_Available_Font_Count_Function *get_available_font_count_;
Get_Available_Font_Function *get_available_font_;
Set_Theme_Colors_Function *set_theme_colors_;
Get_Theme_Colors_Function *get_theme_colors_;
Finalize_Color_Function *finalize_color_;
@ -875,8 +867,6 @@ app_links->get_face_id_ = Get_Face_ID;\
app_links->try_create_new_face_ = Try_Create_New_Face;\
app_links->try_modify_face_ = Try_Modify_Face;\
app_links->try_release_face_ = Try_Release_Face;\
app_links->get_available_font_count_ = Get_Available_Font_Count;\
app_links->get_available_font_ = Get_Available_Font;\
app_links->set_theme_colors_ = Set_Theme_Colors;\
app_links->get_theme_colors_ = Get_Theme_Colors;\
app_links->finalize_color_ = Finalize_Color;\
@ -1057,8 +1047,6 @@ static Face_ID get_face_id(Application_Links *app, Buffer_ID buffer_id){return(a
static Face_ID try_create_new_face(Application_Links *app, Face_Description *description){return(app->try_create_new_face(app, description));}
static b32 try_modify_face(Application_Links *app, Face_ID id, Face_Description *description){return(app->try_modify_face(app, id, description));}
static b32 try_release_face(Application_Links *app, Face_ID id, Face_ID replacement_id){return(app->try_release_face(app, id, replacement_id));}
static i32 get_available_font_count(Application_Links *app){return(app->get_available_font_count(app));}
static Available_Font get_available_font(Application_Links *app, i32 index){return(app->get_available_font(app, index));}
static void set_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->set_theme_colors(app, colors, count));}
static void get_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->get_theme_colors(app, colors, count));}
static argb_color finalize_color(Application_Links *app, int_color color){return(app->finalize_color(app, color));}
@ -1239,8 +1227,6 @@ static Face_ID get_face_id(Application_Links *app, Buffer_ID buffer_id){return(a
static Face_ID try_create_new_face(Application_Links *app, Face_Description *description){return(app->try_create_new_face_(app, description));}
static b32 try_modify_face(Application_Links *app, Face_ID id, Face_Description *description){return(app->try_modify_face_(app, id, description));}
static b32 try_release_face(Application_Links *app, Face_ID id, Face_ID replacement_id){return(app->try_release_face_(app, id, replacement_id));}
static i32 get_available_font_count(Application_Links *app){return(app->get_available_font_count_(app));}
static Available_Font get_available_font(Application_Links *app, i32 index){return(app->get_available_font_(app, index));}
static void set_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->set_theme_colors_(app, colors, count));}
static void get_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->get_theme_colors_(app, colors, count));}
static argb_color finalize_color(Application_Links *app, int_color color){return(app->finalize_color_(app, color));}

View File

@ -15,6 +15,9 @@ global_const u64 table_erased_slot = 1;
global_const u64 table_empty_key = 0;
global_const u64 table_erased_key = max_u64;
global_const u32 table_empty_u32_key = 0;
global_const u32 table_erased_u32_key = max_u32;
////////////////////////////////
internal Table_u64_u64
@ -160,6 +163,148 @@ table_erase(Table_u64_u64 *table, u64 key){
////////////////////////////////
internal Table_u32_u16
make_table_u32_u16(Base_Allocator *allocator, u32 slot_count){
Table_u32_u16 table = {};
table.allocator = allocator;
slot_count = clamp_bot(8, slot_count);
Data mem = base_allocate(allocator, slot_count*(sizeof(*table.keys) + sizeof(*table.vals)));
block_zero(mem.data, mem.size);
table.memory = mem.data;
table.keys = (u32*)table.memory;
table.vals = (u16*)(table.keys + slot_count);
table.slot_count = slot_count;
table.used_count = 0;
table.dirty_count = 0;
return(table);
}
internal void
table_free(Table_u32_u16 *table){
base_free(table->allocator, table->memory);
block_zero_struct(table);
}
internal Table_Lookup
table_lookup(Table_u32_u16 *table, u32 key){
Table_Lookup result = {};
if (key != table_empty_u32_key && key != table_erased_u32_key){
u32 *keys = table->keys;
u32 slot_count = table->slot_count;
u32 first_index = key % slot_count;
u32 index = first_index;
result.hash = key;
for (;;){
if (key == keys[index]){
result.index = index;
result.found_match = true;
result.found_empty_slot = false;
result.found_erased_slot = false;
break;
}
if (table_empty_u32_key == keys[index]){
result.index = index;
result.found_empty_slot = true;
result.found_erased_slot = false;
break;
}
if (table_erased_u32_key == keys[index] && !result.found_erased_slot){
result.index = index;
result.found_erased_slot = true;
}
index += 1;
if (index >= slot_count){
index = 0;
}
if (index == first_index){
break;
}
}
}
return(result);
}
internal b32
table_read(Table_u32_u16 *table, u32 key, u16 *val_out){
b32 result = false;
Table_Lookup lookup = table_lookup(table, key);
if (lookup.found_match){
*val_out = table->vals[lookup.index];
result = true;
}
return(result);
}
internal void
table_insert__inner(Table_u32_u16 *table, Table_Lookup lookup, u32 key, u16 val){
Assert(lookup.found_empty_slot || lookup.found_erased_slot);
table->keys[lookup.index] = key;
table->vals[lookup.index] = val;
table->used_count += 1;
if (lookup.found_empty_slot){
table->dirty_count += 1;
}
}
internal b32
table_rehash(Table_u32_u16 *dst, Table_u32_u16 *src){
b32 result = false;
u32 src_slot_count = src->slot_count;
if ((dst->dirty_count + src->used_count)*8 < dst->slot_count*7){
u32 *src_keys = src->keys;
for (u32 i = 0; i < src_slot_count; i += 1){
u32 key = src_keys[i];
if (key != table_empty_u32_key && key != table_erased_u32_key){
Table_Lookup lookup = table_lookup(dst, key);
table_insert__inner(dst, lookup, key, src->vals[i]);
}
}
result = true;
}
return(result);
}
internal b32
table_insert(Table_u32_u16 *table, u32 key, u16 val){
b32 result = false;
Table_Lookup lookup = table_lookup(table, key);
if (!lookup.found_match){
if ((table->dirty_count + 1)*8 >= table->slot_count*7){
i32 new_slot_count = table->slot_count;
if (table->used_count*2 >= table->slot_count){
new_slot_count = table->slot_count*4;
}
Table_u32_u16 new_table = make_table_u32_u16(table->allocator, new_slot_count);
table_rehash(&new_table, table);
table_free(table);
*table = new_table;
lookup = table_lookup(table, key);
Assert(lookup.found_empty_slot);
}
table_insert__inner(table, lookup, key, val);
result = true;
}
return(result);
}
internal b32
table_erase(Table_u32_u16 *table, u32 key){
b32 result = false;
Table_Lookup lookup = table_lookup(table, key);
if (lookup.found_match){
table->keys[lookup.index] = 0;
table->vals[lookup.index] = 0;
table->used_count -= 1;
result = true;
}
return(result);
}
////////////////////////////////
internal Table_Data_u64
make_table_Data_u64(Base_Allocator *allocator, u32 slot_count){
Table_Data_u64 table = {};

View File

@ -25,6 +25,16 @@ struct Table_u64_u64{
u32 dirty_count;
};
struct Table_u32_u16{
Base_Allocator *allocator;
void *memory;
u32 *keys;
u16 *vals;
u32 slot_count;
u32 used_count;
u32 dirty_count;
};
struct Table_Data_u64{
Base_Allocator *allocator;
void *memory;

View File

@ -775,9 +775,12 @@ DOC_SEE(Buffer_Setting_ID)
new_value = 48;
}
if (new_value != file->settings.display_width){
#if 0
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
#endif
Face *face = 0;
file->settings.display_width = new_value;
file_measure_wraps(system, &models->mem, file, font);
file_measure_wraps(system, &models->mem, file, face);
adjust_views_looking_at_file_to_new_cursor(system, models, file);
}
}break;
@ -789,9 +792,12 @@ DOC_SEE(Buffer_Setting_ID)
new_value = 0;
}
if (new_value != file->settings.minimum_base_display_width){
#if 0
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
#endif
Face *face = 0;
file->settings.minimum_base_display_width = new_value;
file_measure_wraps(system, &models->mem, file, font);
file_measure_wraps(system, &models->mem, file, face);
adjust_views_looking_at_file_to_new_cursor(system, models, file);
}
}break;
@ -867,11 +873,14 @@ DOC_SEE(Buffer_Setting_ID)
}
if (full_remeasure){
#if 0
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
#endif
Face *face = 0;
file_allocate_character_starts_as_needed(&models->mem.heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
buffer_measure_character_starts(system, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, face);
adjust_views_looking_at_file_to_new_cursor(system, models, file);
}
}break;
@ -2928,7 +2937,11 @@ DOC_RETURN(Returns the largest face ID that could be valid. There is no guarant
*/
{
Models *models = (Models*)app->cmd_context;
Face_ID result = 0;
#if 0
Face_ID result = models->system->font.get_largest_id();
#endif
NotImplemented;
return(result);
}
@ -2946,6 +2959,8 @@ DOC_RETURN(Returns true if the given id was a valid face and the change was made
b32 did_change = false;
NotImplemented;
#if 0
Font_Pointers font = system->font.get_pointers_by_id(id);
if (font.valid){
did_change = true;
@ -2957,6 +2972,7 @@ DOC_RETURN(Returns true if the given id was a valid face and the change was made
models->global_font_id = id;
}
}
#endif
return(did_change);
}
@ -3132,26 +3148,26 @@ Global_History_Edit_Group_End(Application_Links *app){
}
internal void
font_pointers_to_face_description(Font_Pointers font, Face_Description *description){
Font_Metrics *metrics = font.metrics;
umem len = cstring_length(metrics->name);
block_copy(description->font.name, metrics->name, len);
face_to_face_description(Face *face, Face_Description *description){
umem size = clamp_top(face->name.size, sizeof(description->font.name) - 1);
block_copy(description->font.name, face->name.str, size);
description->font.name[size] = 0;
description->font.in_local_font_folder = face->settings.stub.in_font_folder;
Font_Settings *settings = font.settings;
description->font.in_local_font_folder = settings->stub.in_font_folder;
description->pt_size = settings->parameters.pt_size;
description->bold = settings->parameters.bold;
description->italic = settings->parameters.italics;
description->underline = settings->parameters.underline;
description->hinting = settings->parameters.use_hinting;
description->pt_size = face->settings.parameters.pt_size;
description->bold = face->settings.parameters.bold;
description->italic = face->settings.parameters.italics;
description->underline = face->settings.parameters.underline;
description->hinting = face->settings.parameters.use_hinting;
}
internal b32
face_description_to_settings(System_Functions *system, Face_Description description, Font_Settings *settings){
face_description_to_settings(System_Functions *system, Face_Description description, Face_Settings *settings){
b32 success = false;
String_Const_u8 desc_name = SCu8(description.font.name);
if (description.font.in_local_font_folder){
#if 0
i32 count = system->font.get_loadable_count();
for (i32 i = 0; i < count; ++i){
Font_Loadable_Description loadable = {};
@ -3170,6 +3186,7 @@ face_description_to_settings(System_Functions *system, Face_Description descript
}
}
}
#endif
}
else{
success = true;
@ -3206,11 +3223,18 @@ DOC_RETURN(Returns true if the given id was a valid face and the change was made
b32 did_change = false;
if (api_check_buffer(file)){
System_Functions *system = models->system;
#if 0
Font_Pointers font = system->font.get_pointers_by_id(id);
if (font.valid){
did_change = true;
file_set_font(system, models, file, id);
}
#endif
Face *face = 0;
if (face != 0){
did_change = true;
file_set_font(system, models, file, id);
}
}
return(did_change);
}
@ -3232,11 +3256,18 @@ DOC_SEE(Face_Description)
System_Functions *system = models->system;
Face_Description description = {};
if (id != 0){
#if 0
Font_Pointers font = system->font.get_pointers_by_id(id);
if (font.valid){
font_pointers_to_face_description(font, &description);
Assert(description.font.name[0] != 0);
}
#endif
Face *face = 0;
if (face != 0){
face_to_face_description(face, &description);
Assert(description.font.name[0] != 0);
}
}
else{
description.pt_size = models->settings.font_size;
@ -3251,11 +3282,18 @@ Get_Face_Metrics(Application_Links *app, Face_ID face_id){
System_Functions *system = models->system;
Face_Metrics result = {};
if (face_id != 0){
#if 0
Font_Pointers font = system->font.get_pointers_by_id(face_id);
if (font.valid){
result.line_height = (f32)font.metrics->height;
result.typical_character_width = font.metrics->sub_advances[1];
}
#endif
Face *face = 0;
if (face != 0){
result.line_height = (f32)face->height;
result.typical_character_width = face->sub_advances[1];
}
}
return(result);
}
@ -3303,9 +3341,12 @@ DOC_SEE(Face_Description)
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Face_ID id = 0;
Font_Settings settings;
Face_Settings settings = {};
if (face_description_to_settings(system, *description, &settings)){
#if 0
id = system->font.face_allocate_and_init(&settings);
#endif
NotImplemented;
}
return(id);
}
@ -3327,7 +3368,7 @@ DOC_SEE(try_create_new_face)
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
b32 success = false;
Font_Settings settings;
Face_Settings settings = {};
if (face_description_to_settings(system, *description, &settings)){
if (alter_font_and_update_files(system, models, id, &settings)){
success = true;
@ -3354,37 +3395,6 @@ DOC_RETURN(Returns true on success and zero on failure.)
return(success);
}
API_EXPORT i32
Get_Available_Font_Count(Application_Links *app)
/*
DOC(An available font is a font that the 4coder font system detected on initialization. Available fonts either come from the font folder in the same path as the 4ed executable, or from the system fonts. Attempting to load fonts not in returned by available fonts will likely fail, but is permitted. Available fonts are not updated after initialization. Just because a font is returned by the available font system does not necessarily mean that it can be loaded.)
DOC_RETURN(Returns the number of available fonts that the user can query.)
*/
{
Models *models = (Models*)app->cmd_context;
i32 count = models->system->font.get_loadable_count();
return(count);
}
API_EXPORT Available_Font
Get_Available_Font(Application_Links *app, i32 index)
/*
DOC_PARAM(index, The index of the available font to retrieve. Must be in the range [0,count-1] where count is the value returned by get_available_font_count.)
DOC_RETURN(Returns a valid Available_Font if index is in the required range. Otherwise returns an invalid Available_Font. An Available_Font is valid if and only if it's name field contains a string with a non-zero length (i.e. font.name[0] != 0))
DOC_SEE(get_available_font_count)
*/
{
Models *models = (Models*)app->cmd_context;
Available_Font available = {};
Font_Loadable_Description description = {};
models->system->font.get_loadable(index, &description);
if (description.valid){
memcpy(available.name, description.display_name, description.display_len);
available.in_local_font_folder = description.stub.in_font_folder;
}
return(available);
}
API_EXPORT void
Set_Theme_Colors(Application_Links *app, Theme_Color *colors, i32 count)
/*
@ -3933,7 +3943,10 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_
b32 wrapped = !file->settings.unwrapped_lines;
Face_ID font_id = file->settings.font_id;
#if 0
Font_Pointers font = system->font.get_pointers_by_id(font_id);
#endif
Face *face = 0;
Full_Cursor intermediate_cursor = file_compute_cursor(system, file, seek_line_char(buffer_point.line_number, 1));
f32 scroll_x = buffer_point.pixel_shift.x;
@ -3962,7 +3975,7 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_
params.start_cursor = render_cursor;
params.wrapped = wrapped;
params.system = system;
params.font = font;
params.face = face;
params.virtual_white = file->settings.virtual_white;
params.wrap_slashes = file->settings.wrap_indicator;
params.one_past_last_abs_pos = one_past_last;

View File

@ -17,9 +17,9 @@
#include "4coder_API/4coder_custom.h"
#include "4coder_base_types.h"
#include "4coder_table.h"
#include "4ed_font.h"
#include "4ed_system.h"
#include "4coder_table.h"
#include "4coder_base_types.cpp"
#include "4coder_string_match.cpp"
@ -47,7 +47,6 @@ struct Mem_Options{
#define FCPP_FORBID_MALLOC
#include "4coder_lib/4cpp_lexer.h"
#include "4ed_log.h"
#include "4ed_ptr_check.h"
#include "4ed_memory_bank.h"
#include "4ed_dynamic_variables.h"

View File

@ -676,7 +676,7 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){
}
internal void
buffer_measure_character_starts(System_Functions *system, Font_Pointers font, Gap_Buffer *buffer, i32 *character_starts, i32 mode, i32 virtual_white){
buffer_measure_character_starts(System_Functions *system, Gap_Buffer *buffer, i32 *character_starts, i32 mode, i32 virtual_white){
Assert(mode == 0);
Gap_Buffer_Stream stream = {};
@ -705,7 +705,7 @@ buffer_measure_character_starts(System_Functions *system, Font_Pointers font, Ga
for (; i < stream.end; ++i){
u8 ch = (u8)stream.data[i];
translating_fully_process_byte(system, font, &tran, ch, i, size, &emits);
translating_fully_process_byte(system, &tran, ch, i, size, &emits);
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
@ -781,7 +781,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
S.skipping_whitespace = false;
}
translating_fully_process_byte(params.system, params.font, &S.tran, ch, S.i, S.size, &S.emits);
translating_fully_process_byte(params.system, &S.tran, ch, S.i, S.size, &S.emits);
}
for (TRANSLATION_EMIT_LOOP(S.J, S.emits)){
@ -809,10 +809,10 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para
else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){
if (!S.skipping_whitespace){
if (S.behavior.do_codepoint_advance){
S.current_adv = font_get_glyph_advance(params.system, params.font.settings, params.font.metrics, params.font.pages, S.step.value);
S.current_adv = font_get_glyph_advance(params.system, params.face, S.step.value);
}
else{
S.current_adv = params.font.metrics->byte_advance;
S.current_adv = params.face->byte_advance;
}
S.did_wrap = false;
@ -942,7 +942,7 @@ buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 li
}
internal void
buffer_remeasure_character_starts(System_Functions *system, Font_Pointers font, Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 *character_starts, i32 mode, i32 virtual_whitespace){
buffer_remeasure_character_starts(System_Functions *system, Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 *character_starts, i32 mode, i32 virtual_whitespace){
Assert(mode == 0);
i32 new_line_count = buffer->line_count;
@ -990,7 +990,7 @@ buffer_remeasure_character_starts(System_Functions *system, Font_Pointers font,
do{
for (; char_i < stream.end; ++char_i){
u8 ch = (u8)stream.data[char_i];
translating_fully_process_byte(system, font, &tran, ch, char_i, size, &emits);
translating_fully_process_byte(system, &tran, ch, char_i, size, &emits);
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
@ -1260,7 +1260,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
DrCase(4);
}
S.font_height = params.font.metrics->height;
S.font_height = (i32)(params.face->height);
S.xy_seek = (params.seek.type == buffer_seek_wrapped_xy || params.seek.type == buffer_seek_unwrapped_xy);
S.size = buffer_size(params.buffer);
@ -1417,7 +1417,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
for (; S.i < S.stream.end; ++S.i){
{
u8 ch = (u8)S.stream.data[S.i];
translating_fully_process_byte(params.system, params.font, &S.tran, ch, S.i, S.size, &S.emits);
translating_fully_process_byte(params.system, &S.tran, ch, S.i, S.size, &S.emits);
}
for (TRANSLATION_EMIT_LOOP(S.J, S.emits)){
@ -1448,10 +1448,10 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
else if (S.behavior.do_number_advance || S.behavior.do_codepoint_advance){
if (S.behavior.do_codepoint_advance){
S.ch_width = font_get_glyph_advance(params.system, params.font.settings, params.font.metrics, params.font.pages, S.step.value);
S.ch_width = font_get_glyph_advance(params.system, params.face, S.step.value);
}
else{
S.ch_width = params.font.metrics->byte_advance;
S.ch_width = params.face->byte_advance;
}
if (S.step.i >= S.wrap_unit_end){
@ -1628,7 +1628,7 @@ internal Render_Item_Write
write_render_item(Render_Item_Write write, i32 index, u32 codepoint, u32 flags,
Render_Item_Flag render_flags){
if (write.item < write.item_end){
f32 ch_width = font_get_glyph_advance(write.system, write.font.settings, write.font.metrics, write.font.pages, codepoint);
f32 ch_width = font_get_glyph_advance(write.system, write.face, codepoint);
b32 visible_on_layout = (write.x_min <= write.x + ch_width && write.x <= write.x_max);
@ -1695,12 +1695,12 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
S.write.x = S.shift_x + line_shift;
S.write.y = S.shift_y;
S.write.system = params.system;
S.write.font = params.font;
S.write.font_height = params.font.metrics->height;
S.write.face = params.face;
S.write.font_height = (i32)params.face->height;
S.write.x_min = params.port_x;
S.write.x_max = params.port_x + params.clip_w;
S.byte_advance = params.font.metrics->byte_advance;
S.byte_advance = params.face->byte_advance;
if (params.virtual_white){
S.skipping_whitespace = true;
@ -1714,7 +1714,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
for (; S.i < S.stream.end; ++S.i){
{
u8 ch = (u8)S.stream.data[S.i];
translating_fully_process_byte(params.system, params.font, &S.tran, ch, S.i, S.size, &S.emits);
translating_fully_process_byte(params.system, &S.tran, ch, S.i, S.size, &S.emits);
}
for (TRANSLATION_EMIT_LOOP(S.J, S.emits)){
@ -1814,9 +1814,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32
case '\t':
{
S.ch_width = font_get_glyph_advance(params.system, params.font.settings,
params.font.metrics, params.font.pages,
'\t');
S.ch_width = font_get_glyph_advance(params.system, params.face, '\t');
f32 new_x = S.write.x + S.ch_width;
S.write = write_render_item(S.write, I, ' ', 0, flags);

View File

@ -90,7 +90,7 @@ struct Buffer_Measure_Wrap_Params{
Gap_Buffer *buffer;
i32 *wrap_line_index;
System_Functions *system;
Font_Pointers font;
Face *face;
b32 virtual_white;
};
@ -124,7 +124,7 @@ struct Buffer_Cursor_Seek_Params{
Gap_Buffer *buffer;
Buffer_Seek seek;
System_Functions *system;
Font_Pointers font;
Face *face;
i32 *wrap_line_index;
i32 *character_starts;
b32 virtual_white;
@ -186,7 +186,7 @@ struct Render_Item_Write{
f32 x;
f32 y;
System_Functions *system;
Font_Pointers font;
Face *face;
i32 font_height;
f32 x_min;
f32 x_max;
@ -207,7 +207,7 @@ struct Buffer_Render_Params{
Full_Cursor start_cursor;
i32 wrapped;
System_Functions *system;
Font_Pointers font;
Face *face;
b32 virtual_white;
i32 wrap_slashes;
i32 one_past_last_abs_pos;

View File

@ -10,7 +10,7 @@
// TOP
internal void
wrap_state_init(System_Functions *system, Code_Wrap_State *state, Editing_File *file, Font_Pointers font){
wrap_state_init(System_Functions *system, Code_Wrap_State *state, Editing_File *file, Face *face){
state->token_array = file->state.token_array;
state->token_ptr = state->token_array.tokens;
state->end_token = state->token_ptr + state->token_array.count;
@ -25,10 +25,10 @@ wrap_state_init(System_Functions *system, Code_Wrap_State *state, Editing_File *
state->size = size;
state->i = 0;
state->font = font;
state->face = face;
state->tab_indent_amount = font_get_glyph_advance(system, font.settings, font.metrics, font.pages, '\t');
state->byte_advance = font.metrics->byte_advance;
state->tab_indent_amount = font_get_glyph_advance(system, face, '\t');
state->byte_advance = face->byte_advance;
state->tran = null_buffer_translating_state;
}
@ -41,7 +41,7 @@ wrap_state_set_top(Code_Wrap_State *state, f32 line_shift){
}
internal Code_Wrap_Step
wrap_state_consume_token(System_Functions *system, Font_Pointers font, Code_Wrap_State *state, i32 fixed_end_point){
wrap_state_consume_token(System_Functions *system, Face *face, Code_Wrap_State *state, i32 fixed_end_point){
Code_Wrap_Step result = {};
i32 i = state->i;
@ -123,7 +123,7 @@ wrap_state_consume_token(System_Functions *system, Font_Pointers font, Code_Wrap
}
u8 ch = (u8)state->stream.data[i];
translating_fully_process_byte(system, font, &state->tran, ch, i, state->size, &state->emits);
translating_fully_process_byte(system, &state->tran, ch, i, state->size, &state->emits);
for (TRANSLATION_EMIT_LOOP(state->J, state->emits)){
TRANSLATION_GET_STEP(state->step, state->behavior, state->J, state->emits);
@ -136,7 +136,7 @@ wrap_state_consume_token(System_Functions *system, Font_Pointers font, Code_Wrap
u32 n = state->step.value;
f32 adv = 0;
if (state->behavior.do_codepoint_advance){
adv = font_get_glyph_advance(system, state->font.settings, state->font.metrics, state->font.pages, n);
adv = font_get_glyph_advance(system, state->face, n);
if (n != ' ' && n != '\t'){
skipping_whitespace = false;
@ -439,7 +439,7 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
}
internal void
file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Font_Pointers font){
file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Face *face){
Heap *heap = &mem->heap;
Arena *scratch = &mem->arena;
@ -453,7 +453,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
params.buffer = &file->state.buffer;
params.wrap_line_index = file->state.wrap_line_index;
params.system = system;
params.font = font;
params.face = face;
params.virtual_white = file->settings.virtual_white;
f32 width = (f32)file->settings.display_width;
@ -484,7 +484,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
i32 max_wrap_indent_mark = Million(1);
if (params.virtual_white && file->state.tokens_complete && !file->state.still_lexing){
wrap_state_init(system, &wrap_state, file, font);
wrap_state_init(system, &wrap_state, file, face);
use_tokens = true;
potential_marks = push_array(scratch, Potential_Wrap_Indent_Pair, floor32(width));
@ -531,7 +531,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
for (; i < stream.end; ++i){
{
u8 ch = stream.data[i];
translating_fully_process_byte(system, font, &tran, ch, i, size, &emits);
translating_fully_process_byte(system, &tran, ch, i, size, &emits);
}
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
@ -545,7 +545,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
word_stage = 1;
}
else{
f32 adv = font_get_glyph_advance(params.system, params.font.settings, params.font.metrics, params.font.pages, codepoint);
f32 adv = font_get_glyph_advance(params.system, params.face, codepoint);
x += adv;
self_x += adv;
@ -659,7 +659,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
for (; i < stream.end; ++i){
{
u8 ch = stream.data[i];
translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits);
translating_fully_process_byte(system, &tran, ch, i, end_i, &emits);
}
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
@ -680,7 +680,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
for (; i < stream.end; ++i){
{
u8 ch = stream.data[i];
translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits);
translating_fully_process_byte(system, &tran, ch, i, end_i, &emits);
}
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
@ -690,7 +690,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
goto doublebreak_stage1;
}
f32 adv = font_get_glyph_advance(params.system, params.font.settings, params.font.metrics, params.font.pages, buffer_step.value);
f32 adv = font_get_glyph_advance(params.system, params.face, buffer_step.value);
x += adv;
if (!first_word && x > current_width){
@ -715,7 +715,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
for (; i < stream.end; ++i){
{
u8 ch = stream.data[i];
translating_fully_process_byte(system, font, &tran, ch, i, end_i, &emits);
translating_fully_process_byte(system, &tran, ch, i, end_i, &emits);
}
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
@ -726,7 +726,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
goto doublebreak_stage2;
}
f32 adv = font_get_glyph_advance(params.system, params.font.settings, params.font.metrics, params.font.pages, buffer_step.value);
f32 adv = font_get_glyph_advance(params.system, params.face, buffer_step.value);
x += adv;
}
}
@ -747,7 +747,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
}
if (!emit_comment_position){
step = wrap_state_consume_token(system, font, &wrap_state, next_line_start);
step = wrap_state_consume_token(system, face, &wrap_state, next_line_start);
}
b32 need_to_choose_a_wrap = false;
@ -874,7 +874,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
wrap_state = original_wrap_state;
for (;;){
step = wrap_state_consume_token(system, font, &wrap_state, wrap_position);
step = wrap_state_consume_token(system, face, &wrap_state, wrap_position);
if (step.position_end >= wrap_position){
break;
}
@ -900,7 +900,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
++real_count;
for (i32 l = 0; wrap_state.i < next_line_start && l < 3; ++l){
wrap_state_consume_token(system, font, &wrap_state, next_line_start);
wrap_state_consume_token(system, face, &wrap_state, next_line_start);
}
}

View File

@ -42,7 +42,7 @@ struct Code_Wrap_State{
i32 size;
i32 i;
Font_Pointers font;
Face *face;
f32 tab_indent_amount;
f32 byte_advance;
@ -69,7 +69,7 @@ struct Wrap_Current_Shift{
};
internal void
file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Font_Pointers font);
file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Face *face);
#endif

View File

@ -282,14 +282,11 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range
i32 new_line_count = buffer_count_newlines(buffer, edit.range.first, edit.range.first + edit.length);
i32 line_shift = new_line_count - replaced_line_count;
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
Assert(font.valid);
file_grow_starts_as_needed(heap, buffer, line_shift);
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
file_allocate_character_starts_as_needed(heap, file);
buffer_remeasure_character_starts(system, font, buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white);
buffer_remeasure_character_starts(system, buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white);
// NOTE(allen): token fixing
if (file->settings.tokens_exist){
@ -297,7 +294,14 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range
}
// NOTE(allen): wrap meta data
file_measure_wraps(system, &models->mem, file, font);
#if 0
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
Assert(font.valid);
#endif
Face *face = 0;
Assert(face != 0);
file_measure_wraps(system, &models->mem, file, face);
// NOTE(allen): cursor fixing
edit_fix_markers(system, models, file, edit);

View File

@ -238,8 +238,12 @@ file_compute_partial_cursor(Editing_File *file, Buffer_Seek seek){
internal Full_Cursor
file_compute_cursor__inner(System_Functions *system, Editing_File *file, Buffer_Seek seek, b32 return_hint){
#if 0
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
Assert(font.valid);
#endif
Face *face = 0;
Assert(face != 0);
Full_Cursor result = {};
@ -247,7 +251,7 @@ file_compute_cursor__inner(System_Functions *system, Editing_File *file, Buffer_
params.buffer = &file->state.buffer;
params.seek = seek;
params.system = system;
params.font = font;
params.face = face;
params.wrap_line_index = file->state.wrap_line_index;
params.character_starts = file->state.character_starts;
params.virtual_white = file->settings.virtual_white;
@ -446,15 +450,19 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
Face_ID font_id = models->global_font_id;
file->settings.font_id = font_id;
#if 0
Font_Pointers font = system->font.get_pointers_by_id(font_id);
Assert(font.valid);
#endif
Face *face = 0;
Assert(face != 0);
file_measure_starts(heap, &file->state.buffer);
file_allocate_character_starts_as_needed(heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
buffer_measure_character_starts(system, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
file_measure_wraps(system, &models->mem, file, face);
//adjust_views_looking_at_files_to_new_cursor(system, models, file);
file->lifetime_object = lifetime_alloc_object(heap, &models->lifetime_allocator, DynamicWorkspace_Buffer, file);

View File

@ -9,6 +9,9 @@
// TOP
// TODO(allen): This is really "renderer font helpers or something like that"
#if 0
internal Face_ID
font_get_id_by_name(System_Functions *system, String_Const_u8 name){
Face_ID id = 0;
@ -155,12 +158,6 @@ font_make_page(System_Functions *system, Font_Settings *settings, Font_Metrics *
return(new_page);
}
internal b32
font_can_render(System_Functions *system, Font_Settings *settings, Font_Metrics *metrics, Font_Page_Storage *pages, u32 codepoint){
b32 result = (codepoint <= 0x10FFFF);
return(result);
}
///////
// HACK(allen): Hack optimizations
struct Font_Cached_Lookup_Result{
@ -220,6 +217,14 @@ font_get_glyph_advance(System_Functions *system, Font_Settings *settings, Font_M
}
return(result);
}
#endif
internal f32
font_get_glyph_advance(System_Functions *system, Face *face, u32 codepoint){
f32 result = 0.f;
NotImplemented;
return(result);
}
// BOTTOM

View File

@ -12,7 +12,6 @@
#if !defined(FCODER_FONT_H)
#define FCODER_FONT_H
// NOTE(allen): A description of an available font.
struct Font_Loadable_Stub{
b32 load_from_path;
b32 in_font_folder;
@ -20,15 +19,7 @@ struct Font_Loadable_Stub{
char name[256];
};
struct Font_Loadable_Description{
b32 valid;
Font_Loadable_Stub stub;
i32 display_len;
char display_name[64];
};
// NOTE(allen): Settings that the are specified that determine how a font should be loaded and rendered.
struct Font_Parameters{
struct Face_Parameters{
i32 pt_size;
b32 italics;
b32 bold;
@ -36,129 +27,58 @@ struct Font_Parameters{
b32 use_hinting;
};
struct Font_Settings{
struct Face_Settings{
Font_Loadable_Stub stub;
Font_Parameters parameters;
Face_Parameters parameters;
};
// NOTE(allen): Data about the font true for the entire font as a whole.
struct Font_Metrics{
i32 name_len;
char name[256];
struct Glyph_Bounds{
Rect_f32 uv;
f32 w;
Rect_f32 xy_off;
};
typedef i32 Texture_Kind;
struct Face{
Face_Settings settings;
i32 height;
i32 ascent;
i32 descent;
i32 line_skip;
i32 advance;
// NOTE(allen): Metrics
String_Const_u8 name;
f32 height;
f32 ascent;
f32 descent;
f32 line_skip;
f32 advance;
f32 underline_yoff1;
f32 underline_yoff2;
f32 byte_advance;
f32 sub_advances[3];
};
// NOTE(allen): The pages of glyph data.
#define GLYPHS_PER_PAGE 256
struct Glyph_Bounds{
f32 x0, x1;
f32 y0, y1;
f32 xoff, yoff;
f32 xoff2, yoff2;
};
global_const Glyph_Bounds null_glyph_bounds = {};
struct Glyph_Page{
u32 page_number;
b32 has_layout;
f32 advance[GLYPHS_PER_PAGE];
Glyph_Bounds glyphs[GLYPHS_PER_PAGE];
i32 tex_width, tex_height;
// NOTE(allen): Glyph data
Table_u32_u16 codepoint_to_index_table;
i32 index_count;
Glyph_Bounds *bounds;
Glyph_Bounds white;
b32 has_gpu_setup;
u32 gpu_tex;
Texture_Kind gpu_texture_kind;
u32 gpu_texture;
Vec3_f32 gpu_texture_dim;
};
#define FONT_PAGE_EMPTY ((Glyph_Page*)0)
#define FONT_PAGE_DELETED ((Glyph_Page*)(1))
#define FONT_PAGE_MAX 0x1100
////////////////////////////////
struct Font_Page_Storage{
Glyph_Page **pages;
u32 page_count;
u32 page_max;
// Hack optimizations
struct Page_Cache{
u32 page_number;
Glyph_Page *page;
};
Page_Cache cache[16];
};
// NOTE(allen): Types of refernces fonts.
struct Font_Pointers{
b32 valid;
Font_Settings *settings;
Font_Metrics *metrics;
Font_Page_Storage *pages;
};
typedef u32 Get_GPU_Texture_Function(Vec3_i32 dim, Texture_Kind texture_kind);
typedef b32 Fill_GPU_Texture_Function(Texture_Kind texture_kind, u32 gpu_texture,
Vec3_i32 p, Vec3_i32 dim, void *data);
// NOTE(allen): Platform layer calls - implemented in a "font provider"
#define Sys_Font_Get_Loadable_Count_Sig(n) i32 (n)(void)
typedef Sys_Font_Get_Loadable_Count_Sig(Font_Get_Loadable_Count_Function);
#define Sys_Font_Get_Loadable_Sig(n,i,o) void (n)(i32 i, Font_Loadable_Description *o)
typedef Sys_Font_Get_Loadable_Sig(Font_Get_Loadable_Function, index, out);
#define Sys_Font_Face_Allocate_And_Init_Sig(n,s) Face_ID (n)(Font_Settings *s)
typedef Sys_Font_Face_Allocate_And_Init_Sig(Font_Face_Allocate_And_Init_Function, settings);
#define Sys_Font_Face_Change_Settings_Sig(n,id,s) b32 (n)(Face_ID id, Font_Settings *s)
typedef Sys_Font_Face_Change_Settings_Sig(Font_Face_Change_Settings_Function, font_id, new_settings);
#define Sys_Font_Face_Release_Sig(n,id) b32 (n)(Face_ID id)
typedef Sys_Font_Face_Release_Sig(Font_Face_Release_Function, font_id);
#define Sys_Font_Get_Largest_ID_Sig(n) Face_ID (n)(void)
typedef Sys_Font_Get_Largest_ID_Sig(Font_Get_Largest_ID_Function);
#define Sys_Font_Get_Count_Sig(n) i32 (n)(void)
typedef Sys_Font_Get_Count_Sig(Font_Get_Count_Function);
#define Sys_Font_Get_Name_By_ID_Sig(n, font_id, out, cap) i32 (n)(Face_ID font_id, char *out, u32 cap)
typedef Sys_Font_Get_Name_By_ID_Sig(Font_Get_Name_By_ID_Function, font_id, out, cap);
#define Sys_Font_Get_Pointers_By_ID_Sig(n, font_id) Font_Pointers (n)(Face_ID font_id)
typedef Sys_Font_Get_Pointers_By_ID_Sig(Font_Get_Pointers_By_ID_Function, font_id);
#define Sys_Font_Load_Page_Sig(n,s,m,p,pn) void (n)(Font_Settings *s, Font_Metrics *m, Glyph_Page *p, u32 pn)
typedef Sys_Font_Load_Page_Sig(Font_Load_Page_Function, settings, metrics, page, page_number);
#define Sys_Font_Allocate_Sig(n,size) void* (n)(i32 size)
typedef Sys_Font_Allocate_Sig(Font_Allocate_Function,size);
#define Sys_Font_Free_Sig(n,ptr) void (n)(void *ptr)
typedef Sys_Font_Free_Sig(Font_Free_Function,ptr);
struct Font_Functions{
Font_Get_Loadable_Count_Function *get_loadable_count;
Font_Get_Loadable_Function *get_loadable;
Font_Face_Allocate_And_Init_Function *face_allocate_and_init;
Font_Face_Change_Settings_Function *face_change_settings;
Font_Face_Release_Function *face_release;
Font_Get_Largest_ID_Function *get_largest_id;
Font_Get_Count_Function *get_count;
Font_Get_Name_By_ID_Function *get_name_by_id;
Font_Get_Pointers_By_ID_Function *get_pointers_by_id;
Font_Load_Page_Function *load_page;
Font_Allocate_Function *allocate;
Font_Free_Function *free;
};
typedef Face Font_Make_Face_Function(Arena *arena, Face_Settings *settings,
Get_GPU_Texture_Function *get_gpu_texture,
Fill_GPU_Texture_Function *fill_gpu_texture);
#endif

View File

@ -17,21 +17,287 @@
#define internal static
internal u32
font_ft_flags(b32 use_hinting){
ft__load_flags(b32 use_hinting){
u32 ft_flags = FT_LOAD_RENDER;
if (use_hinting){
// NOTE(inso): FT_LOAD_TARGET_LIGHT does hinting only vertically, which looks nicer imo
// maybe it could be exposed as an option for hinting, instead of just on/off.
ft_flags |= FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT;
ft_flags |= (FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT);
}
else{
ft_flags |= (FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_HINTING);
}
return(ft_flags);
}
internal FT_Codepoint_Index_Pair_Array
ft__get_codepoint_index_pairs(Arena *arena, FT_Face face, u16 *maximum_index_out){
FT_Long glyph_count = face->num_glyphs;
FT_Codepoint_Index_Pair_Array array = {};
array.count = glyph_count;
array.vals = push_array(arena, FT_Codepoint_Index_Pair, glyph_count);
u16 maximum_index = 0;
i32 counter = 0;
FT_UInt index = 0;
FT_ULong codepoint = FT_Get_First_Char(face, &index);
array.vals[counter].codepoint = codepoint;
array.vals[counter].index = (u16)index;
maximum_index = Max(maximum_index, (u16)index);
counter += 1;
for (;;){
codepoint = FT_Get_Next_Char(face, codepoint, &index);
array.vals[counter].codepoint = codepoint;
array.vals[counter].index = (u16)index;
maximum_index = Max(maximum_index, (u16)index);
counter += 1;
if (counter == glyph_count){
break;
}
}
*maximum_index_out = maximum_index;
return(array);
}
internal Table_u32_u16
ft__get_codepoint_index_table(Base_Allocator *base_allocator, FT_Face face, u16 *maximum_index_out){
FT_Long glyph_count = face->num_glyphs;
Table_u32_u16 table = make_table_u32_u16(base_allocator, glyph_count*4);
u16 maximum_index = 0;
i32 counter = 0;
FT_UInt index = 0;
FT_ULong codepoint = FT_Get_First_Char(face, &index);
table_insert(&table, (u32)codepoint, (u16)index);
maximum_index = Max(maximum_index, (u16)index);
counter += 1;
for (;;){
codepoint = FT_Get_Next_Char(face, codepoint, &index);
table_insert(&table, (u32)codepoint, (u16)index);
maximum_index = Max(maximum_index, (u16)index);
counter += 1;
if (counter == glyph_count){
break;
}
}
*maximum_index_out = maximum_index;
return(table);
}
struct FT_Bad_Rect_Pack{
Vec2_i32 max_dim;
Vec3_i32 dim;
Vec3_i32 p;
i32 current_line_h;
};
internal void
ft__bad_rect_pack_init(FT_Bad_Rect_Pack *pack, Vec2_i32 max_dim){
pack->max_dim = max_dim;
pack->dim = V3i32(0, 0, 0);
pack->p = V3i32(0, 0, 0);
pack->current_line_h = 0;
}
internal void
ft__bad_rect_pack_end_line(FT_Bad_Rect_Pack *pack){
pack->p.y += pack->current_line_h;
pack->dim.y = Max(pack->dim.y, pack->p.y);
pack->current_line_h = 0;
pack->p.x = 0;
}
internal Vec3_i32
ft__bad_rect_pack_next(FT_Bad_Rect_Pack *pack, Vec2_i32 dim){
Vec3_i32 result = {};
if (dim.x <= pack->max_dim.x && dim.y <= pack->max_dim.y){
if (pack->current_line_h < dim.y){
pack->current_line_h = dim.y;
}
if (pack->current_line_h > pack->max_dim.y){
ft__bad_rect_pack_end_line(pack);
pack->p.y = 0;
pack->dim.z += 1;
pack->p.z += 1;
}
else{
if (pack->p.x + dim.x > pack->max_dim.x){
ft__bad_rect_pack_end_line(pack);
}
result = pack->p;
pack->p.x += dim.x;
pack->current_line_h = Max(pack->current_line_h, dim.y);
}
}
return(result);
}
internal void
ft__glyph_bounds_store_uv_raw(Vec3_i32 p, Vec2_i32 dim, Glyph_Bounds *bounds){
bounds->uv = Rf32((f32)p.x, (f32)p.y, (f32)dim.x, (f32)dim.y);
bounds->w = (f32)p.z;
}
enum{
TextureKind_Error,
TextureKind_Mono,
};
internal Face*
ft__font_make_face(Arena *arena, Face_Settings *settings, Get_GPU_Texture_Function *get_gpu_texture, Fill_GPU_Texture_Function *fill_gpu_texture){
String_Const_u8 file_name = SCu8(settings->stub.name, settings->stub.len);
FT_Library ft;
FT_Init_FreeType(&ft);
FT_Face ft_face;
FT_Error error = FT_New_Face(ft, (char*)file_name.str, 0, &ft_face);
Face *face = push_array_zero(arena, Face, 1);;
if (error == 0){
u32 pt_size = settings->parameters.pt_size;
b32 use_hinting = settings->parameters.use_hinting;
FT_Size_RequestRec_ size = {};
size.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
size.height = (pt_size << 6);
FT_Request_Size(ft_face, &size);
face->name = push_string_copy(arena, file_name);
face->ascent = f32_ceil32(ft_face->size->metrics.ascender/64.f);
face->descent = f32_floor32(ft_face->size->metrics.descender/64.f);
face->advance = f32_ceil32(ft_face->size->metrics.max_advance/64.f);
face->height = f32_ceil32(ft_face->size->metrics.height/64.f);
face->line_skip = face->height - (face->ascent - face->descent);
face->height -= face->line_skip;
{
f32 real_over_notional = (f32)face->height/(f32)ft_face->height;
f32 relative_center = -1.f*real_over_notional*ft_face->underline_position;
f32 relative_thickness = real_over_notional*ft_face->underline_thickness;
f32 center = (f32)floor32(face->ascent + relative_center);
f32 thickness = clamp_bot(1.f, relative_thickness);
face->underline_yoff1 = center - thickness*0.5f;
face->underline_yoff2 = center + thickness*0.5f;
}
u16 index_count = 0;
face->codepoint_to_index_table = ft__get_codepoint_index_table(arena->base_allocator, ft_face, &index_count);
face->bounds = push_array(arena, Glyph_Bounds, index_count);
struct FT_Bitmap{
Vec2_i32 dim;
u8 *data;
};
FT_Bitmap *glyph_bitmaps = push_array(arena, FT_Bitmap, index_count);
u32 load_flags = ft__load_flags(use_hinting);
for (u16 i = 0; i < index_count; i += 1){
FT_Bitmap *bitmap = &glyph_bitmaps[i];
error = FT_Load_Glyph(ft_face, i, load_flags);
if (error == 0){
FT_GlyphSlot ft_glyph = ft_face->glyph;
Vec2_i32 dim = V2i32(ft_glyph->bitmap.width, ft_glyph->bitmap.rows);
bitmap->dim = dim;
bitmap->data = push_array(arena, u8, dim.x*dim.y);
face->bounds[i].xy_off.x0 = (f32)(ft_face->glyph->bitmap_left);
face->bounds[i].xy_off.y0 = (f32)(face->ascent - ft_face->glyph->bitmap_top);
face->bounds[i].xy_off.x1 = (f32)(face->bounds[i].xy_off.x0 + dim.x);
face->bounds[i].xy_off.y1 = (f32)(face->bounds[i].xy_off.y0 + dim.y);
switch (ft_glyph->bitmap.pixel_mode){
case FT_PIXEL_MODE_MONO:
{
NotImplemented;
}break;
case FT_PIXEL_MODE_GRAY:
{
u8 *src_line = ft_glyph->bitmap.buffer;
if (ft_glyph->bitmap.pitch < 0){
src_line = ft_glyph->bitmap.buffer + (-ft_glyph->bitmap.pitch)*(dim.y - 1);
}
u8 *dst = bitmap->data;
for (i32 y = 0; y < dim.y; y += 1){
u8 *src_pixel = src_line;
for (i32 x = 0; x < dim.x; x += 1){
*dst = *src_pixel;
dst += 1;
src_pixel += 1;
}
src_line += ft_glyph->bitmap.pitch;
}
}break;
default:
{
NotImplemented;
}break;
}
}
}
u8 white_data[16] = {
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF,
};
FT_Bitmap white = {};
white.dim = V2i32(4, 4);
white.data = white_data;
FT_Bad_Rect_Pack pack = {};
ft__bad_rect_pack_init(&pack, V2i32(1024, 1024));
ft__glyph_bounds_store_uv_raw(ft__bad_rect_pack_next(&pack, white.dim), white.dim, &face->white);
for (u16 i = 0; i < index_count; i += 1){
Vec2_i32 dim = glyph_bitmaps[i].dim;
ft__glyph_bounds_store_uv_raw(ft__bad_rect_pack_next(&pack, dim), dim, &face->bounds[i]);
}
Texture_Kind texture_kind = TextureKind_Mono;
u32 gpu_texture = get_gpu_texture(pack.dim, texture_kind);
face->gpu_texture_kind = texture_kind;
face->gpu_texture = gpu_texture;
Vec3_f32 gpu_texture_dim = V3f32(pack.dim);
face->gpu_texture_dim = gpu_texture_dim;
for (u16 i = 0; i < index_count; i += 1){
Vec3_i32 p = V3i32((i32)face->bounds[i].uv.x0, (i32)face->bounds[i].uv.y0, (i32)face->bounds[i].w);
Vec3_i32 dim = V3i32(glyph_bitmaps[i].dim.x, glyph_bitmaps[i].dim.y, 1);
fill_gpu_texture(texture_kind, gpu_texture, p, dim, glyph_bitmaps[i].data);
face->bounds[i].uv.x1 = (face->bounds[i].uv.x0 + face->bounds[i].uv.x1)/gpu_texture_dim.x;
face->bounds[i].uv.y1 = (face->bounds[i].uv.y0 + face->bounds[i].uv.y1)/gpu_texture_dim.y;
face->bounds[i].uv.x0 = face->bounds[i].uv.x0/gpu_texture_dim.x;
face->bounds[i].uv.y0 = face->bounds[i].uv.y0/gpu_texture_dim.y;
face->bounds[i].w /= gpu_texture_dim.z;
}
face->settings = *settings;
}
FT_Done_FreeType(ft);
return(face);
}
#if 0
internal b32
font_ft_get_face(FT_Library ft, Font_Loadable_Stub *stub, Font_Parameters *parameters, FT_Face *face){
b32 success = true;
@ -520,7 +786,7 @@ Sys_Font_Face_Allocate_And_Init_Sig(system_font_face_allocate_and_init, new_sett
}
if (page_with_slot == 0){
LOG("Could not get a font slot while loading a font\n");
//LOG("Could not get a font slot while loading a font\n");
return(0);
}
@ -849,6 +1115,7 @@ system_font_init(Font_Functions *font_links, u32 pt_size, b32 use_hinting, Font_
first_settings.parameters.use_hinting = use_hinting;
system_font_face_allocate_and_init(&first_settings);
}
#endif
// BOTTOM

View File

@ -12,11 +12,25 @@
#if !defined(FCODER_FONT_PROVIDER_FREETYPE_H)
#define FCODER_FONT_PROVIDER_FREETYPE_H
struct FT_Codepoint_Index_Pair{
u32 codepoint;
u16 index;
};
struct FT_Codepoint_Index_Pair_Array{
FT_Codepoint_Index_Pair *vals;
i32 count;
};
#if 0
struct Font_Slot{
b32 is_active;
Font_Settings settings;
Font_Metrics metrics;
Font_Data data;
#if 0
Font_Page_Storage pages;
#endif
};
struct Font_Slot_Page{
@ -70,7 +84,7 @@ struct Font_Setup{
char name[64];
};
struct Font_Setup_List{
struct _Setup_List{
Font_Setup *first;
Font_Setup *last;
};
@ -106,6 +120,8 @@ internal Sys_Font_Data(name, parameters);
#define Sys_Font_Data_Not_Used \
internal Sys_Font_Data(n,p){ \
Font_Raw_Data data = {}; LOG("there is no font data retrieval procedure available\n"); return(data);}
#endif
#endif

View File

@ -1,68 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 12.06.2017
*
* Setup macro wrappers for the logging system.
*
*/
// TOP
#define GEN_LOG(l,m) l(m, sizeof(m)-1)
#define GEN_LOGF(l,...) do{ char space[4096]; \
i32 length = snprintf(space, sizeof(space), __VA_ARGS__); \
l(space, length); \
}while(0)
#if defined(IS_PLAT_LAYER)
# if defined(USE_LOG)
# define LOG(m) GEN_LOG(sysfunc.log, FNLN "\n" m)
# else
# define LOG(m)
# endif
# if defined(USE_LOGF)
# define LOGF(...) GEN_LOGF(sysfunc.log, FNLN "\n" __VA_ARGS__)
# else
# define LOGF(...)
# endif
#elif defined(IS_OBJC_LAYER)
# if defined(USE_LOG)
# define LOG(m) GEN_LOG(osx_log, FNLN "\n" m)
# else
# define LOG(m)
# endif
# if defined(USE_LOGF)
# define LOGF(...) GEN_LOGF(osx_log, FNLN "\n" __VA_ARGS__)
# else
# define LOGF(...)
# endif
#else /* Not platform layer */
# if defined(USE_LOG)
# define LOG(s,m) GEN_LOG((s)->log, FNLN "\n" m)
# else
# define LOG(s,m)
# endif
# if defined(USE_LOGF)
# define LOGF(s,...) GEN_LOGF((s)->log, FNLN "\n" __VA_ARGS__)
# else
# define LOGF(s,...)
# endif
#endif
// HACK(allen): Get rid of this dependency. Implement snprintf ourself or something.
#if defined(USE_LOG)
# include <stdio.h>
#endif
// BOTTOM

View File

@ -52,33 +52,52 @@ end_render_section(Render_Target *target, System_Functions *system){
Assert(target->clip_top == 0);
}
////////////////////////////////
#define CmdHeader(t) cmd.header.size = sizeof(cmd), cmd.header.type = t
internal void
draw_rectangle(Render_Target *target, f32_Rect rect, u32 color){
Render_Command_Rectangle cmd = {};
CmdHeader(RenCom_Rectangle);
cmd.rect = rect;
cmd.color = color;
cmd.vertices[0] = V2(rect.x0, rect.y0);
cmd.vertices[1] = V2(rect.x1, rect.y0);
cmd.vertices[2] = V2(rect.x0, rect.y1);
cmd.vertices[3] = V2(rect.x1, rect.y1);
void *h = render_begin_push(target, &cmd, cmd.header.size);
render_end_push(target, h);
}
internal void
draw_rectangle(Render_Target *target, i32_Rect rect, u32 color){
draw_rectangle(target, f32R(rect), color);
}
internal void
draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){
Render_Command_Rectangle cmd = {};
CmdHeader(RenCom_Outline);
cmd.rect = rect;
draw_rectangle(target, Rf32(rect.x0, rect.y0, rect.x1, rect.y0 + 1), color);
draw_rectangle(target, Rf32(rect.x1 - 1, rect.y0, rect.x1, rect.y1), color);
draw_rectangle(target, Rf32(rect.x0, rect.y1 - 1, rect.x1, rect.y1), color);
draw_rectangle(target, Rf32(rect.x0, rect.y0, rect.x0 + 1, rect.y1), color);
}
internal void
draw_font_glyph(Render_Target *target, Face_ID font_id, u32 codepoint, f32 x, f32 y, u32 color, u32 flags){
Render_Command_Glyph cmd = {};
CmdHeader(RenCom_Glyph);
cmd.pos.x = x;
cmd.pos.y = y;
cmd.color = color;
cmd.font_id = font_id;
cmd.codepoint = codepoint;
cmd.flags = flags;
void *h = render_begin_push(target, &cmd, cmd.header.size);
render_end_push(target, h);
}
////////////////////////////////
internal void
draw_rectangle(Render_Target *target, i32_Rect rect, u32 color){
draw_rectangle(target, f32R(rect), color);
}
internal void
draw_rectangle_outline(Render_Target *target, i32_Rect rect, u32 color){
draw_rectangle_outline(target, f32R(rect), color);
@ -102,7 +121,6 @@ internal void
draw_margin(Render_Target *target, i32_Rect outer, i32_Rect inner, u32 color){
draw_rectangle(target, i32R(outer.x0, outer.y0, outer.x1, inner.y0), color);
draw_rectangle(target, i32R(outer.x0, inner.y1, outer.x1, outer.y1), color);
draw_rectangle(target, i32R(outer.x0, inner.y0, inner.x0, inner.y1), color);
draw_rectangle(target, i32R(inner.x1, inner.y0, outer.x1, inner.y1), color);
}
@ -113,20 +131,6 @@ draw_margin(Render_Target *target, i32_Rect outer, i32 width, u32 color){
draw_margin(target, outer, inner, color);
}
internal void
draw_font_glyph(Render_Target *target, Face_ID font_id, u32 codepoint, f32 x, f32 y, u32 color, u32 flags){
Render_Command_Glyph cmd;
CmdHeader(RenCom_Glyph);
cmd.pos.x = x;
cmd.pos.y = y;
cmd.color = color;
cmd.font_id = font_id;
cmd.codepoint = codepoint;
cmd.flags = flags;
void *h = render_begin_push(target, &cmd, cmd.header.size);
render_end_push(target, h);
}
internal Vec2
snap_point_to_boundary(Vec2 point){
point.x = (f32)(floor32(point.x));
@ -138,12 +142,16 @@ internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 string, Vec2 point, u32 color, u32 flags, Vec2 delta){
f32 total_delta = 0.f;
#if 0
Font_Pointers font = system->font.get_pointers_by_id(font_id);
if (font.valid != 0){
#endif
Face *face = 0;
if (face != 0){
point = snap_point_to_boundary(point);
f32 byte_advance = font.metrics->byte_advance;
f32 *sub_advances = font.metrics->sub_advances;
f32 byte_advance = face->byte_advance;
f32 *sub_advances = face->sub_advances;
u8 *str = (u8*)string.str;
u8 *str_end = str + string.size;
@ -152,7 +160,7 @@ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, St
Translation_Emits emits = {};
for (u32 i = 0; str < str_end; ++str, ++i){
translating_fully_process_byte(system, font, &tran, *str, i, (i32)string.size, &emits);
translating_fully_process_byte(system, &tran, *str, i, (i32)string.size, &emits);
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
@ -162,7 +170,7 @@ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, St
if (color != 0){
draw_font_glyph(target, font_id, codepoint, point.x, point.y, color, flags);
}
f32 d = font_get_glyph_advance(system, font.settings, font.metrics, font.pages, codepoint);
f32 d = font_get_glyph_advance(system, face, codepoint);
point += d*delta;
total_delta += d;
}

View File

@ -14,7 +14,6 @@
enum Render_Command_Type{
RenCom_Rectangle,
RenCom_Outline,
RenCom_Glyph,
RenCom_ChangeClip,
};
@ -31,8 +30,14 @@ struct Render_Command_Header{
struct Render_Command_Rectangle{
Render_Command_Header header;
f32_Rect rect;
u32 color;
Vec2 vertices[4];
};
struct Render_Command_Rectangle_Outline{
Render_Command_Header header;
u32 color;
Vec2 vertices[5];
};
struct Render_Command_Gradient{

View File

@ -37,7 +37,6 @@ Render_End_Push_Sig(render_internal_end_push, t, h){
Render_Command_Header *header = (Render_Command_Header*)h;
header->size = (i32)(end_ptr - (u8*)h);
}
// TODO(allen): else { LOG }
}
internal void

View File

@ -224,12 +224,8 @@ typedef Sys_Set_Fullscreen_Sig(System_Set_Fullscreen);
#define Sys_Is_Fullscreen_Sig(name) b32 name()
typedef Sys_Is_Fullscreen_Sig(System_Is_Fullscreen);
// debug
#define Sys_Log_Sig(name) void name(char *message, u32 length)
typedef Sys_Log_Sig(System_Log);
struct System_Functions{
Font_Functions font;
Font_Make_Face_Function *font_make_face;
// files (tracked api): 11
System_Set_File_List *set_file_list;
@ -287,9 +283,6 @@ struct System_Functions{
System_Show_Mouse_Cursor *show_mouse_cursor;
System_Set_Fullscreen *set_fullscreen;
System_Is_Fullscreen *is_fullscreen;
// debug: 1
System_Log *log;
};
#endif

56
4ed_system_allocator.cpp Normal file
View File

@ -0,0 +1,56 @@
/*
* 4coder malloc base allocator
*/
// TOP
internal void*
base_reserve__system(void *user_data, umem size, umem *size_out){
System_Functions *system = (System_Functions*)user_data;
umem extra_size = 128;
umem increased_size = size + extra_size;
size = round_up_umem(increased_size, KB(4));
*size_out = size - extra_size;
void *ptr = system->memory_allocate(size);
*(umem*)ptr = size;
ptr = (u8*)ptr + extra_size;
return(ptr);
}
internal void
base_free__system(void *user_data, void *ptr){
System_Functions *system = (System_Functions*)user_data;
umem extra_size = 128;
ptr = (u8*)ptr - extra_size;
umem size = *(umem*)ptr;
system->memory_free(ptr, size);
}
internal Base_Allocator
make_base_allocator_system(System_Functions *system){
return(make_base_allocator(base_reserve__system, 0, 0,
base_free__system, 0, system));
}
global Base_Allocator base_allocator_system = {};
internal Arena
make_arena_system(System_Functions *system, umem chunk_size, umem align){
if (base_allocator_system.reserve == 0){
base_allocator_system = make_base_allocator_system(system);
}
return(make_arena(&base_allocator_system, chunk_size, align));
}
internal Arena
make_arena_system(System_Functions *system, umem chunk_size){
return(make_arena_system(system, chunk_size, 8));
}
internal Arena
make_arena_system(System_Functions *system){
return(make_arena_system(system, KB(16), 8));
}
// BOTTOM

View File

@ -98,7 +98,7 @@ translating_select_emit_rule_ASCII(Translation_State *tran, Translation_Byte_Des
}
internal void
translating_select_emit_rule_with_font(System_Functions *system, Font_Pointers font, Translation_State *tran, Translation_Byte_Description desc, Translation_Emit_Rule *type_out){
translating_select_emit_rule_UTF8(System_Functions *system, Translation_State *tran, Translation_Byte_Description desc, Translation_Emit_Rule *type_out){
type_out->byte_class = desc.byte_class;
type_out->last_byte_handler = desc.last_byte_handler;
type_out->emit_type = desc.prelim_emit_type;
@ -113,7 +113,7 @@ translating_select_emit_rule_with_font(System_Functions *system, Font_Pointers f
}
else{
type_out->codepoint = cp;
if (!font_can_render(system, font.settings, font.metrics, font.pages, cp)){
if (cp > 0x10FFFF){
type_out->emit_type = BufferModelUnit_Numbers;
}
}
@ -178,11 +178,11 @@ translating_generate_emits(Translation_State *tran, Translation_Emit_Rule emit_r
}
internal void
translating_fully_process_byte(System_Functions *system, Font_Pointers font, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){
translating_fully_process_byte(System_Functions *system, Translation_State *tran, u8 ch, u32 i, u32 size, Translation_Emits *emits_out){
Translation_Byte_Description description = {};
translating_consume_byte(tran, ch, i, size, &description);
Translation_Emit_Rule emit_rule = {};
translating_select_emit_rule_with_font(system, font, tran, description, &emit_rule);
translating_select_emit_rule_UTF8(system, tran, description, &emit_rule);
translating_generate_emits(tran, emit_rule, ch, i, emits_out);
}

View File

@ -345,8 +345,13 @@ view_set_file(System_Functions *system, Models *models, View *view, Editing_File
view->mark = edit_pos.cursor_pos;
view_set_preferred_x_to_current_position(system, view);
#if 0
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
view->line_height = font.metrics->height;
#endif
Face *face = 0;
Assert(face != 0);
view->line_height = (i32)face->height;
models->layout.panel_state_dirty = true;
}
@ -386,8 +391,11 @@ adjust_views_looking_at_file_to_new_cursor(System_Functions *system, Models *mod
internal void
file_full_remeasure(System_Functions *system, Models *models, Editing_File *file){
Face_ID font_id = file->settings.font_id;
#if 0
Font_Pointers font = system->font.get_pointers_by_id(font_id);
file_measure_wraps(system, &models->mem, file, font);
#endif
Face *face = 0;
file_measure_wraps(system, &models->mem, file, face);
adjust_views_looking_at_file_to_new_cursor(system, models, file);
Layout *layout = &models->layout;
@ -396,7 +404,7 @@ file_full_remeasure(System_Functions *system, Models *models, Editing_File *file
panel = layout_get_next_open_panel(layout, panel)){
View *view = panel->view;
if (view->file == file){
view->line_height = font.metrics->height;
view->line_height = (i32)face->height;
}
}
}
@ -419,8 +427,10 @@ global_set_font_and_update_files(System_Functions *system, Models *models, Face_
}
internal b32
alter_font_and_update_files(System_Functions *system, Models *models, Face_ID font_id, Font_Settings *new_settings){
alter_font_and_update_files(System_Functions *system, Models *models, Face_ID font_id, Face_Settings *new_settings){
b32 success = false;
NotImplemented;
#if 0
if (system->font.face_change_settings(font_id, new_settings)){
success = true;
for (Node *node = models->working_set.used_sentinel.next;
@ -432,12 +442,15 @@ alter_font_and_update_files(System_Functions *system, Models *models, Face_ID fo
}
}
}
#endif
return(success);
}
internal b32
release_font_and_update_files(System_Functions *system, Models *models, Face_ID font_id, Face_ID replacement_id){
b32 success = false;
NotImplemented;
#if 0
if (system->font.face_release(font_id)){
Font_Pointers font = system->font.get_pointers_by_id(replacement_id);
if (!font.valid){
@ -460,6 +473,7 @@ release_font_and_update_files(System_Functions *system, Models *models, Face_ID
}
}
}
#endif
return(success);
}

View File

@ -161,7 +161,6 @@ enum{
SUPER = 0x40,
INTERNAL = 0x80,
KEEP_ASSERT = 0x100,
LOG = 0x200,
};
internal char**
@ -176,10 +175,6 @@ get_defines_from_flags(Arena *arena, u32 flags){
if (HasFlag(flags, SUPER)){
result = fm_list(arena, fm_list_one_item(arena, "FRED_SUPER"), result);
}
if (HasFlag(flags, LOG)){
char *log_defines[] = { "USE_LOG", "USE_LOGF", 0};
result = fm_list(arena, log_defines, result);
}
return(result);
}
@ -633,7 +628,7 @@ package(Arena *arena, char *cdir){
};
char *tiers[] = { "alpha", "super" };
u32 base_flags = OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | LOG;
u32 base_flags = OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO;
u32 tier_flags[] = { 0, SUPER, };
for (u32 tier_index = 0; tier_index < Tier_COUNT; ++tier_index){
@ -704,7 +699,7 @@ int main(int argc, char **argv){
END_TIME_SECTION("current directory");
#if defined(DEV_BUILD) || defined(OPT_BUILD) || defined(DEV_BUILD_X86)
u32 flags = DEBUG_INFO | SUPER | INTERNAL | LOG;
u32 flags = DEBUG_INFO | SUPER | INTERNAL;
u32 arch = Arch_X64;
#if defined(OPT_BUILD)
flags |= OPTIMIZATION;

View File

@ -12,8 +12,216 @@
#if !defined(FRED_OPENGL_DEFINES_H)
#define FRED_OPENGL_DEFINES_H
#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242
#define GL_DEBUG_OUTPUT 0x92E0
#include <GL/gl.h>
#define GL_MULTISAMPLE 0x809D
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242
#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
#define GL_TEXTURE5 0x84C5
#define GL_TEXTURE6 0x84C6
#define GL_TEXTURE7 0x84C7
#define GL_TEXTURE8 0x84C8
#define GL_TEXTURE9 0x84C9
#define GL_TEXTURE10 0x84CA
#define GL_TEXTURE11 0x84CB
#define GL_TEXTURE12 0x84CC
#define GL_TEXTURE13 0x84CD
#define GL_TEXTURE14 0x84CE
#define GL_TEXTURE15 0x84CF
#define GL_TEXTURE16 0x84D0
#define GL_TEXTURE17 0x84D1
#define GL_TEXTURE18 0x84D2
#define GL_TEXTURE19 0x84D3
#define GL_TEXTURE20 0x84D4
#define GL_TEXTURE21 0x84D5
#define GL_TEXTURE22 0x84D6
#define GL_TEXTURE23 0x84D7
#define GL_TEXTURE24 0x84D8
#define GL_TEXTURE25 0x84D9
#define GL_TEXTURE26 0x84DA
#define GL_TEXTURE27 0x84DB
#define GL_TEXTURE28 0x84DC
#define GL_TEXTURE29 0x84DD
#define GL_TEXTURE30 0x84DE
#define GL_TEXTURE31 0x84DF
#define GL_ARRAY_BUFFER 0x8892
#define GL_STREAM_DRAW 0x88E0
#define GL_STREAM_READ 0x88E1
#define GL_STREAM_COPY 0x88E2
#define GL_STATIC_DRAW 0x88E4
#define GL_STATIC_READ 0x88E5
#define GL_STATIC_COPY 0x88E6
#define GL_DYNAMIC_DRAW 0x88E8
#define GL_DYNAMIC_READ 0x88E9
#define GL_DYNAMIC_COPY 0x88EA
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_VERTEX_SHADER 0x8B31
#define GL_DELETE_STATUS 0x8B80
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_VALIDATE_STATUS 0x8B83
#define GL_INFO_LOG_LENGTH 0x8B84
#define GL_ATTACHED_SHADERS 0x8B85
#define GL_ACTIVE_UNIFORMS 0x8B86
#define GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
#define GL_SHADER_SOURCE_LENGTH 0x8B88
#define GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
#define GL_SRGB 0x8C40
#define GL_SRGB8 0x8C41
#define GL_SRGB_ALPHA 0x8C42
#define GL_SRGB8_ALPHA8 0x8C43
#define GL_READ_FRAMEBUFFER 0x8CA8
#define GL_DRAW_FRAMEBUFFER 0x8CA9
#define GL_FRAMEBUFFER_COMPLETE 0x8CD5
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_COLOR_ATTACHMENT1 0x8CE1
#define GL_COLOR_ATTACHMENT2 0x8CE2
#define GL_COLOR_ATTACHMENT3 0x8CE3
#define GL_COLOR_ATTACHMENT4 0x8CE4
#define GL_COLOR_ATTACHMENT5 0x8CE5
#define GL_COLOR_ATTACHMENT6 0x8CE6
#define GL_COLOR_ATTACHMENT7 0x8CE7
#define GL_COLOR_ATTACHMENT8 0x8CE8
#define GL_COLOR_ATTACHMENT9 0x8CE9
#define GL_COLOR_ATTACHMENT10 0x8CEA
#define GL_COLOR_ATTACHMENT11 0x8CEB
#define GL_COLOR_ATTACHMENT12 0x8CEC
#define GL_COLOR_ATTACHMENT13 0x8CED
#define GL_COLOR_ATTACHMENT14 0x8CEE
#define GL_COLOR_ATTACHMENT15 0x8CEF
#define GL_COLOR_ATTACHMENT16 0x8CF0
#define GL_COLOR_ATTACHMENT17 0x8CF1
#define GL_COLOR_ATTACHMENT18 0x8CF2
#define GL_COLOR_ATTACHMENT19 0x8CF3
#define GL_COLOR_ATTACHMENT20 0x8CF4
#define GL_COLOR_ATTACHMENT21 0x8CF5
#define GL_COLOR_ATTACHMENT22 0x8CF6
#define GL_COLOR_ATTACHMENT23 0x8CF7
#define GL_COLOR_ATTACHMENT24 0x8CF8
#define GL_COLOR_ATTACHMENT25 0x8CF9
#define GL_COLOR_ATTACHMENT26 0x8CFA
#define GL_COLOR_ATTACHMENT27 0x8CFB
#define GL_COLOR_ATTACHMENT28 0x8CFC
#define GL_COLOR_ATTACHMENT29 0x8CFD
#define GL_COLOR_ATTACHMENT30 0x8CFE
#define GL_COLOR_ATTACHMENT31 0x8CFF
#define GL_DEPTH_ATTACHMENT 0x8D00
#define GL_STENCIL_ATTACHMENT 0x8D20
#define GL_FRAMEBUFFER 0x8D40
#define GL_FRAMEBUFFER_SRGB 0x8DB9
#define GL_TEXTURE_2D_MULTISAMPLE 0x9100
#define GL_DEBUG_SEVERITY_HIGH 0x9146
#define GL_DEBUG_SEVERITY_MEDIUM 0x9147
#define GL_DEBUG_SEVERITY_LOW 0x9148
#define GL_TEXTURE_3D 0x806F
#define GL_TEXTURE_2D_ARRAY 0x8C1A
////////////////////////////////
#define GL_R8 0x8229
#define GL_R16 0x822A
#define GL_RG8 0x822B
#define GL_RG16 0x822C
#define GL_R16F 0x822D
#define GL_R32F 0x822E
#define GL_RG16F 0x822F
#define GL_RG32F 0x8230
#define GL_R8I 0x8231
#define GL_R8UI 0x8232
#define GL_R16I 0x8233
#define GL_R16UI 0x8234
#define GL_R32I 0x8235
#define GL_R32UI 0x8236
#define GL_RG8I 0x8237
#define GL_RG8UI 0x8238
#define GL_RG16I 0x8239
#define GL_RG16UI 0x823A
#define GL_RG32I 0x823B
#define GL_RG32UI 0x823C
#define GL_RGBA32UI 0x8D70
#define GL_RGB32UI 0x8D71
#define GL_RGBA16UI 0x8D76
#define GL_RGB16UI 0x8D77
#define GL_RGBA8UI 0x8D7C
#define GL_RGB8UI 0x8D7D
#define GL_RGBA32I 0x8D82
#define GL_RGB32I 0x8D83
#define GL_RGBA16I 0x8D88
#define GL_RGB16I 0x8D89
#define GL_RGBA8I 0x8D8E
#define GL_RGB8I 0x8D8F
#define GL_RGBA32F 0x8814
#define GL_RGB32F 0x8815
#define GL_RGBA16F 0x881A
#define GL_RGB16F 0x881B
#define GL_R8_SNORM 0x8F94
#define GL_RG8_SNORM 0x8F95
#define GL_RGB8_SNORM 0x8F96
#define GL_RGBA8_SNORM 0x8F97
#define GL_R16_SNORM 0x8F98
#define GL_RG16_SNORM 0x8F99
#define GL_RGB16_SNORM 0x8F9A
#define GL_RGBA16_SNORM 0x8F9B
#define GL_DEPTH_COMPONENT16 0x81A5
#define GL_DEPTH_COMPONENT24 0x81A6
#define GL_DEPTH_COMPONENT32 0x81A7
#define GL_DEPTH_COMPONENT32F 0x8CAC
#define GL_DEPTH24_STENCIL8 0x88F0
#define GL_DEPTH_STENCIL 0x84F9
#define GL_UNSIGNED_INT_24_8 0x84FA
#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
////////////////////////////////
#define GL_FRAMEBUFFER_UNDEFINED 0x8219
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER 0x8CDB
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER 0x8CDC
#define GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56
#define GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 0x8DA8
////////////////////////////////
typedef char GLchar;
typedef short GLshort;
typedef signed char GLbyte;
typedef unsigned short GLushort;
typedef ptrdiff_t GLsizeiptr;
typedef ptrdiff_t GLintptr;
typedef void GL_Debug_Function(GLenum src,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
GLchar *message,
void *user_data);
typedef GL_Debug_Function *GLDEBUGPROC;
#define GL_FUNC(N,R,P) typedef R (N##_Function)P; N##_Function *N = 0;
#include "4ed_opengl_funcs.h"
#endif

View File

@ -13,6 +13,77 @@
#include "4ed_opengl_funcs.h"
*/
GL_FUNC(glDebugMessageControl, void, (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled))
GL_FUNC(glDebugMessageCallback, void, (GLDEBUGPROC callback, const void *userParam))
GL_FUNC(glTexImage3D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels))
GL_FUNC(glTexSubImage3D, void, (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels))
GL_FUNC(glGenVertexArrays, void, (GLsizei n, GLuint *arrays))
GL_FUNC(glBindVertexArray, void, (GLuint array))
GL_FUNC(glDeleteVertexArrays, void, (GLsizei n, const GLuint *arrays))
GL_FUNC(glGenBuffers, void, (GLsizei n, GLuint *buffers))
GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer))
GL_FUNC(glBufferData, void, (GLenum target, GLsizeiptr size, const void *data, GLenum usage))
GL_FUNC(glCreateShader, GLuint, (GLenum type))
GL_FUNC(glShaderSource, void, (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length))
GL_FUNC(glCompileShader, void, (GLuint shader))
GL_FUNC(glGetShaderiv, void, (GLuint shader, GLenum pname, GLint *params))
GL_FUNC(glGetShaderInfoLog, void, (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog))
GL_FUNC(glDeleteShader, void, (GLuint shader))
GL_FUNC(glCreateProgram, GLuint, (void))
GL_FUNC(glAttachShader, void, (GLuint program, GLuint shader))
GL_FUNC(glLinkProgram, void, (GLuint program))
GL_FUNC(glUseProgram, void, (GLuint program))
GL_FUNC(glGetProgramiv, void, (GLuint program, GLenum pname, GLint *params))
GL_FUNC(glGetProgramInfoLog, void, (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog))
GL_FUNC(glDeleteProgram, void, (GLuint program))
GL_FUNC(glValidateProgram, void, (GLuint program))
GL_FUNC(glGetUniformLocation, GLint, (GLuint program, const GLchar *name))
GL_FUNC(glGetAttribLocation, GLint, (GLuint program, const GLchar *name))
GL_FUNC(glBindAttribLocation, void, (GLuint program, GLuint index, const GLchar *name))
GL_FUNC(glDisableVertexAttribArray, void, (GLuint index))
GL_FUNC(glEnableVertexAttribArray, void, (GLuint index))
GL_FUNC(glVertexAttribPointer, void, (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer))
GL_FUNC(glUniform1f, void, (GLint location, GLfloat v0))
GL_FUNC(glUniform2f, void, (GLint location, GLfloat v0, GLfloat v1))
GL_FUNC(glUniform3f, void, (GLint location, GLfloat v0, GLfloat v1, GLfloat v2))
GL_FUNC(glUniform4f, void, (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3))
GL_FUNC(glUniform1i, void, (GLint location, GLint v0))
GL_FUNC(glUniform2i, void, (GLint location, GLint v0, GLint v1))
GL_FUNC(glUniform3i, void, (GLint location, GLint v0, GLint v1, GLint v2))
GL_FUNC(glUniform4i, void, (GLint location, GLint v0, GLint v1, GLint v2, GLint v3))
GL_FUNC(glUniform1fv, void, (GLint location, GLsizei count, const GLfloat *value))
GL_FUNC(glUniform2fv, void, (GLint location, GLsizei count, const GLfloat *value))
GL_FUNC(glUniform3fv, void, (GLint location, GLsizei count, const GLfloat *value))
GL_FUNC(glUniform4fv, void, (GLint location, GLsizei count, const GLfloat *value))
GL_FUNC(glUniform1iv, void, (GLint location, GLsizei count, const GLint *value))
GL_FUNC(glUniform2iv, void, (GLint location, GLsizei count, const GLint *value))
GL_FUNC(glUniform3iv, void, (GLint location, GLsizei count, const GLint *value))
GL_FUNC(glUniform4iv, void, (GLint location, GLsizei count, const GLint *value))
GL_FUNC(glUniformMatrix2fv, void, (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value))
GL_FUNC(glUniformMatrix3fv, void, (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value))
GL_FUNC(glUniformMatrix4fv, void, (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value))
GL_FUNC(glActiveTexture, void, (GLenum texture))
GL_FUNC(glGenFramebuffers, void, (GLsizei n, GLuint *framebuffers))
GL_FUNC(glBindFramebuffer, void, (GLenum target, GLuint framebuffer))
GL_FUNC(glCheckFramebufferStatus, GLenum, (GLenum target))
GL_FUNC(glFramebufferTexture1D, void, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level))
GL_FUNC(glFramebufferTexture2D, void, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level))
GL_FUNC(glFramebufferTexture3D, void, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset))
GL_FUNC(glBlitFramebuffer, void, (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter))
GL_FUNC(glTexImage2DMultisample, void, (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations))
#undef GL_FUNC
// BOTTOM

View File

@ -9,92 +9,204 @@
// TOP
// TODO(allen): If we don't actually need this then burn down 4ed_opengl_funcs.h
// Declare function types and function pointers
//#define GL_FUNC(N,R,P) typedef R (N##_Function) P; N##_Function *P = 0;
//#include "4ed_opengl_funcs.h"
#include "4ed_opengl_defines.h"
// OpenGL 2.1 implementation
#if 0
internal GLuint
private_texture_initialize(GLint tex_width, GLint tex_height, u32 *pixels){
gl__texture_initialize(GLint tex_width, GLint tex_height, u32 *pixels){
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, tex_width, tex_height, 0, GL_ALPHA, GL_UNSIGNED_INT, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, tex_width, tex_height, 0, GL_RED, GL_UNSIGNED_INT, pixels);
return(tex);
}
#endif
internal u32
gl__get_gpu_texture(Vec3_i32 dim, Texture_Kind texture_kind){
u32 tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, dim.x, dim.y, 0, GL_RED, GL_UNSIGNED_INT, 0);
return(tex);
}
internal void
private_draw_bind_texture(Render_Target *t, i32 texid){
gl__draw_bind_texture(Render_Target *t, i32 texid){
if (t->bound_texture != texid){
glBindTexture(GL_TEXTURE_2D, texid);
t->bound_texture = texid;
}
}
internal void
private_draw_set_color(Render_Target *t, u32 color){
if (t->color != color){
t->color = color;
Vec4 c = unpack_color4(color);
glColor4f(c.r, c.g, c.b, c.a);
}
internal void CALL_CONVENTION
gl__error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, char *message, void *userParam){
InvalidPath;
}
char *gl__header = R"foo(#version 150
)foo";
char *gl__vertex = R"foo(
uniform vec2 view_t;
uniform mat2x2 view_m;
uniform vec4 color;
in vec2 vertex_p;
in vec2 vertex_t;
smooth out vec4 fragment_color;
smooth out vec2 uv;
void main(void)
{
gl_Position = vec4(view_m*(vertex_p - view_t), 0.f, 1.f);
fragment_color = color;
uv = vertex_t;
}
)foo";
char *gl__fragment = R"foo(
smooth in vec4 fragment_color;
smooth in vec2 uv;
uniform sampler2D sampler;
uniform float texture_override;
out vec4 out_color;
void main(void)
{
out_color = fragment_color*(texture(sampler, uv).r + texture_override);
}
)foo";
#define AttributeList(X) \
X(vertex_p) \
X(vertex_t)
#define UniformList(X) \
X(view_t) \
X(view_m) \
X(color) \
X(sampler) \
X(texture_override)
struct GL_Program{
u32 program;
#define GetAttributeLocation(N) i32 N;
AttributeList(GetAttributeLocation)
#undef GetAttributeLocation
#define GetUniformLocation(N) i32 N;
UniformList(GetUniformLocation)
#undef GetUniformLocation
};
internal GL_Program
gl__make_program(char *header, char *vertex, char *fragment){
if (header == 0){
header = "";
}
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
GLchar *vertex_source_array[] = { header, vertex };
glShaderSource(vertex_shader, ArrayCount(vertex_source_array), vertex_source_array, 0);
glCompileShader(vertex_shader);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
GLchar *fragment_source_array[] = { header, fragment };
glShaderSource(fragment_shader, ArrayCount(fragment_source_array), fragment_source_array, 0);
glCompileShader(fragment_shader);
GLuint program = glCreateProgram();
glAttachShader(program, vertex_shader);
glAttachShader(program, fragment_shader);
glLinkProgram(program);
glValidateProgram(program);
GLint success = false;
glGetProgramiv(program, GL_LINK_STATUS, &success);
if (!success){
GLsizei ignore = 0;
char vertex_errors[KB(4)];
char fragment_errors[KB(4)];
char program_errors[KB(4)];
glGetShaderInfoLog(vertex_shader, sizeof(vertex_errors), &ignore, vertex_errors);
glGetShaderInfoLog(fragment_shader, sizeof(fragment_errors), &ignore, fragment_errors);
glGetProgramInfoLog(program, sizeof(program_errors), &ignore, program_errors);
#if SHIP_MODE
os_popup_window(string_u8_litexpr("Error"), string_u8_litexpr("Shader compilation failed."));
#endif
InvalidPath;
}
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
GL_Program result = {};
result.program = program;
#define GetAttributeLocation(N) result.N = glGetAttribLocation(program, #N);
AttributeList(GetAttributeLocation)
#undef GetAttributeLocation
#define GetUniformLocation(N) result.N = glGetUniformLocation(program, #N);
UniformList(GetUniformLocation)
#undef GetUniformLocation
return(result);
}
#define GLOffset(p,m) ((void*)(OffsetOfMemberStruct(p,m)))
internal void
interpret_render_buffer(Render_Target *t, Arena *scratch){
gl_render(Render_Target *t, Arena *scratch){
local_persist b32 first_opengl_call = true;
local_persist u32 attribute_buffer = 0;
local_persist GL_Program gpu_program = {};
if (first_opengl_call){
first_opengl_call = false;
char *vendor = (char *)glGetString(GL_VENDOR);
char *renderer = (char *)glGetString(GL_RENDERER);
char *version = (char *)glGetString(GL_VERSION);
LOGF("GL_VENDOR: %s\n", vendor);
LOGF("GL_RENDERER: %s\n", renderer);
LOGF("GL_VERSION: %s\n", version);
// TODO(allen): Get this up and running for dev mode again.
#if (defined(BUILD_X64) && 0) || (defined(BUILD_X86) && 0)
// NOTE(casey): This slows down GL but puts error messages to
// the debug console immediately whenever you do something wrong
void CALL_CONVENTION gl_dbg(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam);
glDebugMessageCallback_type *glDebugMessageCallback =
(glDebugMessageCallback_type *)win32_load_gl_always("glDebugMessageCallback", module);
glDebugMessageControl_type *glDebugMessageControl =
(glDebugMessageControl_type *)win32_load_gl_always("glDebugMessageControl", module);
if(glDebugMessageCallback != 0 && glDebugMessageControl != 0)
{
glDebugMessageCallback(opengl_debug_callback, 0);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, GL_TRUE);
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
}
#if !SHIP_MODE
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, 0, true);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW, 0, 0, true);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, 0, true);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, 0, true);
glDebugMessageCallback(gl__error_callback, 0);
#endif
glEnable(GL_TEXTURE_2D);
////////////////////////////////
GLuint dummy_vao = 0;
glGenVertexArrays(1, &dummy_vao);
glBindVertexArray(dummy_vao);
////////////////////////////////
glGenBuffers(1, &attribute_buffer);
glBindBuffer(GL_ARRAY_BUFFER, attribute_buffer);
////////////////////////////////
glEnable(GL_SCISSOR_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
////////////////////////////////
gpu_program = gl__make_program(gl__header, gl__vertex, gl__fragment);
glUseProgram(gpu_program.program);
}
i32 width = t->width;
i32 height = t->height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glScissor(0, 0, width, height);
glClearColor(1.f, 0.f, 1.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
@ -102,9 +214,6 @@ interpret_render_buffer(Render_Target *t, Arena *scratch){
glBindTexture(GL_TEXTURE_2D, 0);
t->bound_texture = 0;
glColor4f(0.f, 0.f, 0.f, 0.f);
t->color = 0;
for (Render_Free_Texture *free_texture = t->free_texture_first;
free_texture != 0;
free_texture = free_texture->next){
@ -124,45 +233,45 @@ interpret_render_buffer(Render_Target *t, Arena *scratch){
case RenCom_Rectangle:
{
Render_Command_Rectangle *rectangle = (Render_Command_Rectangle*)header;
f32_Rect r = rectangle->rect;
private_draw_set_color(t, rectangle->color);
private_draw_bind_texture(t, 0);
glBegin(GL_QUADS);
{
glVertex2f(r.x0, r.y0);
glVertex2f(r.x0, r.y1);
glVertex2f(r.x1, r.y1);
glVertex2f(r.x1, r.y0);
}
glEnd();
}break;
case RenCom_Outline:
{
Render_Command_Rectangle *rectangle = (Render_Command_Rectangle*)header;
f32_Rect r = rect_inner(rectangle->rect, .5f);
private_draw_set_color(t, rectangle->color);
private_draw_bind_texture(t, 0);
glBegin(GL_LINE_STRIP);
{
glVertex2f(r.x0, r.y0);
glVertex2f(r.x1, r.y0);
glVertex2f(r.x1, r.y1);
glVertex2f(r.x0, r.y1);
glVertex2f(r.x0, r.y0);
}
glEnd();
gl__draw_bind_texture(t, 0);
Vec4 c = unpack_color4(rectangle->color);
i32 vertex_count = ArrayCount(rectangle->vertices);
glBufferData(GL_ARRAY_BUFFER, sizeof(rectangle->vertices), rectangle->vertices, GL_STREAM_DRAW);
glEnableVertexAttribArray(gpu_program.vertex_p);
glVertexAttribPointer(gpu_program.vertex_p, 2, GL_FLOAT, true, sizeof(rectangle->vertices[0]), 0);
glUniform2f(gpu_program.view_t, width/2.f, height/2.f);
f32 m[4] = {
2.f/width, 0.f,
0.f, -2.f/height,
};
glUniformMatrix2fv(gpu_program.view_m, 1, GL_FALSE, m);
glUniform4f(gpu_program.color, c.r, c.g, c.b, c.a);
glUniform1f(gpu_program.texture_override, 1.f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertex_count);
glDisableVertexAttribArray(gpu_program.vertex_p);
}break;
case RenCom_Glyph:
{
Render_Command_Glyph *glyph = (Render_Command_Glyph*)header;
#if 0
Font_Pointers font = system_font_get_pointers_by_id(glyph->font_id);
if (!font.valid){
break;
}
#endif
Face *face = 0;
if (face == 0){
break;
}
u32 codepoint = glyph->codepoint;
#if 0
u32 page_number = codepoint/GLYPHS_PER_PAGE;
Glyph_Page *page = font_cached_get_page(font.pages, page_number);
if (page == 0){
@ -175,10 +284,9 @@ interpret_render_buffer(Render_Target *t, Arena *scratch){
i32 tex_height = 0;
u32 *pixels = font_load_page_pixels(scratch, font.settings, page, page_number, &tex_width, &tex_height);
page->has_gpu_setup = true;
page->gpu_tex = private_texture_initialize(tex_width, tex_height, pixels);
page->gpu_tex = gl__texture_initialize(tex_width, tex_height, pixels);
end_temp(temp);
}
if (page->gpu_tex == 0){
break;
}
@ -189,38 +297,76 @@ interpret_render_buffer(Render_Target *t, Arena *scratch){
i32 tex_width = page->tex_width;
i32 tex_height = page->tex_height;
f32 x = glyph->pos.x;
f32 y = glyph->pos.y;
f32_Rect uv = {};
// TODO(allen): do(think about baking unit_u/unit_v into font data)
f32 unit_u = 1.f/tex_width;
f32 unit_v = 1.f/tex_height;
#else
uv.x0 = bounds.x0*unit_u;
uv.y0 = bounds.y0*unit_v;
uv.x1 = bounds.x1*unit_u;
uv.y1 = bounds.y1*unit_v;
u16 glyph_index = 0;
if (!table_read(&face->codepoint_to_index_table, codepoint, &glyph_index)){
glyph_index = 0;
}
Glyph_Bounds bounds = face->bounds[glyph_index];
GLuint tex = face->gpu_texture;
Vec3_f32 gpu_texture_dim = face->gpu_texture_dim;
#endif
private_draw_set_color(t, glyph->color);
private_draw_bind_texture(t, tex);
glBegin(GL_QUADS);
if ((glyph->flags & GlyphFlag_Rotate90) == 0){
glTexCoord2f(uv.x0, uv.y1); glVertex2f(x + bounds.xoff , y + bounds.yoff2);
glTexCoord2f(uv.x1, uv.y1); glVertex2f(x + bounds.xoff2, y + bounds.yoff2);
glTexCoord2f(uv.x1, uv.y0); glVertex2f(x + bounds.xoff2, y + bounds.yoff );
glTexCoord2f(uv.x0, uv.y0); glVertex2f(x + bounds.xoff , y + bounds.yoff );
f32 x = glyph->pos.x;
f32 y = glyph->pos.y;
f32_Rect uv = Rf32(bounds.uv.x0, bounds.uv.y0,
bounds.uv.x1, bounds.uv.y1);
f32_Rect xy = Rf32(x + bounds.xy_off.x0, y + bounds.xy_off.y0,
x + bounds.xy_off.x1, y + bounds.xy_off.y1);
struct Textutred_Vertex{
Vec2 xy;
Vec2 uv;
};
Textutred_Vertex vertices[4];
if (!HasFlag(glyph->flags, GlyphFlag_Rotate90)){
vertices[0].xy = V2(xy.x0, xy.y1); vertices[0].uv = V2(uv.x0, uv.y1);
vertices[1].xy = V2(xy.x1, xy.y1); vertices[1].uv = V2(uv.x1, uv.y1);
vertices[2].xy = V2(xy.x0, xy.y0); vertices[2].uv = V2(uv.x0, uv.y0);
vertices[3].xy = V2(xy.x1, xy.y0); vertices[3].uv = V2(uv.x1, uv.y0);
}
else{
glTexCoord2f(uv.x0, uv.y1); glVertex2f(x + bounds.yoff2, y + bounds.xoff2);
glTexCoord2f(uv.x1, uv.y1); glVertex2f(x + bounds.yoff2, y + bounds.xoff );
glTexCoord2f(uv.x1, uv.y0); glVertex2f(x + bounds.yoff , y + bounds.xoff );
glTexCoord2f(uv.x0, uv.y0); glVertex2f(x + bounds.yoff , y + bounds.xoff2);
vertices[0].xy = V2(xy.x0, xy.y1); vertices[0].uv = V2(uv.x1, uv.y1);
vertices[1].xy = V2(xy.x1, xy.y1); vertices[1].uv = V2(uv.x1, uv.y0);
vertices[2].xy = V2(xy.x0, xy.y0); vertices[2].uv = V2(uv.x0, uv.y1);
vertices[3].xy = V2(xy.x1, xy.y0); vertices[3].uv = V2(uv.x0, uv.y0);
}
glEnd();
gl__draw_bind_texture(t, tex);
Vec4 c = unpack_color4(glyph->color);
i32 vertex_count = ArrayCount(vertices);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
glEnableVertexAttribArray(gpu_program.vertex_p);
glEnableVertexAttribArray(gpu_program.vertex_t);
glVertexAttribPointer(gpu_program.vertex_p, 2, GL_FLOAT, true, sizeof(vertices[0]), GLOffset(&vertices[0], xy));
glVertexAttribPointer(gpu_program.vertex_t, 2, GL_FLOAT, true, sizeof(vertices[0]), GLOffset(&vertices[0], uv));
glUniform2f(gpu_program.view_t, width/2.f, height/2.f);
f32 m[4] = {
2.f/width, 0.f,
0.f, -2.f/height,
};
glUniformMatrix2fv(gpu_program.view_m, 1, GL_FALSE, m);
glUniform4f(gpu_program.color, c.r, c.g, c.b, c.a);
glUniform1i(gpu_program.sampler, 0);
glUniform1f(gpu_program.texture_override, 0.f);
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertex_count);
glDisableVertexAttribArray(gpu_program.vertex_p);
glDisableVertexAttribArray(gpu_program.vertex_t);
#if 0
if (codepoint != ' ' && font.settings->parameters.underline){
// TODO(allen): recover this feature
glDisable(GL_TEXTURE_2D);
f32 x0 = x;
@ -239,6 +385,7 @@ interpret_render_buffer(Render_Target *t, Arena *scratch){
glEnable(GL_TEXTURE_2D);
}
#endif
}break;
case RenCom_ChangeClip:

View File

@ -63,8 +63,6 @@ link_system_code(){
SYSLINK(set_fullscreen);
SYSLINK(is_fullscreen);
SYSLINK(show_mouse_cursor);
SYSLINK(log);
}
// BOTTOM

View File

@ -46,11 +46,11 @@ memory_init(){
internal void
load_app_code(void){
LOG("Loading 4coder core...");
//LOG("Loading 4coder core...");
App_Get_Functions *get_funcs = 0;
if (system_load_library(&libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){
if (system_load_library(&shared_vars.scratch, &libraries.app_code, "4ed_app", LoadLibrary_BinaryDirectory)){
get_funcs = (App_Get_Functions*)system_get_proc(&libraries.app_code, "app_get_functions");
}
else{
@ -95,7 +95,7 @@ load_custom_code(){
for (u32 i = 0; custom_files[i] != 0 && !has_library; ++i){
char *file = custom_files[i];
for (u32 j = 0; j < ArrayCount(locations) && !has_library; ++j){
if (system_load_library(&libraries.custom, file, locations[j], success_file, sizeof(success_file))){
if (system_load_library(&shared_vars.scratch, &libraries.custom, file, locations[j], success_file, sizeof(success_file))){
has_library = true;
success_file[sizeof(success_file) - 1] = 0;
}
@ -120,12 +120,12 @@ load_custom_code(){
system_error_box(custom_fail_missing_get_bindings_msg);
}
LOGF("Loaded custom file: %s\n", success_file);
//LOGF("Loaded custom file: %s\n", success_file);
}
internal void
read_command_line(i32 argc, char **argv){
LOG("Reading command line\n");
//LOG("Reading command line\n");
char cwd[4096];
u32 size = sysfunc.get_current_path(cwd, sizeof(cwd));
if (size == 0 || size >= sizeof(cwd)){
@ -139,7 +139,7 @@ read_command_line(i32 argc, char **argv){
i32 *file_count = 0;
app.read_command_line(&sysfunc, &memory_vars, curdir, &plat_settings, &files, &file_count, argc, argv);
sysshared_filter_real_files(files, file_count);
LOG("Read command line.\n");
//LOG("Read command line.\n");
}
internal void

View File

@ -36,59 +36,57 @@ enum{
};
internal b32
system_load_library(Library *library, char *name, Load_Library_Location location, char *full_file_out, u32 full_file_max){
char space[4096];
String extension = file_extension(make_string_slowly(name));
if (!match(extension, DLL)){
String full_name = make_fixed_width_string(space);
append(&full_name, name);
append(&full_name, "." DLL);
if (terminate_with_null(&full_name)){
name = space;
}
else{
name = 0;
}
system_load_library(Arena *scratch, Library *library, char *name_cstr, Load_Library_Location location, char *full_file_out, u32 full_file_max){
Temp_Memory temp = begin_temp(scratch);
String_Const_char name = SCchar(name_cstr);
String_Const_char extension = string_file_extension(name);
if (!string_match(extension, string_litexpr( DLL ))){
String_Const_char full_name = push_stringf(scratch, "%.*s." DLL, string_expand(name));
name_cstr = full_name.str;
}
char path_space[4096];
String path = make_fixed_width_string(path_space);
umem memory_size = KB(4);
String_Const_char path = {};
path.str = push_array(scratch, char, memory_size);
switch (location){
case LoadLibrary_CurrentDirectory:
{
path.size = sysfunc.get_current_path(path.str, path.memory_size);
path.size = (umem)sysfunc.get_current_path(path.str, (i32)memory_size);
}break;
case LoadLibrary_BinaryDirectory:
{
path.size = sysfunc.get_4ed_path(path.str, path.memory_size);
path.size = (umem)sysfunc.get_4ed_path(path.str, (i32)memory_size);
}break;
default: LOG("Invalid library location passed.\n"); break;
//default: LOG("Invalid library location passed.\n"); break;
}
b32 success = false;
if (path.size > 0){
if (path.str[path.size - 1] != SLASH){
append(&path, SLASH);
path = push_stringf(scratch, "%.*s%c%.*s", string_expand(path), SLASH, string_expand(name));
}
else{
path = push_stringf(scratch, "%.*s%.*s", string_expand(path), string_expand(name));
}
append(&path, name);
terminate_with_null(&path);
success = system_load_library_direct(library, path.str);
if (success && full_file_out != 0){
String out = make_string_cap(full_file_out, 0, full_file_max);
copy(&out, path);
terminate_with_null(&out);
if (success && full_file_out != 0 && full_file_out > 0){
u32 fill_size = clamp_top((u32)(path.size), (u32)(full_file_max - 1));
block_copy(full_file_out, path.str, fill_size);
full_file_out[fill_size] = 0;
}
}
end_temp(temp);
return(success);
}
internal b32
system_load_library(Library *library, char *name, Load_Library_Location location){
b32 result = system_load_library(library, name, location, 0, 0);
return(result);
system_load_library(Arena *scratch, Library *library, char *name, Load_Library_Location location){
return(system_load_library(scratch, library, name, location, 0, 0));
}
#endif

View File

@ -16,12 +16,6 @@
// Standard implementation of file system stuff based on the file track layer.
//
internal i32
system_get_binary_path_string(String *out){
out->size = system_get_4ed_path(out->str, out->memory_size);
return(out->size);
}
internal void
init_shared_vars(){
shared_vars.scratch = make_arena_system(&sysfunc);
@ -46,20 +40,6 @@ sysshared_filter_real_files(char **files, i32 *file_count){
*file_count = j;
}
internal b32
sysshared_to_binary_path(String *out_filename, char *filename){
b32 translate_success = 0;
i32 max = out_filename->memory_size;
i32 size = out_filename->size = system_get_4ed_path(out_filename->str, out_filename->memory_size);
if (size > 0 && size < max-1){
out_filename->size = size;
if (append_sc(out_filename, filename) && terminate_with_null(out_filename)){
translate_success = 1;
}
}
return(translate_success);
}
#endif
// BOTTOM

View File

@ -37,7 +37,6 @@
#include "4ed_font.h"
#include "4ed_system.h"
#include "4ed_log.h"
#include "4ed_render_target.h"
#include "4ed_render_format.h"
#include "4ed.h"
@ -86,7 +85,7 @@
#define frame_useconds (1000000UL / FPS)
#define LINUX_FN_DEBUG(fmt, ...) do { \
LOGF("%s: " fmt "\n", __func__, ##__VA_ARGS__); \
/*LOGF("%s: " fmt "\n", __func__, ##__VA_ARGS__);*/ \
} while (0)
// TODO(allen): Make an intrinsics header that uses the cracked OS to define a single set of intrinsic names.
@ -678,7 +677,7 @@ linux_get_loadable_fonts(Partition *part, Font_Setup_List *list){
FcObjectSet* os = FcObjectSetBuild(FC_FAMILY, FC_FILE, (char*)0);
FcFontSet* fs = FcFontList(fc_config, pat, os);
if (fs != 0){
LOGF("Total matching fonts: %d\n", fs->nfont);
//LOGF("Total matching fonts: %d\n", fs->nfont);
for (int i=0; fs && i < fs->nfont; ++i) {
FcPattern* font = fs->fonts[i];
FcChar8 *file = 0;
@ -776,7 +775,7 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con
int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);
if (glXCreateContextAttribsARB == 0){
LOG("glXCreateContextAttribsARB() not found, using old-style GLX context\n" );
//LOG("glXCreateContextAttribsARB() not found, using old-style GLX context\n" );
ctx = glXCreateNewContext( XDisplay, *best_config, GLX_RGBA_TYPE, 0, True );
}
else{
@ -790,15 +789,15 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con
None
};
LOG("Creating GL 2.1 context... ");
//LOG("Creating GL 2.1 context... ");
ctx = glXCreateContextAttribsARB(XDisplay, *best_config, 0, True, context_attribs);
XSync( XDisplay, False );
if (!ctxErrorOccurred && ctx){
LOG("Created GL 2.1 context.\n");
//LOG("Created GL 2.1 context.\n");
}
else{
LOG("Could not create a context.\n");
//LOG("Could not create a context.\n");
exit(1);
}
}
@ -807,21 +806,21 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con
XSetErrorHandler(oldHandler);
if (ctxErrorOccurred || !ctx){
LOG("Failed to create an OpenGL context\n");
//LOG("Failed to create an OpenGL context\n");
exit(1);
}
b32 Direct;
if (!glXIsDirect(XDisplay, ctx)){
LOG("Indirect GLX rendering context obtained\n");
//LOG("Indirect GLX rendering context obtained\n");
Direct = false;
}
else{
LOG("Direct GLX rendering context obtained\n");
//LOG("Direct GLX rendering context obtained\n");
Direct = true;
}
LOG("Making context current\n");
//LOG("Making context current\n");
glXMakeCurrent( XDisplay, XWindow, ctx );
//TODO(inso): glGetStringi is required in core profile if the GL version is >= 3.0
@ -838,7 +837,7 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con
glXQueryDrawable(XDisplay, XWindow, GLX_SWAP_INTERVAL_EXT, &swap_val);
linuxvars.vsync = (swap_val == true);
LOGF("VSync enabled? %s.\n", linuxvars.vsync ? "Yes" : "No");
//LOGF("VSync enabled? %s.\n", linuxvars.vsync ? "Yes" : "No");
}
}
@ -852,12 +851,12 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con
if (glXGetSwapIntervalMESA != 0){
linuxvars.vsync = glXGetSwapIntervalMESA();
LOGF("VSync enabled? %s (MESA)\n", linuxvars.vsync ? "Yes" : "No");
//LOGF("VSync enabled? %s (MESA)\n", linuxvars.vsync ? "Yes" : "No");
}
else{
// NOTE(inso): assume it worked?
linuxvars.vsync = true;
LOG("VSync enabled? possibly (MESA)\n");
//LOG("VSync enabled? possibly (MESA)\n");
}
}
@ -870,12 +869,12 @@ InitializeOpenGLContext(Display *XDisplay, Window XWindow, GLXFBConfig *best_con
// NOTE(inso): The SGI one doesn't seem to have a way to confirm we got it...
linuxvars.vsync = true;
LOG("VSync enabled? hopefully (SGI)\n");
//LOG("VSync enabled? hopefully (SGI)\n");
}
}
else{
LOG("VSync enabled? nope, no suitable extension\n");
//LOG("VSync enabled? nope, no suitable extension\n");
}
return(ctx);
@ -889,10 +888,10 @@ GLXCanUseFBConfig(Display *XDisplay)
int GLXMajor, GLXMinor;
char *XVendor = ServerVendor(XDisplay);
LOGF("XWindows vendor: %s\n", XVendor);
//LOGF("XWindows vendor: %s\n", XVendor);
if (glXQueryVersion(XDisplay, &GLXMajor, &GLXMinor))
{
LOGF("GLX version %d.%d\n", GLXMajor, GLXMinor);
//LOGF("GLX version %d.%d\n", GLXMajor, GLXMinor);
if (((GLXMajor == 1 ) && (GLXMinor >= 3)) || (GLXMajor > 1))
{
Result = true;
@ -939,7 +938,7 @@ ChooseGLXConfig(Display *XDisplay, int XScreenIndex)
int id = 0;
glXGetFBConfigAttrib(XDisplay, Result.BestConfig, GLX_FBCONFIG_ID, &id);
LOGF("Using FBConfig: %d (0x%x)\n", id, id);
//LOGF("Using FBConfig: %d (0x%x)\n", id, id);
XFree(VI);
}
@ -971,12 +970,12 @@ LinuxInputInit(Display *dpy, Window XWindow){
setlocale(LC_ALL, "");
XSetLocaleModifiers("");
b32 locale_supported = XSupportsLocale();
LOGF("Supported locale?: %s.\n", locale_supported ? "Yes" : "No");
//LOGF("Supported locale?: %s.\n", locale_supported ? "Yes" : "No");
if (!locale_supported){
LOG("Reverting to 'C' ... ");
//LOG("Reverting to 'C' ... ");
setlocale(LC_ALL, "C");
locale_supported = XSupportsLocale();
LOGF("C is supported? %s.\n", locale_supported ? "Yes" : "No");
//LOGF("C is supported? %s.\n", locale_supported ? "Yes" : "No");
}
result.input_method = XOpenIM(dpy, 0, 0, 0);
@ -1010,13 +1009,13 @@ LinuxInputInit(Display *dpy, Window XWindow){
}
else{
result = null_init_input_result;
LOG("Could not get minimum required input style.\n");
//LOG("Could not get minimum required input style.\n");
exit(1);
}
}
else{
result = null_init_input_result;
LOG("Could not open X Input Method.\n");
//LOG("Could not open X Input Method.\n");
exit(1);
}
@ -1189,7 +1188,7 @@ LinuxGetXSettingsDPI(Display* dpy, int screen)
Atom XSET_SET = XInternAtom(dpy, "_XSETTINGS_SETTINGS", True);
if (XSET_SEL == None || XSET_SET == None){
LOG("XSETTINGS unavailable.\n");
//LOG("XSETTINGS unavailable.\n");
return(dpi);
}
@ -1206,12 +1205,12 @@ LinuxGetXSettingsDPI(Display* dpy, int screen)
unsigned long pad, num;
if (XGetWindowProperty(dpy, xset_win, XSET_SET, 0, 1024, False, XSET_SET, &type, &fmt, &num, &pad, &prop) != Success){
LOG("XSETTINGS: GetWindowProperty failed.\n");
//LOG("XSETTINGS: GetWindowProperty failed.\n");
goto out;
}
if (fmt != 8){
LOG("XSETTINGS: Wrong format.\n");
//LOG("XSETTINGS: Wrong format.\n");
goto out;
}
}
@ -1220,7 +1219,7 @@ LinuxGetXSettingsDPI(Display* dpy, int screen)
p = (char*)(xs + 1);
if (xs->byte_order != 0){
LOG("FIXME: XSETTINGS not host byte order?\n");
//LOG("FIXME: XSETTINGS not host byte order?\n");
goto out;
}
@ -1253,7 +1252,7 @@ LinuxGetXSettingsDPI(Display* dpy, int screen)
} break;
default: {
LOG("XSETTINGS: Got invalid type...\n");
//LOG("XSETTINGS: Got invalid type...\n");
goto out;
} break;
}
@ -1457,7 +1456,7 @@ linux_handle_x11_events(void)
//TODO(inso): handle properly
Xutf8ResetIC(linuxvars.input_context);
XSetICFocus(linuxvars.input_context);
LOG("FIXME: XBufferOverflow from LookupString.\n");
//LOG("FIXME: XBufferOverflow from LookupString.\n");
}
// don't push modifiers
@ -1478,7 +1477,7 @@ linux_handle_x11_events(void)
//TODO(inso): handle properly
Xutf8ResetIC(linuxvars.input_context);
XSetICFocus(linuxvars.input_context);
LOG("FIXME: XBufferOverflow from LookupString.\n");
//LOG("FIXME: XBufferOverflow from LookupString.\n");
}
if (*buff_no_caps){
@ -1973,7 +1972,7 @@ main(int argc, char **argv){
linuxvars.XDisplay = XOpenDisplay(0);
if (!linuxvars.XDisplay){
// NOTE(inso): probably not worth trying the popup in this case...
LOG("Can't open display!\n");
//LOG("Can't open display!\n");
exit(1);
}
@ -2009,10 +2008,10 @@ main(int argc, char **argv){
linuxvars.dpi_x = dw_mm ? dw / (dw_mm / 25.4) : 96;
linuxvars.dpi_y = dh_mm ? dh / (dh_mm / 25.4) : 96;
LOGF("%dx%d - %dmmx%dmm DPI: %dx%d\n", dw, dh, dw_mm, dh_mm, linuxvars.dpi_x, linuxvars.dpi_y);
//LOGF("%dx%d - %dmmx%dmm DPI: %dx%d\n", dw, dh, dw_mm, dh_mm, linuxvars.dpi_x, linuxvars.dpi_y);
}
else{
LOGF("DPI from XSETTINGS: %d\n", linuxvars.dpi_x);
//LOGF("DPI from XSETTINGS: %d\n", linuxvars.dpi_x);
}
int window_width, window_height;
@ -2028,7 +2027,7 @@ main(int argc, char **argv){
XFixesSelectSelectionInput(linuxvars.XDisplay, linuxvars.XWindow, linuxvars.atom_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask);
}
else{
LOG("Your X server doesn't support XFIXES, mention this fact if you report any clipboard-related issues.\n");
//LOG("Your X server doesn't support XFIXES, mention this fact if you report any clipboard-related issues.\n");
}
Init_Input_Result input_result = LinuxInputInit(linuxvars.XDisplay, linuxvars.XWindow);
@ -2109,7 +2108,7 @@ main(int argc, char **argv){
terminate_with_null(&curdir);
replace_char(&curdir, '\\', '/');
LOG("Initializing application variables\n");
//LOG("Initializing application variables\n");
app.init(&sysfunc, &target, &memory_vars, linuxvars.clipboard_contents, curdir, custom_api);
LinuxResizeTarget(window_width, window_height);
@ -2140,7 +2139,7 @@ main(int argc, char **argv){
if (num_events == -1){
if (errno != EINTR){
LOG("epoll_wait\n");
//LOG("epoll_wait\n");
}
continue;
}
@ -2215,7 +2214,7 @@ main(int argc, char **argv){
result = app.step(&sysfunc, &target, &memory_vars, &frame_input);
}
else{
LOG("app.step == 0 -- skipping\n");
//LOG("app.step == 0 -- skipping\n");
}
@ -2242,7 +2241,7 @@ main(int argc, char **argv){
}
// NOTE(allen): Render
interpret_render_buffer(&target, &shared_vars.pixel_scratch);
gl_render(&target, &shared_vars.pixel_scratch);
glXSwapBuffers(linuxvars.XDisplay, linuxvars.XWindow);
// NOTE(allen): Toggle Full Screen

View File

@ -13,7 +13,7 @@
// HACK(allen): // NOTE(inso): this was a quick hack, might need some cleanup.
internal void
system_error_box(char *msg, b32 shutdown = true){
LOGF("Fatal Error: %s\n", msg);
//LOGF("Fatal Error: %s\n", msg);
Display *dpy = XOpenDisplay(0);
if (!dpy){

View File

@ -38,7 +38,6 @@
#include "4ed_font.h"
#include "4ed_system.h"
#include "4ed_log.h"
#include "4ed_render_target.h"
#include "4ed_render_format.h"
#include "4ed.h"
@ -722,7 +721,7 @@ osx_step(void){
result = app.step(&sysfunc, &target, &memory_vars, &frame_input);
}
else{
LOG("app.step == 0 -- skipping\n");
//LOG("app.step == 0 -- skipping\n");
}
// NOTE(allen): Finish the Loop
@ -743,7 +742,7 @@ osx_step(void){
// NOTE(allen): Render
osx_begin_render();
interpret_render_buffer(&target, &shared_vars.pixel_scratch);
gl_render(&target, &shared_vars.pixel_scratch);
osx_end_render();
// NOTE(allen): Toggle Full Screen
@ -865,7 +864,7 @@ osx_init(){
clipboard_string = make_string(osx_objc.clipboard_data, osx_objc.clipboard_size);
}
LOG("Initializing application variables\n");
//LOG("Initializing application variables\n");
app.init(&sysfunc, &target, &memory_vars, clipboard_string, curdir, custom_api);
}

View File

@ -16,7 +16,6 @@
#include "4coder_API/4coder_version.h"
#include "4coder_API/4coder_keycodes.h"
#include "4ed_log.h"
#include "4ed_cursor_codes.h"
#include "4ed_linked_node_macros.h"
@ -522,7 +521,7 @@ osx_file_listener_hash(u64 hash, void *name, i32 counter, File_Watching_Handle *
}
if (!result){
LOG("file change listener table error: could not find a free slot in the table\n");
//LOG("file change listener table error: could not find a free slot in the table\n");
}
}

View File

@ -11,7 +11,7 @@
internal void
system_error_box(char *msg, b32 shutdown = true){
LOGF("error box: %s\n", msg);
//LOGF("error box: %s\n", msg);
osx_error_dialogue(msg);
if (shutdown){
exit(1);

View File

@ -39,11 +39,11 @@ print_open_file_descriptors(void){
if (descriptor_open(fd)){
char b[MAXPATHLEN + 1];
fcntl(fd, F_GETPATH, b);
LOGF("FD(%d) = \"%s\"\n", fd, b);
//LOGF("FD(%d) = \"%s\"\n", fd, b);
}
}
}
#define FD_CHECK() LOG("FD_CHECK\n"); print_open_file_descriptors()
//#define FD_CHECK() LOG("FD_CHECK\n"); print_open_file_descriptors()
// BOTTOM

View File

@ -32,44 +32,6 @@ Sys_Get_Current_Path_Sig(system_get_current_path){
return(result);
}
//
// Logging
//
internal
Sys_Log_Sig(system_log){
if (plat_settings.use_log == LogTo_LogFile){
char file_path_space[1024];
String file_path = make_fixed_width_string(file_path_space);
file_path.size = system_get_4ed_path(file_path.str, file_path.memory_size);
append_sc(&file_path, "4coder_log.txt");
terminate_with_null(&file_path);
i32 fd = -1;
if (unixvars.did_first_log){
fd = open(file_path.str, O_WRONLY | O_CREAT | O_APPEND, 00640);
}
else{
fd = open(file_path.str, O_WRONLY | O_CREAT | O_TRUNC, 00640);
unixvars.did_first_log = true;
}
if (fd >= 0){
do{
ssize_t written = write(fd, message, length);
if (written != -1){
length -= written;
message += written;
}
} while(length > 0);
close(fd);
}
}
else if (plat_settings.use_log == LogTo_Stdout){
fwrite(message, 1, length, stdout);
}
}
//
// Shared system functions (system_shared.h)
//
@ -77,7 +39,7 @@ Sys_Log_Sig(system_log){
internal
Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
b32 result = access((char*)filename, W_OK) == 0;
LOGF("%s = %d\n", filename, result);
//LOGF("%s = %d\n", filename, result);
return(result);
}
@ -91,7 +53,6 @@ system_memory_allocate_extended(void *base, umem size){
// We will count on the user to keep track of size themselves.
void *result = mmap(base, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (result == MAP_FAILED){
LOG("error: mmap failed\n");
result = 0;
}
return(result);
@ -132,7 +93,6 @@ Sys_Memory_Set_Protection_Sig(system_memory_set_protection){
if(mprotect(ptr, size, protect) == -1){
result = 0;
LOG("error: mprotect\n");
}
return(result);
@ -159,7 +119,7 @@ Sys_Set_File_List_Sig(system_set_file_list){
return;
}
LOGF("%s\n", directory);
//LOGF("%s\n", directory);
DIR *d = opendir(directory);
if (d != 0){
@ -296,7 +256,7 @@ Sys_Get_Canonical_Sig(system_get_canonical){
#if defined(FRED_INTERNAL)
if (len != (write_p - path) || memcmp(filename, path, len) != 0){
LOGF("[%.*s] -> [%.*s]\n", len, filename, (int)(write_p - path), path);
//LOGF("[%.*s] -> [%.*s]\n", len, filename, (int)(write_p - path), path);
}
#endif
@ -313,10 +273,10 @@ Sys_Load_Handle_Sig(system_load_handle){
i32 fd = open(filename, O_RDONLY);
if (fd == -1 || fd == 0){
LOGF("upable to open file descriptor for %s\n", filename);
//LOGF("upable to open file descriptor for %s\n", filename);
}
else{
LOGF("file descriptor (%d) == file %s\n", fd, filename);
//LOGF("file descriptor (%d) == file %s\n", fd, filename);
*(i32*)handle_out = fd;
result = true;
}
@ -332,10 +292,10 @@ Sys_Load_Size_Sig(system_load_size){
struct stat st = {};
if (fstat(fd, &st) == -1){
LOGF("unable to stat a file\n");
//LOGF("unable to stat a file\n");
}
else{
LOGF("file descriptor (%d) has size %d\n", fd, (i32)st.st_size);
//LOGF("file descriptor (%d) has size %d\n", fd, (i32)st.st_size);
result = st.st_size;
}
@ -350,7 +310,7 @@ Sys_Load_File_Sig(system_load_file){
ssize_t n = read(fd, buffer, size);
if (n == -1){
if (errno != EINTR){
LOGF("error reading from file descriptor (%d)\n", fd);
//LOGF("error reading from file descriptor (%d)\n", fd);
break;
}
}
@ -369,11 +329,11 @@ Sys_Load_Close_Sig(system_load_close){
i32 fd = *(i32*)&handle;
if (close(fd) == -1){
LOGF("error closing file descriptor (%d)\n", fd);
//LOGF("error closing file descriptor (%d)\n", fd);
result = false;
}
else{
LOGF("file descriptor (%d) closed\n", fd);
//LOGF("file descriptor (%d) closed\n", fd);
}
FD_CHECK();
@ -385,16 +345,15 @@ internal
Sys_Save_File_Sig(system_save_file){
i32 fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 00640);
LOGF("%s %d\n", filename, size);
//LOGF("%s %d\n", filename, size);
if (fd < 0){
LOGF("error: open '%s': %s\n", filename, strerror(errno));
//LOGF("error: open '%s': %s\n", filename, strerror(errno));
}
else{
do{
ssize_t written = write(fd, buffer, size);
if (written == -1){
if (errno != EINTR){
LOG("error: write\n");
break;
}
}
@ -419,7 +378,7 @@ Sys_File_Exists_Sig(system_file_exists){
char buff[PATH_MAX] = {};
if (len + 1 > PATH_MAX){
LOG("system_directory_has_file: path too long\n");
//LOG("system_directory_has_file: path too long\n");
}
else{
memcpy(buff, filename, len);
@ -428,7 +387,7 @@ Sys_File_Exists_Sig(system_file_exists){
result = stat(buff, &st) == 0 && S_ISREG(st.st_mode);
}
LOGF("%s: %d\n", buff, result);
//LOGF("%s: %d\n", buff, result);
return(result);
}

File diff suppressed because it is too large Load Diff

View File

@ -84,54 +84,34 @@ Sys_Get_4ed_Path_Sig(system_get_4ed_path){
u8 *memory = (u8*)system_memory_allocate(binary_path_capacity);
i32 size = GetModuleFileName_utf8(&shared_vars.scratch, 0, memory, binary_path_capacity);
Assert(size <= binary_path_capacity - 1);
win32vars.binary_path = make_string(memory, size);
remove_last_folder(&win32vars.binary_path);
terminate_with_null(&win32vars.binary_path);
win32vars.binary_path = SCu8(memory, size);
win32vars.binary_path = string_remove_last_folder(win32vars.binary_path);
win32vars.binary_path.str[win32vars.binary_path.size] = 0;
}
i32 copy_size = Min(win32vars.binary_path.size, capacity);
i32 copy_size = Min((i32)(win32vars.binary_path.size), capacity);
block_copy(out, win32vars.binary_path.str, copy_size);
return(win32vars.binary_path.size);
}
//
// Logging
//
internal
Sys_Log_Sig(system_log){
if (plat_settings.use_log){
u8 space[4096];
String str = make_fixed_width_string(space);
str.size = system_get_4ed_path(str.str, str.memory_size);
append_sc(&str, "4coder_log.txt");
terminate_with_null(&str);
HANDLE file = CreateFile_utf8(&shared_vars.scratch, space, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
SetFilePointer(file, win32vars.log_position, 0, FILE_BEGIN);
win32vars.log_position += length;
DWORD written = 0;
DWORD total_written = 0;
do{
WriteFile(file, message + total_written, length - total_written, &written, 0);
total_written += written;
}while (total_written < length);
CloseHandle(file);
}
}
return((i32)(win32vars.binary_path.size));
}
//
// Files
//
internal String
win32_remove_unc_prefix_characters(String path){
if (match_part(path, make_lit_string("\\\\?\\UNC"))){
internal String_Const_u8
win32_remove_unc_prefix_characters(String_Const_u8 path){
if (string_match(string_prefix(path, 7), string_u8_litexpr("\\\\?\\UNC"))){
#if 0
// TODO(allen): Why no just do
path = string_skip(path, 7);
path.str[0] = '\\';
// ?
#endif
path.size -= 7;
memmove(path.str, path.str + 7, path.size);
path.str[0] = '\\';
}
else if (match_part(path, make_lit_string("\\\\?\\"))){
else if (string_match(string_prefix(path, 4), string_u8_litexpr("\\\\?\\"))){
// TODO(allen): Same questions essentially.
path.size -= 4;
memmove(path.str, path.str + 4, path.size);
}
@ -142,27 +122,27 @@ internal
Sys_Set_File_List_Sig(system_set_file_list){
b32 clear_list = true;
if (directory != 0){
char dir_space[MAX_PATH + 32];
String dir = make_string_cap(dir_space, 0, MAX_PATH + 32);
append_sc(&dir, directory);
terminate_with_null(&dir);
u8 dir_space[MAX_PATH + 32];
umem directory_original_length = cstring_length(directory);
block_copy(dir_space, directory, directory_original_length);
String_Const_u8 dir = SCu8(dir_space, directory_original_length);
HANDLE dir_handle = CreateFile_utf8(&shared_vars.scratch, (u8*)dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0);
HANDLE dir_handle = CreateFile_utf8(&shared_vars.scratch, dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0);
if (dir_handle != INVALID_HANDLE_VALUE){
DWORD final_length = GetFinalPathNameByHandle_utf8(&shared_vars.scratch, dir_handle, (u8*)dir_space, sizeof(dir_space), 0);
DWORD final_length = GetFinalPathNameByHandle_utf8(&shared_vars.scratch, dir_handle, dir_space, sizeof(dir_space), 0);
CloseHandle(dir_handle);
if (final_length + 3 < sizeof(dir_space)){
u8 *c_str_dir = (u8*)dir_space;
u8 *c_str_dir = dir_space;
if (c_str_dir[final_length - 1] == 0){
--final_length;
}
String str_dir = make_string(c_str_dir, final_length);
String adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
String_Const_u8 str_dir = SCu8(c_str_dir, final_length);
String_Const_u8 adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
c_str_dir = (u8*)adjusted_str_dir.str;
final_length = adjusted_str_dir.size;
c_str_dir = adjusted_str_dir.str;
final_length = (DWORD)(adjusted_str_dir.size);
c_str_dir[final_length] = '\\';
c_str_dir[final_length + 1] = '*';
c_str_dir[final_length + 2] = 0;
@ -177,9 +157,9 @@ Sys_Set_File_List_Sig(system_set_file_list){
*canon_directory_size_out = final_length;
}
else{
u32 length = copy_fast_unsafe_cc(canon_directory_out, directory);
canon_directory_out[length] = 0;
*canon_directory_size_out = length;
block_copy(canon_directory_out, directory, directory_original_length);
canon_directory_out[directory_original_length] = 0;
*canon_directory_size_out = (i32)directory_original_length;
}
}
@ -244,8 +224,8 @@ Sys_Set_File_List_Sig(system_set_file_list){
info->filename_len = length;
*name++ = 0;
String fname = make_string_cap(info->filename, length, length+1);
replace_char(&fname, '\\', '/');
String_Const_u8 fname = SCu8(info->filename, length);
fname = string_mod_replace_character(fname, '\\', '/');
++info;
++corrected_file_count;
}
@ -293,10 +273,10 @@ Sys_Get_Canonical_Sig(system_get_canonical){
if (buffer[final_length - 1] == 0){
--final_length;
}
String str_dir = make_string(buffer, final_length);
String adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
buffer = adjusted_str_dir.str;
final_length = adjusted_str_dir.size;
String_Const_u8 str_dir = SCu8(buffer, final_length);
String_Const_u8 adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
buffer = (char*)adjusted_str_dir.str;
final_length = (i32)adjusted_str_dir.size;
buffer[final_length] = 0;
result = final_length;
}
@ -304,9 +284,9 @@ Sys_Get_Canonical_Sig(system_get_canonical){
CloseHandle(file);
}
else{
String src_str = make_string(filename, len);
String path_str = path_of_directory(src_str);
String front_str = front_of_directory(src_str);
String_Const_u8 src_str = SCu8(filename, len);
String_Const_u8 path_str = string_remove_last_folder(src_str);
String_Const_u8 front_str = string_front_of_path(src_str);
memcpy(src_space, path_str.str, path_str.size);
src_space[path_str.size] = 0;
@ -320,13 +300,13 @@ Sys_Get_Canonical_Sig(system_get_canonical){
if (buffer[final_length-1] == 0){
--final_length;
}
String str_dir = make_string(buffer, final_length);
String adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
buffer = adjusted_str_dir.str;
final_length = adjusted_str_dir.size;
String_Const_u8 str_dir = SCu8(buffer, final_length);
String_Const_u8 adjusted_str_dir = win32_remove_unc_prefix_characters(str_dir);
buffer = (char*)adjusted_str_dir.str;
final_length = (i32)adjusted_str_dir.size;
buffer[final_length++] = '\\';
memcpy(buffer + final_length, front_str.str, front_str.size);
final_length += front_str.size;
final_length += (i32)(front_str.size);
buffer[final_length] = 0;
result = final_length;
}

View File

@ -11,7 +11,7 @@
internal void
system_error_box(char *msg, b32 shutdown = true){
LOGF("error box: %s\n", msg);
//LOGF("error box: %s\n", msg);
MessageBox_utf8(&shared_vars.scratch, 0, (u8*)msg, (u8*)"Error", 0);
if (shutdown){
exit(1);

View File

@ -59,16 +59,18 @@
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
#define WGL_CONTEXT_FLAGS_ARB 0x2094
#define ERROR_INVALID_VERSION_ARB 0x2095
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
#define WGL_CONTEXT_LAYER_PLANE_ARB 0x2093
#define WGL_CONTEXT_FLAGS_ARB 0x2094
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20A9
#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x0001
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
#define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
#define ERROR_INVALID_VERSION_ARB 0x2095
#define ERROR_INVALID_PROFILE_ARB 0x2096
// BOTTOM

View File

@ -39,8 +39,8 @@ input_8_to_16(Arena *scratch, u8 *in){
}
internal Win32_UTF16
input_8_to_16(Arena *scratch, String in){
return(input_8_to_16(scratch, (u8*)in.str, in.size));
input_8_to_16(Arena *scratch, String_Const_u8 in){
return(input_8_to_16(scratch, in.str, (u32)in.size));
}
internal HANDLE
@ -217,7 +217,7 @@ internal BOOL
GetFileAttributesEx_utf8String(Arena *scratch, String_Const_u8 file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info){
BOOL result = FALSE;
Temp_Memory temp = begin_temp(scratch);
Win32_UTF16 string_16 = input_8_to_16(scratch, string_old_from_new(file_name));
Win32_UTF16 string_16 = input_8_to_16(scratch, file_name);
if (string_16.success){
result = GetFileAttributesExW((LPWSTR)string_16.utf16, info_level_id, file_info);
}