Convert renderer to use new logging facility

This commit is contained in:
Azamat H. Hackimov 2024-08-20 04:19:09 +03:00
parent c32c2d3db3
commit d8de33eb35
5 changed files with 47 additions and 42 deletions

View File

@ -35,6 +35,7 @@ target_include_directories(renderer PRIVATE ${GENERATED_HEADERS})
target_link_libraries(renderer PRIVATE target_link_libraries(renderer PRIVATE
glm::glm glm::glm
SDL2::SDL2 SDL2::SDL2
plog::plog
bitmap bitmap
ddio ddio
mem mem

View File

@ -22,6 +22,7 @@
#include <cstring> #include <cstring>
#include "pserror.h" #include "pserror.h"
#include "log.h"
#include "mono.h" #include "mono.h"
#include "3d.h" #include "3d.h"
#include "renderer.h" #include "renderer.h"
@ -362,7 +363,7 @@ int rend_SetPreferredState(renderer_preferred_state *pref_state) {
gpu_preferred_state = *pref_state; gpu_preferred_state = *pref_state;
if (gpu_state.initted) { if (gpu_state.initted) {
int reinit = 0; int reinit = 0;
mprintf(0, "Inside pref state!\n"); LOG_DEBUG << "Inside pref state!";
// Change gamma if needed // Change gamma if needed
if (pref_state->width != gpu_state.screen_width || pref_state->height != gpu_state.screen_height || if (pref_state->width != gpu_state.screen_width || pref_state->height != gpu_state.screen_height ||

View File

@ -19,6 +19,7 @@
#include "pserror.h" #include "pserror.h"
#include "3d.h" #include "3d.h"
#include "HardwareInternal.h" #include "HardwareInternal.h"
#include "log.h"
static int free_point_num = -1; static int free_point_num = -1;
static g3Point temp_points[MAX_POINTS_IN_POLY]; static g3Point temp_points[MAX_POINTS_IN_POLY];
@ -44,7 +45,7 @@ g3Point *GetTempPoint(void) {
void FreeTempPoint(g3Point *p) { void FreeTempPoint(g3Point *p) {
if (free_point_num < 1) { if (free_point_num < 1) {
mprintf(1, "clipper: no temp points to free\n"); LOG_FATAL << "clipper: no temp points to free";
free_point_num = 1; free_point_num = 1;
Int3(); Int3();
} }
@ -349,7 +350,7 @@ g3Point **g3_ClipPolygon(g3Point **pointlist, int *nv, g3Codes *cc) {
//& ASSERT(free_point_num == 0); //DAJ UTB CMO //& ASSERT(free_point_num == 0); //DAJ UTB CMO
if (free_point_num != 0) { if (free_point_num != 0) {
mprintf(1, "clipper: leftover temp point\n"); LOG_FATAL << "clipper: leftover temp point";
free_point_num = 0; free_point_num = 0;
Int3(); Int3();
} }

View File

@ -39,6 +39,7 @@
#include "application.h" #include "application.h"
#include "bitmap.h" #include "bitmap.h"
#include "lightmap.h" #include "lightmap.h"
#include "log.h"
#include "rend_opengl.h" #include "rend_opengl.h"
#include "grdefs.h" #include "grdefs.h"
#include "mem.h" #include "mem.h"
@ -237,9 +238,9 @@ bool opengl_CheckExtension(std::string_view extName) {
// Gets some specific information about this particular flavor of opengl // Gets some specific information about this particular flavor of opengl
void opengl_GetInformation() { void opengl_GetInformation() {
mprintf(0, "OpenGL Vendor: %s\n", dglGetString(GL_VENDOR)); LOG_INFO.printf("OpenGL Vendor: %s", dglGetString(GL_VENDOR));
mprintf(0, "OpenGL Renderer: %s\n", dglGetString(GL_RENDERER)); LOG_INFO.printf("OpenGL Renderer: %s", dglGetString(GL_RENDERER));
mprintf(0, "OpenGL Version: %s\n", dglGetString(GL_VERSION)); LOG_INFO.printf("OpenGL Version: %s", dglGetString(GL_VERSION));
} }
int opengl_MakeTextureObject(int tn) { int opengl_MakeTextureObject(int tn) {
@ -299,7 +300,7 @@ int opengl_InitCache() {
// Sets default states for our renderer // Sets default states for our renderer
void opengl_SetDefaults() { void opengl_SetDefaults() {
mprintf(0, "Setting states\n"); LOG_INFO << "Setting states";
gpu_state.cur_color = 0x00FFFFFF; gpu_state.cur_color = 0x00FFFFFF;
gpu_state.cur_bilinear_state = -1; gpu_state.cur_bilinear_state = -1;
@ -425,7 +426,7 @@ int opengl_Setup(oeApplication *app, const int *width, const int *height) {
if (!GSDLWindow) { if (!GSDLWindow) {
GSDLWindow = SDL_CreateWindow("Descent 3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winw, winh, flags); GSDLWindow = SDL_CreateWindow("Descent 3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winw, winh, flags);
if (!GSDLWindow) { if (!GSDLWindow) {
mprintf(0, "OpenGL: SDL window creation failed: %s", SDL_GetError()); LOG_ERROR.printf("OpenGL: SDL window creation failed: %s", SDL_GetError());
return 0; return 0;
} }
} else { } else {
@ -436,7 +437,7 @@ int opengl_Setup(oeApplication *app, const int *width, const int *height) {
if (!GSDLGLContext) { if (!GSDLGLContext) {
GSDLGLContext = SDL_GL_CreateContext(GSDLWindow); GSDLGLContext = SDL_GL_CreateContext(GSDLWindow);
if (!GSDLGLContext) { if (!GSDLGLContext) {
mprintf(0, "OpenGL: OpenGL context creation failed: %s", SDL_GetError()); LOG_ERROR.printf("OpenGL: OpenGL context creation failed: %s", SDL_GetError());
SDL_DestroyWindow(GSDLWindow); SDL_DestroyWindow(GSDLWindow);
GSDLWindow = nullptr; GSDLWindow = nullptr;
return 0; return 0;
@ -451,7 +452,7 @@ int opengl_Setup(oeApplication *app, const int *width, const int *height) {
GSDLGLContext = nullptr; GSDLGLContext = nullptr;
SDL_DestroyWindow(GSDLWindow); SDL_DestroyWindow(GSDLWindow);
GSDLWindow = nullptr; GSDLWindow = nullptr;
mprintf(0, "Error loading opengl dll: %s\n", ex.what()); LOG_ERROR.printf("Error loading opengl dll: %s", ex.what());
mod_FreeModule(&OpenGLDLLInst); mod_FreeModule(&OpenGLDLLInst);
OpenGLDLLHandle = nullptr; OpenGLDLLHandle = nullptr;
return 0; return 0;
@ -495,20 +496,20 @@ int opengl_Setup(oeApplication *app, const int *width, const int *height) {
dglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, GOpenGLRBODepth); dglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, GOpenGLRBODepth);
if (dglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) { if (dglCheckFramebufferStatus(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
mprintf(0, "OpenGL: our framebuffer object is incomplete, giving up"); LOG_WARNING << "OpenGL: our framebuffer object is incomplete, giving up";
dglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0); dglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
dglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); dglFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
dglBindRenderbuffer(GL_RENDERBUFFER, 0); dglBindRenderbuffer(GL_RENDERBUFFER, 0);
dglBindFramebuffer(GL_FRAMEBUFFER, 0); dglBindFramebuffer(GL_FRAMEBUFFER, 0);
dglDeleteFramebuffers(1, &GOpenGLFBO); dglDeleteFramebuffers(1, &GOpenGLFBO);
dglDeleteRenderbuffers(1, &GOpenGLRBOColor); dglDeleteRenderbuffers(1, &GOpenGLRBOColor);
dglDeleteRenderbuffers(1, &GOpenGLRBODepth); dglDeleteRenderbuffers(1, &GOpenGLRBODepth);
GOpenGLFBO = GOpenGLRBOColor = GOpenGLRBODepth = 0; GOpenGLFBO = GOpenGLRBOColor = GOpenGLRBODepth = 0;
SDL_GL_DeleteContext(GSDLGLContext); SDL_GL_DeleteContext(GSDLGLContext);
SDL_DestroyWindow(GSDLWindow); SDL_DestroyWindow(GSDLWindow);
GSDLGLContext = nullptr; GSDLGLContext = nullptr;
GSDLWindow = nullptr; GSDLWindow = nullptr;
return 0; return 0;
} }
// rcg09182000 gamma fun. // rcg09182000 gamma fun.
@ -536,7 +537,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
int retval = 1; int retval = 1;
int i; int i;
mprintf(0, "Setting up opengl mode!\n"); LOG_INFO << "Setting up opengl mode!";
if (pref_state) { if (pref_state) {
gpu_preferred_state = *pref_state; gpu_preferred_state = *pref_state;
@ -580,7 +581,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
ASSERT(opengl_packed_Translate_table); ASSERT(opengl_packed_Translate_table);
ASSERT(opengl_packed_4444_translate_table); ASSERT(opengl_packed_4444_translate_table);
mprintf(0, "Building packed OpenGL translate table...\n"); LOG_INFO << "Building packed OpenGL translate table...";
for (i = 0; i < 65536; i++) { for (i = 0; i < 65536; i++) {
int r = (i >> 10) & 0x1f; int r = (i >> 10) & 0x1f;
@ -627,7 +628,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
ASSERT(opengl_Translate_table); ASSERT(opengl_Translate_table);
ASSERT(opengl_4444_translate_table); ASSERT(opengl_4444_translate_table);
mprintf(0, "Building OpenGL translate table...\n"); LOG_INFO << "Building OpenGL translate table...";
for (i = 0; i < 65536; i++) { for (i = 0; i < 65536; i++) {
uint32_t pix; uint32_t pix;
@ -693,7 +694,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
gpu_state.initted = 1; gpu_state.initted = 1;
mprintf(0, "OpenGL initialization at %d x %d was successful.\n", width, height); LOG_INFO.printf("OpenGL initialization at %d x %d was successful.", width, height);
return retval; return retval;
} }
@ -962,7 +963,7 @@ int opengl_MakeBitmapCurrent(int handle, int map_type, int tn) {
} }
if (w != h) { if (w != h) {
mprintf(0, "Can't use non-square textures with OpenGL!\n"); LOG_WARNING << "Can't use non-square textures with OpenGL!";
return 0; return 0;
} }
@ -1130,7 +1131,7 @@ void gpu_DrawFlatPolygon3D(g3Point **p, int nv) {
// Sets the gamma correction value // Sets the gamma correction value
void rend_SetGammaValue(float val) { void rend_SetGammaValue(float val) {
gpu_preferred_state.gamma = val; gpu_preferred_state.gamma = val;
mprintf(0, "Setting gamma to %f\n", val); LOG_DEBUG.printf("Setting gamma to %f", val);
} }
// Resets the texture cache // Resets the texture cache
@ -1259,7 +1260,7 @@ int rend_Init(renderer_type state, oeApplication *app, renderer_preferred_state
Renderer_initted = 1; Renderer_initted = 1;
} }
mprintf(0, "Renderer init is set to %d\n", Renderer_initted); LOG_DEBUG.printf("Renderer init is set to %d", Renderer_initted);
#ifndef OEM_V3 #ifndef OEM_V3
retval = opengl_Init(app, pref_state); retval = opengl_Init(app, pref_state);
@ -1271,7 +1272,7 @@ int rend_Init(renderer_type state, oeApplication *app, renderer_preferred_state
} }
void rend_Close() { void rend_Close() {
mprintf(0, "CLOSE:Renderer init is set to %d\n", Renderer_initted); LOG_DEBUG.printf("CLOSE: Renderer init is set to %d", Renderer_initted);
if (!Renderer_initted) if (!Renderer_initted)
return; return;
@ -1330,7 +1331,7 @@ void rend_SetFogBorders(float nearz, float farz) {
void rend_SetRendererType(renderer_type state) { void rend_SetRendererType(renderer_type state) {
Renderer_type = state; Renderer_type = state;
mprintf(0, "RendererType is set to %d.\n", state); LOG_DEBUG.printf("RendererType is set to %d.", state);
} }
void rend_SetLighting(light_state state) { void rend_SetLighting(light_state state) {
@ -1421,10 +1422,10 @@ void rend_Flip() {
RTP_INCRVALUE(texture_uploads, OpenGL_uploads); RTP_INCRVALUE(texture_uploads, OpenGL_uploads);
RTP_INCRVALUE(polys_drawn, OpenGL_polys_drawn); RTP_INCRVALUE(polys_drawn, OpenGL_polys_drawn);
mprintf_at(1, 1, 0, "Uploads=%d Polys=%d Verts=%d ", OpenGL_uploads, OpenGL_polys_drawn, OpenGL_verts_processed); LOG_VERBOSE.printf("Uploads=%d Polys=%d Verts=%d", OpenGL_uploads, OpenGL_polys_drawn, OpenGL_verts_processed);
mprintf_at(1, 2, 0, "Sets= 0:%d 1:%d 2:%d 3:%d ", OpenGL_sets_this_frame[0], OpenGL_sets_this_frame[1], LOG_VERBOSE.printf("Sets= 0:%d 1:%d 2:%d 3:%d", OpenGL_sets_this_frame[0], OpenGL_sets_this_frame[1],
OpenGL_sets_this_frame[2], OpenGL_sets_this_frame[3]); OpenGL_sets_this_frame[2], OpenGL_sets_this_frame[3]);
mprintf_at(1, 3, 0, "Sets= 4:%d 5:%d ", OpenGL_sets_this_frame[4], OpenGL_sets_this_frame[5]); LOG_VERBOSE.printf("Sets= 4:%d 5:%d", OpenGL_sets_this_frame[4], OpenGL_sets_this_frame[5]);
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
OpenGL_sets_this_frame[i] = 0; OpenGL_sets_this_frame[i] = 0;
} }
@ -1512,7 +1513,7 @@ void rend_ClearZBuffer() { dglClear(GL_DEPTH_BUFFER_BIT); }
// Clears the zbuffer for the screen // Clears the zbuffer for the screen
void rend_ResetCache() { void rend_ResetCache() {
mprintf(0, "Resetting texture cache!\n"); LOG_DEBUG << "Resetting texture cache!";
opengl_ResetCache(); opengl_ResetCache();
} }
@ -1777,7 +1778,7 @@ int rend_InitOpenGLWindow(oeApplication *app, renderer_preferred_state *pref_sta
// Shuts down OpenGL in a window // Shuts down OpenGL in a window
void rend_CloseOpenGLWindow() { void rend_CloseOpenGLWindow() {
opengl_Close(); opengl_Close();
mprintf(1, "SHUTTING DOWN WINDOWED OPENGL!"); LOG_DEBUG << "SHUTTING DOWN WINDOWED OPENGL!";
} }
// Sets the hardware bias level for coplanar polygons // Sets the hardware bias level for coplanar polygons

View File

@ -28,6 +28,7 @@
#include <SDL_opengl.h> #include <SDL_opengl.h>
#include "descent.h" #include "descent.h"
#include "log.h"
#include "module.h" #include "module.h"
#include "pserror.h" #include "pserror.h"
@ -104,19 +105,19 @@ FnPtr<Ret(Args...)>::FnPtr(std::string_view name, bool optional) : fn_{} {
} }
static module *LoadOpenGLDLL(const char *dllname) { static module *LoadOpenGLDLL(const char *dllname) {
mprintf(0, "Loading OpenGL dll...\n"); LOG_INFO << "Loading OpenGL dll...";
int rc = SDL_GL_LoadLibrary(dllname[0] ? dllname : nullptr); int rc = SDL_GL_LoadLibrary(dllname[0] ? dllname : nullptr);
if (rc < 0) { if (rc < 0) {
const char *sdlErr = SDL_GetError(); const char *sdlErr = SDL_GetError();
mprintf(0, "OpenGL: Couldn't open library [%s].\n", dllname[0] ? dllname : "system default"); LOG_ERROR.printf("OpenGL: Couldn't open library [%s]: SDL error [%s].",
mprintf(0, "OpenGL: SDL error is [%s].", sdlErr); dllname[0] ? dllname : "system default", sdlErr);
return NULL; return NULL;
} }
strcpy(loadedLibrary, dllname); strcpy(loadedLibrary, dllname);
mprintf(0, "OpenGL dll loading successful.\n"); LOG_INFO << "OpenGL dll loading successful.";
return &OpenGLDLLInst; return &OpenGLDLLInst;
} }