- Fixed crashing when D3D11 DEBUG flag fails in ID3D11CreateDevice, and instead log a descriptive error then continue as usual
- Stuff
This commit is contained in:
parent
c92b6fd4b7
commit
2a843fe7aa
16 changed files with 229 additions and 4874 deletions
5
build.c
5
build.c
|
@ -6,7 +6,6 @@
|
|||
// #Temporary
|
||||
#define RUN_TESTS 0
|
||||
#define OOGABOOGA_DEV 1
|
||||
#define ENABLE_PROFILING 1
|
||||
|
||||
#define INITIAL_PROGRAM_MEMORY_SIZE MB(5)
|
||||
|
||||
|
@ -35,7 +34,9 @@ typedef struct Context_Extra {
|
|||
|
||||
// #include "oogabooga/examples/text_rendering.c"
|
||||
// #include "oogabooga/examples/custom_logger.c"
|
||||
#include "oogabooga/examples/renderer_stress_test.c"
|
||||
// #include "oogabooga/examples/renderer_stress_test.c"
|
||||
// #include "oogabooga/examples/tile_game.c"
|
||||
#include "oogabooga/examples/audio_test.c"
|
||||
|
||||
// This is where you swap in your own project!
|
||||
// #include "entry_yourepicgamename.c"
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
## v0.00.005 - Z layers
|
||||
|
||||
Renderer:
|
||||
- Added optional Z-sorting
|
||||
- Either set quad->z or call push_z_layer(s64) (and pop_z_layer())
|
||||
- Enable with draw_frame.enable_z_sorting = true
|
||||
- Refactored the quad buffering to just be a growing quad buffer rather than a linked list of quad blocks. Your CPU will be thankful.
|
||||
- Fixed crashing when D3D11 DEBUG flag fails in ID3D11CreateDevice, and instead log a descriptive error then continue as usual
|
||||
|
||||
Misc:
|
||||
- removed gfx_impl_legacy_opengl.c
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define thread_local _Thread_local
|
||||
|
||||
#define local_persist static
|
||||
|
||||
#define forward_global extern
|
||||
|
||||
#define null 0
|
||||
|
||||
void printf(const char* fmt, ...);
|
||||
#define ASSERT_STR_HELPER(x) #x
|
||||
|
|
Binary file not shown.
BIN
oogabooga/examples/bruh.wav
Normal file
BIN
oogabooga/examples/bruh.wav
Normal file
Binary file not shown.
|
@ -11,8 +11,6 @@ int entry(int argc, char **argv) {
|
|||
while (!window.should_close) {
|
||||
reset_temporary_storage();
|
||||
|
||||
os_update();
|
||||
|
||||
float64 now = os_get_current_time_in_seconds();
|
||||
Matrix4 rect_xform = m4_scalar(1.0);
|
||||
rect_xform = m4_rotate_z(rect_xform, (f32)now);
|
||||
|
@ -21,6 +19,7 @@ int entry(int argc, char **argv) {
|
|||
|
||||
draw_rect(v2(sin(now), -.8), v2(.5, .25), COLOR_RED);
|
||||
|
||||
os_update();
|
||||
gfx_update();
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
BIN
oogabooga/examples/song.ogg
Normal file
BIN
oogabooga/examples/song.ogg
Normal file
Binary file not shown.
183
oogabooga/examples/tile_game.c
Normal file
183
oogabooga/examples/tile_game.c
Normal file
|
@ -0,0 +1,183 @@
|
|||
|
||||
|
||||
#define X_TILE_COUNT 128
|
||||
#define Y_TILE_COUNT 128
|
||||
|
||||
#define TILE_WIDTH 64
|
||||
#define TILE_HEIGHT 64
|
||||
#define TILE_COUNT (TILE_WIDTH * TILE_HEIGHT)
|
||||
|
||||
#define WORLD_WIDTH (X_TILE_COUNT * TILE_WIDTH)
|
||||
#define WORLD_HEIGHT (Y_TILE_COUNT * TILE_HEIGHT)
|
||||
|
||||
#define Z_LAYER_TILE_GRID -1
|
||||
#define Z_LAYER_TILE_LAYER_BASE 100
|
||||
|
||||
#define Z_LAYER_EDITOR_GUI 200
|
||||
|
||||
#define MAX_LAYERS 6
|
||||
|
||||
|
||||
typedef struct Tile_Layer {
|
||||
Gfx_Image *tile_images[TILE_COUNT];
|
||||
} Tile_Layer;
|
||||
Tile_Layer tile_layers[MAX_LAYERS] = {0};
|
||||
|
||||
u64 get_tile_index(s32 x, s32 y) {
|
||||
return y * X_TILE_COUNT + x;
|
||||
}
|
||||
u64 get_tile_index_from_pos(Vector2 p) {
|
||||
s32 x = (s32)((p.x/WORLD_WIDTH)*X_TILE_COUNT);
|
||||
s32 y = (s32)((p.y/WORLD_HEIGHT)*Y_TILE_COUNT);
|
||||
return get_tile_index(x, y);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
APP_STATE_EDITING,
|
||||
APP_STATE_PLAYING
|
||||
} App_State;
|
||||
|
||||
float32 delta_time = 0;
|
||||
App_State app_state = APP_STATE_EDITING;
|
||||
|
||||
s64 current_tile_layer = 0;
|
||||
|
||||
Matrix4 camera_view;
|
||||
|
||||
void update_editor();
|
||||
void update_game();
|
||||
|
||||
int entry(int argc, char **argv) {
|
||||
|
||||
window.title = STR("Tile game");
|
||||
window.scaled_width = 1280; // We need to set the scaled size if we want to handle system scaling (DPI)
|
||||
window.scaled_height = 720;
|
||||
window.x = 200;
|
||||
window.y = 90;
|
||||
window.clear_color = hex_to_rgba(0x6495EDff);
|
||||
|
||||
camera_view = m4_scalar(1.0);
|
||||
|
||||
float64 last_time = os_get_current_time_in_seconds();
|
||||
while (!window.should_close) {
|
||||
reset_temporary_storage();
|
||||
|
||||
draw_frame.projection = m4_make_orthographic_projection(window.pixel_width * -0.5, window.pixel_width * 0.5, window.pixel_height * -0.5, window.pixel_height * 0.5, -1, 10);
|
||||
draw_frame.enable_z_sorting = true;
|
||||
|
||||
float64 now = os_get_current_time_in_seconds();
|
||||
delta_time = (float32)(now - last_time);
|
||||
last_time = now;
|
||||
|
||||
if (app_state == APP_STATE_EDITING) {
|
||||
update_editor();
|
||||
} else if (app_state == APP_STATE_PLAYING) {
|
||||
update_game();
|
||||
}
|
||||
|
||||
os_update();
|
||||
gfx_update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vector2 screen_to_world(Vector2 screen) {
|
||||
Matrix4 proj = draw_frame.projection;
|
||||
Matrix4 view = draw_frame.view;
|
||||
float window_w = window.width;
|
||||
float window_h = window.height;
|
||||
|
||||
// Normalize the mouse coordinates
|
||||
float ndc_x = (screen.x / (window_w * 0.5f)) - 1.0f;
|
||||
float ndc_y = (screen.y / (window_h * 0.5f)) - 1.0f;
|
||||
|
||||
// Transform to world coordinates
|
||||
Vector4 world_pos = v4(ndc_x, ndc_y, 0, 1);
|
||||
world_pos = m4_transform(m4_inverse(proj), world_pos);
|
||||
world_pos = m4_transform(view, world_pos);
|
||||
|
||||
return world_pos.xy;
|
||||
}
|
||||
|
||||
Vector2 get_mouse_world_pos() {
|
||||
return screen_to_world(v2(input_frame.mouse_x, input_frame.mouse_y));
|
||||
}
|
||||
|
||||
void update_editor() {
|
||||
|
||||
const float32 cam_move_speed = 400.0;
|
||||
Vector2 cam_move_axis = v2(0, 0);
|
||||
if (is_key_down('A')) {
|
||||
cam_move_axis.x -= 1.0;
|
||||
}
|
||||
if (is_key_down('D')) {
|
||||
cam_move_axis.x += 1.0;
|
||||
}
|
||||
if (is_key_down('S')) {
|
||||
cam_move_axis.y -= 1.0;
|
||||
}
|
||||
if (is_key_down('W')) {
|
||||
cam_move_axis.y += 1.0;
|
||||
}
|
||||
|
||||
Vector2 cam_move = v2_mulf(cam_move_axis, delta_time * cam_move_speed);
|
||||
camera_view = m4_translate(camera_view, v3(v2_expand(cam_move), 0));
|
||||
draw_frame.view = camera_view;
|
||||
|
||||
Vector2 bottom_left = screen_to_world(v2(-window.width/2, -window.height/2));
|
||||
Vector2 top_right = screen_to_world(v2( window.width/2, window.height/2));
|
||||
|
||||
Vector2 origin = v2(-WORLD_WIDTH/2, -WORLD_HEIGHT/2);
|
||||
int first_visible_tile_x = ((origin.x + bottom_left.x)/WORLD_WIDTH) *X_TILE_COUNT;
|
||||
int first_visible_tile_y = ((origin.y + bottom_left.y)/WORLD_HEIGHT)*Y_TILE_COUNT;
|
||||
int last_visible_tile_x = ((origin.x + top_right.x )/WORLD_WIDTH) *X_TILE_COUNT;
|
||||
int last_visible_tile_y = ((origin.y + top_right.y )/WORLD_HEIGHT)*Y_TILE_COUNT;
|
||||
|
||||
// Visualize empty tile grid & react to mouse
|
||||
push_z_layer(Z_LAYER_TILE_GRID);
|
||||
|
||||
for (s32 tile_x = first_visible_tile_x; tile_x <= last_visible_tile_x; tile_x += 1) {
|
||||
for (s32 tile_y = first_visible_tile_y; tile_y <=last_visible_tile_y; tile_y += 1) {
|
||||
bool variation = (tile_x%2==0 && tile_y%2==1) || (tile_x%2==1 && tile_y%2==0);
|
||||
|
||||
Vector2 pos = v2_add(origin, v2(tile_x*TILE_WIDTH, tile_y*TILE_HEIGHT));
|
||||
draw_rect(pos, v2(TILE_WIDTH, TILE_HEIGHT), variation?v4(.27,.27,.27,1):v4(.3,.3,.3,1));
|
||||
|
||||
push_z_layer(Z_LAYER_EDITOR_GUI);
|
||||
|
||||
float left = pos.x;
|
||||
float bottom = pos.y;
|
||||
float right = left + TILE_WIDTH;
|
||||
float top = bottom + TILE_HEIGHT;
|
||||
Vector2 m = get_mouse_world_pos();
|
||||
bool hovered = m.x >= left && m.x < right && m.y >= bottom && m.y < top;
|
||||
|
||||
if (hovered) {
|
||||
draw_rect(pos, v2(TILE_WIDTH, TILE_HEIGHT), v4(0, 0, 0, 0.3));
|
||||
}
|
||||
|
||||
pop_z_layer();
|
||||
}
|
||||
}
|
||||
pop_z_layer();
|
||||
|
||||
for (int i = 0; i < MAX_LAYERS; i++) {
|
||||
Tile_Layer *layer = &tile_layers[i];
|
||||
push_z_layer(Z_LAYER_TILE_LAYER_BASE + i);
|
||||
Vector2 origin = v2(-WORLD_WIDTH/2, -WORLD_HEIGHT/2);
|
||||
for (s32 tile_x = first_visible_tile_x; tile_x <= last_visible_tile_x; tile_x += 1) {
|
||||
for (s32 tile_y = first_visible_tile_y; tile_y <=last_visible_tile_y; tile_y += 1) {
|
||||
Gfx_Image *img = layer->tile_images[get_tile_index(tile_x, tile_y)];
|
||||
if (img) {
|
||||
Vector2 pos = v2_add(origin, v2(tile_x*TILE_WIDTH, tile_y*TILE_HEIGHT));
|
||||
draw_image(img, pos, v2(TILE_WIDTH, TILE_HEIGHT), COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
pop_z_layer();
|
||||
}
|
||||
}
|
||||
void update_game() {
|
||||
|
||||
}
|
Binary file not shown.
|
@ -272,22 +272,38 @@ void gfx_init() {
|
|||
};
|
||||
s64 num_feature_levels = sizeof(feature_levels)/sizeof(D3D_FEATURE_LEVEL);
|
||||
|
||||
for (s64 i = 0; i < num_drivers; i++) {
|
||||
d3d11_driver_type = driver_types[i];
|
||||
bool debug_failed = false;
|
||||
|
||||
hr = D3D11CreateDevice(0, d3d11_driver_type, 0, flags, feature_levels, num_feature_levels, D3D11_SDK_VERSION, &d3d11_device, &d3d11_feature_level, &d3d11_context);
|
||||
for (s64 i = 0; i < 2; i++) {
|
||||
for (s64 i = 0; i < num_drivers; i++) {
|
||||
d3d11_driver_type = driver_types[i];
|
||||
|
||||
if (hr == E_INVALIDARG) {
|
||||
// 11_1 not recognized in 11.0
|
||||
hr = D3D11CreateDevice(0, d3d11_driver_type, 0, flags, feature_levels+1, num_feature_levels-1, D3D11_SDK_VERSION, &d3d11_device, &d3d11_feature_level, &d3d11_context);
|
||||
hr = D3D11CreateDevice(0, d3d11_driver_type, 0, flags, feature_levels, num_feature_levels, D3D11_SDK_VERSION, &d3d11_device, &d3d11_feature_level, &d3d11_context);
|
||||
|
||||
if (hr == E_INVALIDARG) {
|
||||
// 11_1 not recognized in 11.0
|
||||
hr = D3D11CreateDevice(0, d3d11_driver_type, 0, flags, feature_levels+1, num_feature_levels-1, D3D11_SDK_VERSION, &d3d11_device, &d3d11_feature_level, &d3d11_context);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr)) break;
|
||||
|
||||
log_verbose("Failed driver type number %d (%d)", i, driver_types[i]);
|
||||
}
|
||||
if (SUCCEEDED(hr)) {
|
||||
break;
|
||||
} else {
|
||||
debug_failed = true;
|
||||
flags &= ~(D3D11_CREATE_DEVICE_DEBUG);
|
||||
|
||||
if (SUCCEEDED(hr)) break;
|
||||
|
||||
log_verbose("Failed driver type number %d (%d)", i, driver_types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
win32_check_hr(hr);
|
||||
|
||||
if (debug_failed) {
|
||||
log_error("We could not init D3D11 with DEBUG flag. This is likely because you have not enabled \"Graphics Tools\" in windows settings. https://github.com/microsoft/DirectX-Graphics-Samples/issues/447#issuecomment-415611443");
|
||||
}
|
||||
|
||||
assert(d3d11_device != 0, "D3D11CreateDevice failed");
|
||||
|
||||
#if CONFIGURATION == DEBUG
|
||||
|
|
|
@ -111,7 +111,11 @@
|
|||
|
||||
#define OGB_VERSION (OGB_VERSION_MAJOR*1000000+OGB_VERSION_MINOR*1000+OGB_VERSION_PATCH)
|
||||
|
||||
#include <math.h>
|
||||
#include <immintrin.h>
|
||||
#include <intrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
|
@ -234,8 +238,6 @@ typedef u8 bool;
|
|||
// Dependencies
|
||||
///
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "third_party.c"
|
||||
|
||||
/////
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
|
||||
|
||||
// #Cleanup we only need vsnprintf
|
||||
typedef void* (__cdecl *Crt_Memcpy_Proc) (void*, const void*, size_t);
|
||||
typedef int (__cdecl *Crt_Memcmp_Proc) (const void*, const void*, size_t);
|
||||
typedef void* (__cdecl *Crt_Memset_Proc) (void*, int, size_t);
|
||||
|
@ -45,6 +46,7 @@ typedef struct Os_Info {
|
|||
|
||||
Dynamic_Library_Handle crt;
|
||||
|
||||
// #Cleanup we only need vsnprintf
|
||||
Crt_Memcpy_Proc crt_memcpy;
|
||||
Crt_Memcmp_Proc crt_memcmp;
|
||||
Crt_Memset_Proc crt_memset;
|
||||
|
@ -144,6 +146,7 @@ void os_high_precision_sleep(f64 ms);
|
|||
// Time
|
||||
///
|
||||
|
||||
// #Cleanup getting the cycle count is an x86 intrinsic so this should be in cpu.c
|
||||
u64 os_get_current_cycle_count();
|
||||
float64 os_get_current_time_in_seconds();
|
||||
|
||||
|
|
|
@ -49,17 +49,9 @@ size_t stbtt_strlen(const char* str) {
|
|||
#undef C
|
||||
#undef L
|
||||
|
||||
#define DR_MP3_NO_STDIO
|
||||
#define DRMP3_ASSERT(exp) assert(exp, "dr_mp3 assertion failed")
|
||||
#define DRMP3_MALLOC(sz) third_party_malloc(sz)
|
||||
#define DRMP3_REALLOC(p,newsz) third_party_allocator.proc(newsz, p, ALLOCATOR_REALLOCATE, 0)
|
||||
#define DRMP3_FREE(p) third_party_free(p)
|
||||
#define DR_MP3_IMPLEMENTATION
|
||||
#include "third_party/dr_mp3.h"
|
||||
|
||||
#define DR_WAV_NO_STDIO
|
||||
#define DR_WAV_NO_WCHAR
|
||||
#define DRWAV_ASSERT(exp) assert(exp, "dr_mp3 assertion failed")
|
||||
#define DRWAV_ASSERT(exp) assert(exp, "dr_wav assertion failed")
|
||||
#define DRWAV_MALLOC(sz) third_party_malloc(sz)
|
||||
#define DRWAV_REALLOC(p,newsz) third_party_allocator.proc(newsz, p, ALLOCATOR_REALLOCATE, 0)
|
||||
#define DRWAV_FREE(p) third_party_free(p)
|
||||
|
|
4838
oogabooga/third_party/dr_mp3.h
vendored
4838
oogabooga/third_party/dr_mp3.h
vendored
File diff suppressed because it is too large
Load diff
2
oogabooga/third_party/stb_vorbis.c
vendored
2
oogabooga/third_party/stb_vorbis.c
vendored
|
@ -984,7 +984,7 @@ static void setup_temp_free(vorb *f, void *p, int sz)
|
|||
f->temp_offset += (sz+7)&~7;
|
||||
return;
|
||||
}
|
||||
free(p);
|
||||
third_party_free(p); // #Modified malloc -> third_party_malloc Charlie Malmqvist 2024-07-11
|
||||
}
|
||||
|
||||
#define CRC32_POLY 0x04c11db7 // from spec
|
||||
|
|
Reference in a new issue