diff --git a/src/os/core/win32/os_core_win32.c b/src/os/core/win32/os_core_win32.c index 13602237..9e829e1f 100644 --- a/src/os/core/win32/os_core_win32.c +++ b/src/os/core/win32/os_core_win32.c @@ -1156,6 +1156,7 @@ internal void os_mutex_release(Mutex mutex) { OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]); + DeleteCriticalSection(&entity->mutex); os_w32_entity_release(entity); } diff --git a/src/render/render_core.c b/src/render/render_core.c index 3e5723c4..09ab175f 100644 --- a/src/render/render_core.c +++ b/src/render/render_core.c @@ -9,6 +9,46 @@ //////////////////////////////// //~ rjf: Helpers +internal U64 +r_bytes_per_pixel_from_tex2dfmt(R_Tex2DFmt fmt) +{ + U64 num_bits = 0; + for EachIndex(channel_idx, 4) + { + R_ChannelSizeKind size_kind = r_size_kind_from_tex2dfmt_channel(fmt, channel_idx); + switch(size_kind) + { + default:{}break; + case R_ChannelSizeKind_2: {num_bits += 2;}break; + case R_ChannelSizeKind_8: {num_bits += 8;}break; + case R_ChannelSizeKind_10:{num_bits += 10;}break; + case R_ChannelSizeKind_11:{num_bits += 11;}break; + case R_ChannelSizeKind_16:{num_bits += 16;}break; + case R_ChannelSizeKind_24:{num_bits += 24;}break; + case R_ChannelSizeKind_32:{num_bits += 32;}break; + } + } + U64 num_bits_rounded = num_bits+7; + num_bits_rounded -= num_bits_rounded%8; + U64 num_bytes = num_bits_rounded/8; + return num_bytes; +} + +internal Mat4x4F32 +r_sample_channel_map_from_tex2dfmt(R_Tex2DFmt fmt) +{ + Mat4x4F32 result = + { + { + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, + } + }; + return result; +} + internal Mat4x4F32 r_sample_channel_map_from_tex2dformat(R_Tex2DFormat fmt) { diff --git a/src/render/render_core.h b/src/render/render_core.h index c23c0503..e9182497 100644 --- a/src/render/render_core.h +++ b/src/render/render_core.h @@ -14,6 +14,62 @@ //////////////////////////////// //~ rjf: Enums +typedef U8 R_ChannelCode; // 3 bits +typedef enum R_ChannelCodeEnum +{ + R_ChannelCode_Null, + R_ChannelCode_R, + R_ChannelCode_G, + R_ChannelCode_B, + R_ChannelCode_A, +} +R_ChannelCodeEnum; + +typedef U8 R_ChannelSizeKind; // 3 bits +typedef enum R_ChannelSizeKindEnum +{ + R_ChannelSizeKind_Null, + R_ChannelSizeKind_2, + R_ChannelSizeKind_8, + R_ChannelSizeKind_10, + R_ChannelSizeKind_11, + R_ChannelSizeKind_16, + R_ChannelSizeKind_24, + R_ChannelSizeKind_32, +} +R_ChannelSizeKindEnum; + +typedef U8 R_ChannelTypeKind; // 3 bits +typedef enum R_ChannelTypeKindEnum +{ + R_ChannelTypeKind_Null, + R_ChannelTypeKind_UInt, + R_ChannelTypeKind_SInt, + R_ChannelTypeKind_UNorm, + R_ChannelTypeKind_SNorm, + R_ChannelTypeKind_Float, +} +R_ChannelTypeKindEnum; + +typedef U64 R_Tex2DFmt; +// +// set of channels, each channel including {code, size, type kind}, 3 bits each: +// [0, 3) -> channel code +// [3, 6) -> channel size +// [6, 9) -> channel type kind +// +// 9 bits per channel, * number of channels, e.g. 4 channels -> 36 bits + +#define R_Channel(channel_idx, code_name, size_kind_name, type_kind_name) ((((U64)(R_ChannelCode_##code_name & 0x7)) | ((U64)(R_ChannelSizeKind_##size_kind_name & 0x7) << 3) | ((U64)(R_ChannelTypeKind_##type_kind_name & 0x7) << 6)) << ((channel_idx)*9)) +#define r_code_from_tex2dfmt_channel(fmt, channel_idx) ((R_ChannelCode)(((fmt) & (0x7<<((channel_idx)*9))) >> ((channel_idx)*9))) +#define r_size_kind_from_tex2dfmt_channel(fmt, channel_idx) ((R_ChannelSizeKind)(((fmt) & (0x38<<((channel_idx)*9))) >> ((channel_idx)*9 + 3))) +#define r_type_kind_from_tex2dfmt_channel(fmt, channel_idx) ((R_ChannelTypeKind)(((fmt) & (0x1c0<<((channel_idx)*9))) >> ((channel_idx)*9 + 6))) + +#define R_Tex2DFmt_R8 (R_Channel(0, R, 8, UInt)) +#define R_Tex2DFmt_RG8 (R_Channel(0, R, 8, UInt) | R_Channel(1, G, 8, UInt)) +#define R_Tex2DFmt_RGB8 (R_Channel(0, R, 8, UInt) | R_Channel(1, G, 8, UInt) | R_Channel(2, B, 8, UInt)) +#define R_Tex2DFmt_RGBA8 (R_Channel(0, R, 8, UInt) | R_Channel(1, G, 8, UInt) | R_Channel(2, B, 8, UInt) | R_Channel(3, A, 8, UInt)) + typedef U32 R_GeoVertexFlags; enum { @@ -197,6 +253,8 @@ struct R_PassList //////////////////////////////// //~ rjf: Helpers +internal U64 r_bytes_per_pixel_from_tex2dfmt(R_Tex2DFmt fmt); +internal Mat4x4F32 r_sample_channel_map_from_tex2dfmt(R_Tex2DFmt fmt); internal Mat4x4F32 r_sample_channel_map_from_tex2dformat(R_Tex2DFormat fmt); ////////////////////////////////