Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original "high resolution" support #217

Merged
merged 3 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/BRSRC13/CORE/DOSIO/dosio.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
br_pixelmap* DOSGfxBegin(char* setup_string) {
LOG_TRACE("(\"%s\")", setup_string);

Harness_Hook_DOSGfxBegin();
return BrPixelmapAllocate(BR_PMT_INDEX_8, 320, 200, NULL, BR_PMAF_NORMAL);
}
1 change: 0 additions & 1 deletion src/DETHRACE/common/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,6 @@ void RenderAFrame(int pDepth_mask_on) {
gBack_screen->base_y = 0;
if (gCurrent_race.map_image != NULL) {
if (gReal_graf_data_index) {
LOG_DEBUG("DOUBLING");
BrPixelmapRectangleFill(gBack_screen, 0, 0, 640, 40, 0);
BrPixelmapRectangleFill(gBack_screen, 0, 440, 640, 40, 0);
DRPixelmapDoubledCopy(
Expand Down
16 changes: 13 additions & 3 deletions src/DETHRACE/pc-dos/dossys.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,19 @@ void PDAllocateScreenAndBack() {
BrTableFindHook(PDMissingTable);
BrModelFindHook(PDMissingModel);
BrMapFindHook(PDMissingMap);
gScreen = DOSGfxBegin(gGraf_specs[gGraf_spec_index].gfx_init_string);

// This is a bit of a mix between the original DOS code and windows code...
// DOS:
// gScreen = DOSGfxBegin(gGraf_specs[gGraf_spec_index].gfx_init_string);
//
// Windows:
// SSDXInit(gGraf_specs[gGraf_spec_index].total_width, gGraf_specs[gGraf_spec_index].total_height)
// gScreen = BrPixelmapAllocate(BR_PMT_INDEX_8, ...)
//

Harness_Hook_GraphicsInit(gGraf_specs[gGraf_spec_index].total_width, gGraf_specs[gGraf_spec_index].total_height);
gScreen = BrPixelmapAllocate(BR_PMT_INDEX_8, gGraf_specs[gGraf_spec_index].total_width, gGraf_specs[gGraf_spec_index].total_height, NULL, BR_PMAF_NORMAL);

gScreen->origin_x = 0;
gDOSGfx_initialized = 1;
gScreen->origin_y = 0;
Expand Down Expand Up @@ -518,13 +530,11 @@ void PDSetPaletteEntries(br_pixelmap* pPalette, int pFirst_colour, int pCount) {
// IDA: void __cdecl PDSwitchToRealResolution()
void PDSwitchToRealResolution() {
LOG_TRACE("()");
NOT_IMPLEMENTED();
}

// IDA: void __cdecl PDSwitchToLoresMode()
void PDSwitchToLoresMode() {
LOG_TRACE("()");
NOT_IMPLEMENTED();
}

// IDA: void __usercall PDMouseButtons(int *pButton_1@<EAX>, int *pButton_2@<EDX>)
Expand Down
14 changes: 11 additions & 3 deletions src/harness/harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,24 @@ int Harness_ProcessCommandLine(int* argc, char* argv[]) {
return 0;
}

void Harness_Hook_DOSGfxBegin() {
void Harness_Hook_GraphicsInit(int render_width, int render_height) {
int window_width, window_height;
if (force_nullrenderer) {
return;
}
renderer = Window_Create("Dethrace", 640, 400, 320, 200);
if (render_width == 320) {
window_width = render_width * 2;
window_height = render_height * 2;
} else {
window_width = render_width;
window_height = render_height;
}
renderer = Window_Create("Dethrace", window_width, window_height, render_width, render_height);
}

// Render 2d back buffer
void Harness_RenderScreen(br_pixelmap* dst, br_pixelmap* src) {
renderer->FullScreenQuad((uint8_t*)src->pixels, 320, 200);
renderer->FullScreenQuad((uint8_t*)src->pixels);

last_dst = dst;
last_src = src;
Expand Down
2 changes: 1 addition & 1 deletion src/harness/include/harness/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ void Harness_Hook_PDServiceSystem();
void Harness_Hook_PDSetKeyArray();
// void Harness_Hook_MainGameLoop(); // limit FPS
void Harness_Hook_FlushRenderer(); // synchronize in-memory framebuffer and depthbuffer
void Harness_Hook_GraphicsInit(int render_width, int render_height);

// BRender hooks
void Harness_Hook_DOSGfxBegin();
void Harness_Hook_BrDevPaletteSetOld(br_pixelmap* pm);
void Harness_Hook_BrDevPaletteSetEntryOld(int i, br_colour colour);
void Harness_Hook_BrPixelmapDoubleBuffer(br_pixelmap* dst, br_pixelmap* src);
Expand Down
2 changes: 1 addition & 1 deletion src/harness/io_platforms/sdl_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ tRenderer* Window_Create(char* title, int width, int height, int pRender_width,
sdl_window_scale.x = ((float)pRender_width) / width;
sdl_window_scale.y = ((float)pRender_height) / height;

// SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
SDL_ShowCursor(SDL_DISABLE);

context = SDL_GL_CreateContext(window);
if (!context) {
Expand Down
4 changes: 2 additions & 2 deletions src/harness/renderers/gl/gl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void GLRenderer_EndScene() {
CHECK_GL_ERROR("GLRenderer_RenderFullScreenQuad");
}

void GLRenderer_FullScreenQuad(uint8_t* screen_buffer, int width, int height) {
void GLRenderer_FullScreenQuad(uint8_t* screen_buffer) {
glViewport(vp_x, vp_y, vp_width, vp_height);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDisable(GL_DEPTH_TEST);
Expand All @@ -370,7 +370,7 @@ void GLRenderer_FullScreenQuad(uint8_t* screen_buffer, int width, int height) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, screen_buffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, render_width, render_height, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, screen_buffer);
glBindVertexArray(screen_buffer_vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, screen_buffer_ebo);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
Expand Down
66 changes: 37 additions & 29 deletions src/harness/renderers/gl/gl_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,49 @@

#include "harness.h"


#define CHECK_GL_ERROR(msg) \
{ \
GLenum e = glGetError(); \
if (e != GL_NO_ERROR) { \
const char *err; \
switch (e) { \
case GL_NO_ERROR: \
err = "GL_NO_ERROR"; break; \
case GL_INVALID_ENUM: \
err = "GL_INVALID_ENUM"; break; \
case GL_INVALID_VALUE: \
err = "GL_INVALID_VALUE"; break; \
case GL_INVALID_OPERATION: \
err = "GL_INVALID_OPERATION"; break; \
case GL_INVALID_FRAMEBUFFER_OPERATION: \
err = "GL_INVALID_FRAMEBUFFER_OPERATION"; break; \
case GL_OUT_OF_MEMORY: \
err = "GL_OUT_OF_MEMORY"; break; \
case GL_STACK_UNDERFLOW: \
err = "GL_STACK_UNDERFLOW"; break; \
case GL_STACK_OVERFLOW: \
err = "GL_STACK_OVERFLOW"; break; \
default: \
err = "unknown"; break; \
} \
LOG_PANIC("glError %d (%s): %s", e, err, msg); \
} \
#define CHECK_GL_ERROR(msg) \
{ \
GLenum e = glGetError(); \
if (e != GL_NO_ERROR) { \
const char* err; \
switch (e) { \
case GL_NO_ERROR: \
err = "GL_NO_ERROR"; \
break; \
case GL_INVALID_ENUM: \
err = "GL_INVALID_ENUM"; \
break; \
case GL_INVALID_VALUE: \
err = "GL_INVALID_VALUE"; \
break; \
case GL_INVALID_OPERATION: \
err = "GL_INVALID_OPERATION"; \
break; \
case GL_INVALID_FRAMEBUFFER_OPERATION: \
err = "GL_INVALID_FRAMEBUFFER_OPERATION"; \
break; \
case GL_OUT_OF_MEMORY: \
err = "GL_OUT_OF_MEMORY"; \
break; \
case GL_STACK_UNDERFLOW: \
err = "GL_STACK_UNDERFLOW"; \
break; \
case GL_STACK_OVERFLOW: \
err = "GL_STACK_OVERFLOW"; \
break; \
default: \
err = "unknown"; \
break; \
} \
LOG_PANIC("glError %d (%s): %s", e, err, msg); \
} \
}

void GLRenderer_Init(int width, int height, int render_width, int render_height);
void GLRenderer_SetPalette(uint8_t* rgba_colors);
void GLRenderer_BeginScene(br_actor* camera, br_pixelmap* colour_buffer);
void GLRenderer_EndScene();
void GLRenderer_FullScreenQuad(uint8_t* screen_buffer, int width, int height);
void GLRenderer_FullScreenQuad(uint8_t* screen_buffer);
void GLRenderer_Model(br_actor* actor, br_model* model, br_matrix34 model_matrix);
void GLRenderer_BufferTexture(br_pixelmap* pm);
void GLRenderer_BufferMaterial(br_material* mat);
Expand Down
19 changes: 15 additions & 4 deletions src/harness/renderers/null.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ void Null_Init() {}
void Null_BeginFrame(br_actor* camera, br_pixelmap* colour_buffer) {}
void Null_EndFrame() {}
void Null_SetPalette(uint8_t* palette) {}
void Null_RenderFullScreenQuad(uint8_t* src, int width, int height) {}
void Null_RenderFullScreenQuad(uint8_t* src) {}
void Null_RenderModel(br_actor* actor, br_model* model, br_matrix34 model_matrix) {}
void Null_RenderFrameBuffer() {}
void Null_ClearBuffers() {}
void Null_BufferTexture(br_pixelmap* pm) {}
void Null_BufferMaterial(br_material* mat) {}
void Null_BufferModel(br_model* model) {}
void Null_FlushBuffers(br_pixelmap* color_buffer, br_pixelmap* depth_buffer) {}
void Null_GetRenderSize(int* width, int* height) { *width = 640; *height = 480; }
void Null_GetWindowSize(int* width, int* height) { *width = 640; *height = 480; }
void Null_GetRenderSize(int* width, int* height) {
*width = 640;
*height = 480;
}
void Null_GetWindowSize(int* width, int* height) {
*width = 640;
*height = 480;
}
void Null_SetWindowSize(int width, int height) {}
void Null_GetViewportSize(int* x, int* y, int* width, int* height) { *x = 0; *y = 0; *width = 640; *height = 480; }
void Null_GetViewportSize(int* x, int* y, int* width, int* height) {
*x = 0;
*y = 0;
*width = 640;
*height = 480;
}

tRenderer null_renderer = {
Null_Init,
Expand Down
2 changes: 1 addition & 1 deletion src/harness/renderers/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ typedef struct tRenderer {
void (*BeginScene)(br_actor* camera, br_pixelmap* colour_buffer);
void (*EndScene)();
void (*SetPalette)(uint8_t* palette);
void (*FullScreenQuad)(uint8_t* src, int width, int height);
void (*FullScreenQuad)(uint8_t* src);
void (*Model)(br_actor* actor, br_model* model, br_matrix34 model_matrix);
void (*ClearBuffers)();
void (*BufferTexture)(br_pixelmap* pm);
Expand Down