diff --git a/CMakeLists.txt b/CMakeLists.txt index 32963ac0..281faa7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,9 +237,11 @@ if (WITH_CLIENT) file(GLOB_RECURSE SOURCES_CLIENT "code/client/*.c" "code/client/*.cpp" "code/qcommon/puff.c") file(GLOB_RECURSE SOURCES_UILIB "code/uilib/*.c" "code/uilib/*.cpp") + include("code/renderergl2/glsl/shaders.cmake") #file(GLOB_RECURSE SOURCES_RENDERER "code/sdl/*.c" "code/renderer/*.c" "code/renderer/*.cpp") file(GLOB_RECURSE SOURCES_RENDERER "code/sdl/*.c" "code/renderercommon/*.c" "code/renderergl2/*.c" "code/renderergl2/*.cpp") - set(SOURCES_CLIENT_APP ${SOURCES_APP} ${SOURCES_SERVER} ${SOURCES_CLIENT} ${SOURCES_UILIB} ${SOURCES_LIBS} ${SOURCES_RENDERER}) + list(FILTER SOURCES_RENDERER EXCLUDE REGEX "(.*)/tr_subs.c") + set(SOURCES_CLIENT_APP ${SOURCES_APP} ${SOURCES_SERVER} ${SOURCES_CLIENT} ${SOURCES_UILIB} ${SOURCES_LIBS} ${SOURCES_RENDERER} ${SHADER_SRCS}) add_executable(openmohaa ${SOURCES_PLATFORM_SPECIFIC} ${SOURCES_CLIENT_APP} ${SOURCES_CLIENT_PLATFORM_SPECIFIC}) target_compile_definitions(openmohaa PRIVATE NO_SCRIPTENGINE APP_MODULE TARGET_GAME_TYPE=${TARGET_GAME_TYPE}) @@ -268,11 +270,6 @@ if (WITH_CLIENT) set_target_properties(sdl2main PROPERTIES IMPORTED_IMPLIB "${CMAKE_SOURCE_DIR}/code/libs/win64/SDL264main.lib" ) - - add_library(glew32 SHARED IMPORTED) - set_target_properties(glew32 PROPERTIES - IMPORTED_IMPLIB "${CMAKE_SOURCE_DIR}/code/libs/win64/glew32.lib" - ) else() add_library(sdl2 SHARED IMPORTED) set_target_properties(sdl2 PROPERTIES @@ -283,14 +280,9 @@ if (WITH_CLIENT) set_target_properties(sdl2main PROPERTIES IMPORTED_IMPLIB "${CMAKE_SOURCE_DIR}/code/libs/win32/SDL2main.lib" ) - - add_library(glew32 SHARED IMPORTED) - set_target_properties(glew32 PROPERTIES - IMPORTED_IMPLIB "${CMAKE_SOURCE_DIR}/code/libs/win32/glew32.lib" - ) endif() - target_link_libraries(openmohaa PRIVATE opengl32 sdl2 sdl2main glew32) + target_link_libraries(openmohaa PRIVATE sdl2 sdl2main) endif() target_link_libraries(openmohaa PRIVATE wsock32 ws2_32) diff --git a/code/cgame/cg_public.h b/code/cgame/cg_public.h index 77202b2e..55290315 100644 --- a/code/cgame/cg_public.h +++ b/code/cgame/cg_public.h @@ -131,12 +131,12 @@ typedef struct char * (*Args)( void ); // concatenation of all argv >= 1 void (*AddCommand)( const char *cmd ); void (*Cmd_Stuff)(const char* text); - void (*Cmd_Execute)(cbufExec_t execWhen, const char* text); + void (*Cmd_Execute)(int execWhen, const char* text); void (*Cmd_TokenizeString)(const char* textIn); // a -1 return means the file does not exist // NULL can be passed for buf to just determine existance - int (*FS_ReadFile)( const char *name, void **buf, qboolean quiet ); + long (*FS_ReadFile)( const char *name, void **buf, qboolean quiet ); void (*FS_FreeFile)( void *buf ); int (*FS_WriteFile)( const char *qpath, const void *buffer, int size ); void (*FS_WriteTextFile)( const char *qpath, const void *buffer, int size ); diff --git a/code/cgame/tr_types.h b/code/cgame/tr_types.h index e315f521..7da8997e 100644 --- a/code/cgame/tr_types.h +++ b/code/cgame/tr_types.h @@ -23,9 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // DESCRIPTION: // Renderer types -#ifndef __TR_TYPES_H -#define __TR_TYPES_H - +#pragma once #define MAX_DLIGHTS 32 // can't be increased, because bit flags are used on surfaces #define MAX_ENTITIES 1023 // can't be increased without changing drawsurf bit packing @@ -271,6 +269,3 @@ typedef struct { #define OPENGL_DRIVER_NAME "opengl32" #endif // !defined _WIN32 - - -#endif // __TR_TYPES_H diff --git a/code/client/cl_cgame.cpp b/code/client/cl_cgame.cpp index 8c2ec2d1..6e51a078 100644 --- a/code/client/cl_cgame.cpp +++ b/code/client/cl_cgame.cpp @@ -480,8 +480,8 @@ void CL_ShutdownCGame( void ) { Sys_UnloadCGame(); - if( re.FreeModels ) { - re.FreeModels(); + if( re.newre.FreeModels ) { + re.newre.FreeModels(); } Z_FreeTags( TAG_CGAME ); @@ -586,12 +586,12 @@ void CL_InitCGameDLL( clientGameImport_t *cgi, clientGameExport_t **cge ) { cgi->CM_PointLeafnum = CM_PointLeafnum; cgi->CM_LeafInPVS = CM_LeafInPVS; - cgi->R_MarkFragments = re.MarkFragments; - cgi->R_MarkFragmentsForInlineModel = re.MarkFragmentsForInlineModel; - cgi->R_GetInlineModelBounds = re.GetInlineModelBounds; - cgi->R_GetLightingForDecal = re.GetLightingForDecal; - cgi->R_GetLightingForSmoke = re.GetLightingForSmoke; - cgi->R_GatherLightSources = re.R_GatherLightSources; + cgi->R_MarkFragments = re.newre.MarkFragments; + cgi->R_MarkFragmentsForInlineModel = re.newre.MarkFragmentsForInlineModel; + cgi->R_GetInlineModelBounds = re.newre.GetInlineModelBounds; + cgi->R_GetLightingForDecal = re.newre.GetLightingForDecal; + cgi->R_GetLightingForSmoke = re.newre.GetLightingForSmoke; + cgi->R_GatherLightSources = re.newre.R_GatherLightSources; cgi->S_StartSound = S_StartSound; cgi->S_StartLocalSound = CL_StartLocalSound; @@ -620,39 +620,39 @@ void CL_InitCGameDLL( clientGameImport_t *cgi, clientGameExport_t **cge ) { cgi->R_RenderScene = re.RenderScene; cgi->R_LoadWorldMap = re.LoadWorld; - cgi->R_PrintBSPFileSizes = re.PrintBSPFileSizes; - cgi->R_MapVersion = re.MapVersion; + cgi->R_PrintBSPFileSizes = re.newre.PrintBSPFileSizes; + cgi->R_MapVersion = re.newre.MapVersion; cgi->R_RegisterModel = re.RegisterModel; - cgi->R_SpawnEffectModel = re.SpawnEffectModel; - cgi->R_RegisterServerModel = re.RegisterServerModel; - cgi->R_UnregisterServerModel = re.UnregisterServerModel; + cgi->R_SpawnEffectModel = re.newre.SpawnEffectModel; + cgi->R_RegisterServerModel = re.newre.RegisterServerModel; + cgi->R_UnregisterServerModel = re.newre.UnregisterServerModel; cgi->R_RegisterShader = re.RegisterShader; cgi->R_RegisterShaderNoMip = re.RegisterShaderNoMip; - cgi->R_AddRefEntityToScene = re.AddRefEntityToScene; - cgi->R_AddRefSpriteToScene = re.AddRefSpriteToScene; + cgi->R_AddRefEntityToScene = re.newre.AddRefEntityToScene; + cgi->R_AddRefSpriteToScene = re.newre.AddRefSpriteToScene; - cgi->R_AddLightToScene = re.AddLightToScene; - cgi->R_AddPolyToScene = re.AddPolyToScene; - cgi->R_AddTerrainMarkToScene = re.AddTerrainMarkToScene; + cgi->R_AddLightToScene = re.newre.AddLightToScene; + cgi->R_AddPolyToScene = re.newre.AddPolyToScene; + cgi->R_AddTerrainMarkToScene = re.newre.AddTerrainMarkToScene; cgi->R_SetColor = re.SetColor; cgi->R_DrawStretchPic = re.DrawStretchPic; - cgi->R_LoadFont = re.LoadFont; - cgi->R_DrawString = re.DrawString; - cgi->R_ModelBounds = re.ModelBounds; - cgi->R_ModelRadius = re.ModelRadius; - cgi->R_GetRenderEntity = re.GetRenderEntity; - cgi->R_Noise = re.Noise; - cgi->R_DebugLine = re.DebugLine; + cgi->R_LoadFont = re.newre.LoadFont; + cgi->R_DrawString = re.newre.DrawString; + cgi->R_ModelBounds = re.newre.ModelBounds; + cgi->R_ModelRadius = re.newre.ModelRadius; + cgi->R_GetRenderEntity = re.newre.GetRenderEntity; + cgi->R_Noise = re.newre.Noise; + cgi->R_DebugLine = re.newre.DebugLine; cgi->GetShader = CL_GetShaderPointer; - cgi->R_GetShaderWidth = re.GetShaderWidth; - cgi->R_GetShaderHeight = re.GetShaderHeight; + cgi->R_GetShaderWidth = re.newre.GetShaderWidth; + cgi->R_GetShaderHeight = re.newre.GetShaderHeight; - cgi->R_DrawBox = re.DrawBox; - cgi->R_SwipeBegin = re.SwipeBegin; - cgi->R_SwipePoint = re.SwipePoint; - cgi->R_SwipeEnd = re.SwipeEnd; + cgi->R_DrawBox = re.newre.DrawBox; + cgi->R_SwipeBegin = re.newre.SwipeBegin; + cgi->R_SwipePoint = re.newre.SwipePoint; + cgi->R_SwipeEnd = re.newre.SwipeEnd; cgi->GetGameState = CL_GetGameState; cgi->GetSnapshot = CL_GetSnapshot; @@ -684,7 +684,7 @@ void CL_InitCGameDLL( clientGameImport_t *cgi, clientGameExport_t **cge ) { cgi->Key_KeynumToBindString = Key_KeynumToBindString; cgi->Key_GetKeysForCommand = Key_GetKeysForCommand; - cgi->R_Model_GetHandle = re.R_Model_GetHandle; + cgi->R_Model_GetHandle = re.newre.R_Model_GetHandle; cgi->TIKI_NumAnims = TIKI_NumAnims; cgi->TIKI_CalculateBounds = TIKI_CalculateBounds; @@ -709,9 +709,9 @@ void CL_InitCGameDLL( clientGameImport_t *cgi, clientGameExport_t **cge ) { cgi->Tag_NumForName = TIKI_Tag_NameToNum; cgi->Tag_NameForNum = TIKI_Tag_NumToName; - cgi->ForceUpdatePose = re.ForceUpdatePose; - cgi->TIKI_Orientation = re.TIKI_Orientation; - cgi->TIKI_IsOnGround = re.TIKI_IsOnGround; + cgi->ForceUpdatePose = re.newre.ForceUpdatePose; + cgi->TIKI_Orientation = re.newre.TIKI_Orientation; + cgi->TIKI_IsOnGround = re.newre.TIKI_IsOnGround; cgi->UI_ShowScoreBoard = UI_ShowScoreboard_f; cgi->UI_HideScoreBoard = UI_HideScoreboard_f; diff --git a/code/client/cl_cin.cpp b/code/client/cl_cin.cpp index fc3ada32..c2ec3efd 100644 --- a/code/client/cl_cin.cpp +++ b/code/client/cl_cin.cpp @@ -1583,13 +1583,13 @@ void CIN_DrawCinematic (int handle) { CIN_ResampleCinematic(handle, buf2); - re.DrawStretchRaw( x, y, w, h, 256, 256, 0, (byte *)buf2); + re.DrawStretchRaw( x, y, w, h, 256, 256, (byte *)buf2, 0, qfalse); cinTable[handle].dirty = qfalse; Hunk_FreeTempMemory(buf2); return; } - re.DrawStretchRaw( x, y, w, h, cinTable[handle].drawX, cinTable[handle].drawY, 0, buf); + re.DrawStretchRaw( x, y, w, h, cinTable[handle].drawX, cinTable[handle].drawY, buf, 0, qfalse); cinTable[handle].dirty = qfalse; } diff --git a/code/client/cl_main.cpp b/code/client/cl_main.cpp index d55bde84..8f8e6ba8 100644 --- a/code/client/cl_main.cpp +++ b/code/client/cl_main.cpp @@ -2329,7 +2329,7 @@ void CL_CheckUserinfo( void ) { } void CL_SetFrameNumber(int frameNumber) { - re.SetFrameNumber(frameNumber); + re.newre.SetFrameNumber(frameNumber); } /* @@ -2576,7 +2576,7 @@ void CL_StartHunkUsers( void ) { CL_RefMalloc ============ */ -void *CL_RefMalloc(size_t size) { +void *CL_RefMalloc(int size) { return Z_TagMalloc( size, TAG_RENDERER ); } @@ -2606,7 +2606,7 @@ void* CL_RefStaticMallocDebug(size_t size, const char* label, const char* file, CL_RefStaticMalloc ============ */ -void *CL_RefStaticMalloc(size_t size ) { +void *CL_RefStaticMalloc(int size, ha_pref preference ) { void *ptr = Z_TagMalloc( size, TAG_STATIC_RENDERER ); Com_Memset( ptr, 0, size ); return ptr; @@ -2617,7 +2617,7 @@ void *CL_RefStaticMalloc(size_t size ) { CL_RefStaticMallocTemp ============ */ -void* CL_RefStaticMallocTemp(size_t size) { +void* CL_RefStaticMallocTemp(int size) { return Hunk_AllocateTempMemory(size); } @@ -2703,6 +2703,14 @@ int CL_ScaledMilliseconds(void) { return Sys_Milliseconds()*com_timescale->value; } +void CL_RefFS_WriteFile(const char* qpath, const void* buffer, int size) { + FS_WriteFile(qpath, buffer, size); +} + +char** CL_RefFS_ListFiles(const char* name, const char* extension, int* numfilesfound) { + return FS_ListFiles(path, extension, qtrue, numfilesfound); +} + /* ============ CL_InitRef @@ -2727,8 +2735,8 @@ void CL_InitRef( void ) { ri.Milliseconds = CL_ScaledMilliseconds; ri.Malloc = CL_RefMalloc; ri.Free = Z_Free; - ri.Clear = CL_RefClear; - ri.Hunk_Clear = CL_RefStaticClear; + ri.newri.Clear = CL_RefClear; + ri.newri.Hunk_Clear = CL_RefStaticClear; #ifdef HUNK_DEBUG ri.Hunk_AllocDebug = CL_RefStaticMallocDebug; #else @@ -2738,45 +2746,45 @@ void CL_InitRef( void ) { ri.Hunk_FreeTempMemory = Hunk_FreeTempMemory; ri.CM_DrawDebugSurface = CM_DrawDebugSurface; - ri.FS_OpenFile = FS_FOpenFileRead; - ri.FS_CloseFile = FS_FCloseFile; - ri.FS_Read = FS_Read; - ri.FS_Seek = FS_Seek; + ri.newri.FS_OpenFile = FS_FOpenFileRead; + ri.newri.FS_CloseFile = FS_FCloseFile; + ri.newri.FS_Read = FS_Read; + ri.newri.FS_Seek = FS_Seek; ri.FS_ReadFile = FS_ReadFile; - ri.FS_ReadFileEx = FS_ReadFileEx; + ri.newri.FS_ReadFileEx = FS_ReadFileEx; ri.FS_FreeFile = FS_FreeFile; - ri.FS_WriteFile = FS_WriteFile; + ri.FS_WriteFile = CL_RefFS_WriteFile; ri.FS_FreeFileList = FS_FreeFileList; - ri.FS_ListFiles = FS_ListFiles; + ri.FS_ListFiles = CL_RefFS_ListFiles; ri.FS_FileIsInPAK = FS_FileIsInPAK; ri.FS_FileExists = FS_FileExists; ri.Cvar_Get = Cvar_Get; ri.Cvar_Set = Cvar_Set; - ri.Cvar_SetDefault = Cvar_SetDefault; + ri.newri.Cvar_SetDefault = Cvar_SetDefault; - ri.CM_EntityString = CM_EntityString; - ri.CM_MapTime = CM_MapTime; - ri.CM_BoxTrace = CM_BoxTrace; - ri.CG_PermanentMark = CL_CG_PermanentMark; - ri.CG_PermanentTreadMarkDecal = CL_CG_PermanentTreadMarkDecal; - ri.CG_PermanentUpdateTreadMark = CL_CG_PermanentUpdateTreadMark; - ri.CM_TerrainSquareType = CM_TerrainSquareType; - ri.CG_ProcessInitCommands = CL_CG_ProcessInitCommands; - ri.CG_EndTiki = CL_CG_EndTiki; - ri.SetPerformanceCounters = CL_RefSetPerformanceCounters; + ri.newri.CM_EntityString = CM_EntityString; + ri.newri.CM_MapTime = CM_MapTime; + ri.newri.CM_BoxTrace = CM_BoxTrace; + ri.newri.CG_PermanentMark = CL_CG_PermanentMark; + ri.newri.CG_PermanentTreadMarkDecal = CL_CG_PermanentTreadMarkDecal; + ri.newri.CG_PermanentUpdateTreadMark = CL_CG_PermanentUpdateTreadMark; + ri.newri.CM_TerrainSquareType = CM_TerrainSquareType; + ri.newri.CG_ProcessInitCommands = CL_CG_ProcessInitCommands; + ri.newri.CG_EndTiki = CL_CG_EndTiki; + ri.newri.SetPerformanceCounters = CL_RefSetPerformanceCounters; - ri.DebugLines = &DebugLines; - ri.numDebugLines = &numDebugLines; - ri.DebugStrings = &DebugStrings; - ri.numDebugStrings = &numDebugStrings; + ri.newri.DebugLines = &DebugLines; + ri.newri.numDebugLines = &numDebugLines; + ri.newri.DebugStrings = &DebugStrings; + ri.newri.numDebugStrings = &numDebugStrings; - ri.TIKI_OrientationInternal = TIKI_OrientationInternal; - ri.TIKI_IsOnGroundInternal = TIKI_IsOnGroundInternal; - ri.TIKI_SetPoseInternal = TIKI_SetPoseInternal; - ri.TIKI_Alloc = TIKI_Alloc; - ri.GetRadiusInternal = TIKI_GetRadiusInternal; - ri.GetCentroidRadiusInternal = TIKI_GetCentroidRadiusInternal; - ri.GetFrameInternal = TIKI_GetFrameInternal; + ri.newri.TIKI_OrientationInternal = TIKI_OrientationInternal; + ri.newri.TIKI_IsOnGroundInternal = TIKI_IsOnGroundInternal; + ri.newri.TIKI_SetPoseInternal = TIKI_SetPoseInternal; + ri.newri.TIKI_Alloc = TIKI_Alloc; + ri.newri.GetRadiusInternal = TIKI_GetRadiusInternal; + ri.newri.GetCentroidRadiusInternal = TIKI_GetCentroidRadiusInternal; + ri.newri.GetFrameInternal = TIKI_GetFrameInternal; #ifdef USE_RENDERER_DLL // su44: load renderer dll diff --git a/code/client/cl_scrn.cpp b/code/client/cl_scrn.cpp index 85756290..7c1a0c86 100644 --- a/code/client/cl_scrn.cpp +++ b/code/client/cl_scrn.cpp @@ -439,7 +439,7 @@ void SCR_DrawScreenField( void ) { if ( cls.glconfig.vidWidth * 480 > cls.glconfig.vidHeight * 640 ) { re.SetColor( g_color_table[0] ); //re.DrawStretchPic( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, 0, 0, 0, cls.whiteShader ); - re.DrawBox( 0, 0, cls.glconfig.vidHeight, cls.glconfig.vidWidth ); + re.newre.DrawBox( 0, 0, cls.glconfig.vidHeight, cls.glconfig.vidWidth ); re.SetColor( NULL ); } } diff --git a/code/client/cl_ui.cpp b/code/client/cl_ui.cpp index 48548969..9db2ee74 100644 --- a/code/client/cl_ui.cpp +++ b/code/client/cl_ui.cpp @@ -1637,10 +1637,10 @@ UI_ClearBackground ==================== */ void UI_ClearBackground( void ) { - re.Set2DWindow( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, -1, -1 ); - re.Scissor( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight ); + re.newre.Set2DWindow( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, -1, -1 ); + re.newre.Scissor( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight ); re.SetColor( g_color_table[ 0 ] ); - re.DrawBox( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight ); + re.newre.DrawBox( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight ); re.SetColor( NULL ); } @@ -1712,7 +1712,7 @@ void UI_Update(void) { Menu* currentMenu; UIRect2D frame; - re.SetRenderTime(cls.realtime); + re.newre.SetRenderTime(cls.realtime); CL_FillUIDef(); uWinMan.ServiceEvents(); @@ -3704,17 +3704,17 @@ CL_FillUIImports ==================== */ void CL_FillUIImports( void ) { - uii.Rend_DrawBox = re.DrawBox; + uii.Rend_DrawBox = re.newre.DrawBox; uii.Rend_DrawPicStretched = re.DrawStretchPic; - uii.Rend_DrawPicTiled = re.DrawTilePic; - uii.Rend_GetShaderHeight = re.GetShaderHeight; - uii.Rend_GetShaderWidth = re.GetShaderWidth; - uii.Rend_DrawString = re.DrawString; - uii.Rend_LoadFont = re.LoadFont; + uii.Rend_DrawPicTiled = re.newre.DrawTilePic; + uii.Rend_GetShaderHeight = re.newre.GetShaderHeight; + uii.Rend_GetShaderWidth = re.newre.GetShaderWidth; + uii.Rend_DrawString = re.newre.DrawString; + uii.Rend_LoadFont = re.newre.LoadFont; uii.Rend_RegisterMaterial = re.RegisterShaderNoMip; - uii.Rend_RefreshMaterial = re.RefreshShaderNoMip; - uii.Rend_Scissor = re.Scissor; - uii.Rend_Set2D = re.Set2DWindow; + uii.Rend_RefreshMaterial = re.newre.RefreshShaderNoMip; + uii.Rend_Scissor = re.newre.Scissor; + uii.Rend_Set2D = re.newre.Set2DWindow; uii.Rend_SetColor = re.SetColor; uii.Cmd_Stuff = Cbuf_AddText; diff --git a/code/client/cl_uistd.cpp b/code/client/cl_uistd.cpp index 834bfca4..dc992b0d 100644 --- a/code/client/cl_uistd.cpp +++ b/code/client/cl_uistd.cpp @@ -491,13 +491,13 @@ void UIFakkLabel::DrawStatbar( float frac ) float width = frac * m_frame.size.width; m_statbar_material->ReregisterMaterial(); - re.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material->GetMaterial()); + re.newre.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material->GetMaterial()); if (alpha != 0.0 && m_statbar_material_flash) { re.SetColor(col); m_statbar_material_flash->ReregisterMaterial(); - re.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material_flash->GetMaterial()); + re.newre.DrawTilePic(0.0, 0.0, width, m_frame.size.height, m_statbar_material_flash->GetMaterial()); } break; } @@ -509,13 +509,13 @@ void UIFakkLabel::DrawStatbar( float frac ) float y = m_frame.size.height * (1.0 - frac); m_statbar_material->ReregisterMaterial(); - re.DrawTilePic(0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material->GetMaterial()); + re.newre.DrawTilePic(0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material->GetMaterial()); if (alpha != 0.0 && m_statbar_material_flash) { re.SetColor(col); m_statbar_material_flash->ReregisterMaterial(); - re.DrawTilePic(0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material_flash->GetMaterial()); + re.newre.DrawTilePic(0.0, y, m_frame.size.width, m_frame.size.height, m_statbar_material_flash->GetMaterial()); } break; } @@ -821,7 +821,7 @@ void UIFakkLabel::DrawStatCompass( float frac ) vVerts[2][1] = vCenter[1] - vCompassDir[1] * vCenter[1] - fSinVal * vCenter[0]; m_statbar_material->ReregisterMaterial(); - re.DrawTrianglePic(vVerts, vTexCoords, m_statbar_material->GetMaterial()); + re.newre.DrawTrianglePic(vVerts, vTexCoords, m_statbar_material->GetMaterial()); vVerts[0][0] = vVerts[2][0]; vVerts[0][1] = vVerts[2][1]; @@ -834,7 +834,7 @@ void UIFakkLabel::DrawStatCompass( float frac ) vVerts[2][1] = vCenter[1] * fSinVal + vCenter[0] - vCompassDir[1] * vCenter[1]; m_statbar_material->ReregisterMaterial(); - re.DrawTrianglePic(vVerts, vTexCoords, m_statbar_material->GetMaterial()); + re.newre.DrawTrianglePic(vVerts, vTexCoords, m_statbar_material->GetMaterial()); } void UIFakkLabel::DrawStatSpinner( float frac ) diff --git a/code/client/cl_uiview3d.cpp b/code/client/cl_uiview3d.cpp index 1905ff5f..74331ac6 100644 --- a/code/client/cl_uiview3d.cpp +++ b/code/client/cl_uiview3d.cpp @@ -55,7 +55,7 @@ void View3D::Draw set2D(); - re.SavePerformanceCounters(); + re.newre.SavePerformanceCounters(); Draw2D(); } @@ -132,7 +132,7 @@ void View3D::DrawFPS if (fps->integer == 2) { re.SetColor(UBlack); - re.DrawBox( + re.newre.DrawBox( 0.0, m_frame.pos.y + m_frame.size.height - m_font->getHeight(qfalse) * 4.0, m_frame.pos.x + m_frame.size.width, diff --git a/code/client/client.h b/code/client/client.h index 7da66591..1ff4da8b 100644 --- a/code/client/client.h +++ b/code/client/client.h @@ -26,7 +26,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "../qcommon/q_shared.h" #include "../qcommon/qcommon.h" -#include "../renderer/tr_public.h" +#include "../cgame/tr_types.h" +#include "../renderercommon/tr_public.h" #include "keys.h" #include "snd_public.h" #include "../cgame/cg_public.h" diff --git a/code/qcommon/cmd.c b/code/qcommon/cmd.c index 9480df60..25d2e974 100644 --- a/code/qcommon/cmd.c +++ b/code/qcommon/cmd.c @@ -148,7 +148,7 @@ void Cbuf_InsertText( const char *text ) { Cbuf_ExecuteText ============ */ -void Cbuf_ExecuteText (cbufExec_t exec_when, const char *text) +void Cbuf_ExecuteText (int exec_when, const char *text) { switch (exec_when) { diff --git a/code/qcommon/files.cpp b/code/qcommon/files.cpp index ae39e844..a22f5140 100644 --- a/code/qcommon/files.cpp +++ b/code/qcommon/files.cpp @@ -1706,7 +1706,7 @@ Filename are relative to the quake search path a null buffer will just return the file length without loading ============ */ -int FS_ReadFileEx( const char *qpath, void **buffer, qboolean quiet ) { +long FS_ReadFileEx( const char *qpath, void **buffer, qboolean quiet ) { fileHandle_t h; byte* buf; qboolean isConfig; @@ -1824,7 +1824,7 @@ Filename are relative to the quake search path a null buffer will just return the file length without loading ============ */ -int FS_ReadFile( const char *qpath, void **buffer ) { +long FS_ReadFile( const char *qpath, void **buffer ) { return FS_ReadFileEx( qpath, buffer, qfalse ); } diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h index 696e27ab..ce9f383c 100644 --- a/code/qcommon/qcommon.h +++ b/code/qcommon/qcommon.h @@ -439,7 +439,7 @@ void Cbuf_Init (void); void Cbuf_AddText( const char *text ); // Adds command text at the end of the buffer, does NOT add a final \n -void Cbuf_ExecuteText(cbufExec_t exec_when, const char *text ); +void Cbuf_ExecuteText(int exec_when, const char *text ); // this can be used in place of either Cbuf_AddText or Cbuf_InsertText void Cbuf_Execute (int msec); @@ -705,8 +705,8 @@ size_t FS_Read( void *buffer, size_t len, fileHandle_t f ); void FS_FCloseFile( fileHandle_t f ); // note: you can't just fclose from another DLL, due to MS libc issues -int FS_ReadFileEx( const char *qpath, void **buffer, qboolean quiet ); -int FS_ReadFile( const char *qpath, void **buffer ); +long FS_ReadFileEx(const char* qpath, void** buffer, qboolean quiet); +long FS_ReadFile(const char* qpath, void** buffer); const char *FS_Gamedir( void ); // returns the length of the file // a null buffer will just return the file length without loading diff --git a/code/renderercommon/new/tr_public_new.h b/code/renderercommon/new/tr_public_new.h new file mode 100644 index 00000000..29203400 --- /dev/null +++ b/code/renderercommon/new/tr_public_new.h @@ -0,0 +1,147 @@ +/* +=========================================================================== +Copyright (C) 2023 the OpenMoHAA team + +This file is part of OpenMoHAA source code. + +OpenMoHAA source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +OpenMoHAA source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with OpenMoHAA source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#include "../../cgame/tr_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct dtiki_s dtiki_t; +typedef struct skelAnimFrame_s skelAnimFrame_t; + +typedef struct { + qhandle_t(*SpawnEffectModel)(const char* name, vec3_t pos, vec3_t axis[3]); + qhandle_t(*RegisterServerModel)(const char* name); + void (*UnregisterServerModel)(qhandle_t model); + qhandle_t(*RefreshShaderNoMip)(const char* name); + void (*FreeModels)(); + + void (*PrintBSPFileSizes)(); + int (*MapVersion)(); + + void (*AddRefEntityToScene)(const refEntity_t* re, int parentEntityNumber); + void (*AddRefSpriteToScene)(const refEntity_t* ent); + qboolean(*AddPolyToScene)(qhandle_t hShader, int numVerts, const polyVert_t* verts, int renderfx); + void (*AddTerrainMarkToScene)(int terrainIndex, qhandle_t hShader, int numVerts, const polyVert_t* verts, int renderfx); + void (*AddLightToScene)(const vec3_t org, float intensity, float r, float g, float b, int type); + void (*RenderScene)(const refdef_t* fd); + + refEntity_t* (*GetRenderEntity)(int entityNumber); + void (*SavePerformanceCounters)(); + + void (*Set2DWindow)(int x, int y, int w, int h, float left, float right, float bottom, float top, float n, float f); + void (*DrawTilePic)(float x, float y, float w, float h, qhandle_t hShader); + void (*DrawTilePicOffset)(float x, float y, float w, float h, qhandle_t hShader, int offsetX, int offsetY); + void (*DrawTrianglePic)(vec2_t* points, vec2_t* texCoords, qhandle_t hShader); + void (*DrawBackground)(int cols, int rows, int bgr, uint8_t* data); + + // Draw images for cinematic rendering, pass as 32 bit rgba + void (*DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, int components, const byte* data); + void (*DebugLine)(const vec3_t start, const vec3_t end, float r, float g, float b, float alpha); + void (*DrawBox)(float x, float y, float w, float h); + void (*AddBox)(float x, float y, float w, float h); + + void (*BeginFrame)(stereoFrame_t stereoFrame); + void (*Scissor)(int x, int y, int width, int height); + void (*DrawLineLoop)(const vec2_t* points, int count, int stippleFactor, int stippleMask); + + int (*MarkFragments)( int numPoints, const vec3_t *points, const vec3_t projection, + int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t *fragmentBuffer, float fRadiusSquared); + int (*MarkFragmentsForInlineModel)(clipHandle_t bmodel, const vec3_t angles, const vec3_t origin, int numPoints, + const vec3_t* points, const vec3_t projection, int maxPoints, vec3_t pointBuffer, + int maxFragments, markFragment_t* fragmentBuffer, float radiusSquared); + + void (*GetInlineModelBounds)(int index, vec3_t mins, vec3_t maxs); + void (*GetLightingForDecal)(vec3_t light, vec3_t facing, vec3_t origin); + void (*GetLightingForSmoke)(vec3_t light, vec3_t origin); + int (*R_GatherLightSources)(const vec3_t pos, vec3_t* lightPos, vec3_t* lightIntensity, int maxLights); + + void (*ModelBounds)(qhandle_t model, vec3_t mins, vec3_t maxs); + float (*ModelRadius)(qhandle_t handle); + + dtiki_t* (*R_Model_GetHandle)(qhandle_t handle); + void (*DrawString)(fontheader_t* font, const char* text, float x, float y, int maxLen, qboolean virtualScreen); + float (*GetFontHeight)(const fontheader_t* font); + float (*GetFontStringWidth)(const fontheader_t* font, const char* string); + fontheader_t* (*LoadFont)(const char* name); + void (*SwipeBegin)(float thisTime, float life, qhandle_t hShader); + void (*SwipePoint)(vec3_t point1, vec3_t point2, float time); + void (*SwipeEnd)(); + void (*SetRenderTime)(int t); + float (*Noise)(float x, float y, float z, float t); + qboolean (*SetMode)(int mode, const glconfig_t* glConfig); + void (*SetFullscreen)(qboolean fullScreen); + int (*GetShaderWidth)(qhandle_t hShader); + int (*GetShaderHeight)(qhandle_t hShader); + const char* (*GetGraphicsInfo)(); + void (*ForceUpdatePose)(refEntity_t* model); + orientation_t (*TIKI_Orientation)(refEntity_t* model, int tagNum); + qboolean (*TIKI_IsOnGround)(refEntity_t* model, int tagNum, float threshold); + void (*SetFrameNumber)(int frameNumber); + +} refexport_new_t; + +typedef struct { + char* (*LV_ConvertString)(char* string); + void (*Hunk_Clear)(); + void (*Clear)(); + void (*Cvar_SetDefault)(cvar_t* var, const char* varValue); + byte* (*CM_ClusterPVS)(int cluster); + + + int (*FS_OpenFile)(const char* qpath, fileHandle_t *file, qboolean uniqueFILE, qboolean quiet); + size_t (*FS_Read)(void* buffer, size_t len, fileHandle_t fileHandle); + void (*FS_CloseFile)(fileHandle_t fileHandle); + int (*FS_Seek)(fileHandle_t fileHandle, long offset, fsOrigin_t origin); + long (*FS_ReadFileEx)(const char* qpath, void** buffer, qboolean quiet); + + void (*CM_BoxTrace)(trace_t* results, const vec3_t start, const vec3_t end, const vec3_t mins, const vec3_t maxs, int model, int brushMask, int cylinder); + int (*CM_TerrainSquareType)(int terrainPatch, int i, int j); + char* (*CM_EntityString)(); + const char* (*CM_MapTime)(); + int (*CG_PermanentMark)(const vec3_t origin, const vec3_t dir, float orientation, float sScale, float tScale, float red, float green, float blue, float alpha, qboolean doLighting, float sCenter, float tCenter, markFragment_t* markFragments, void* polyVerts); + int (*CG_PermanentTreadMarkDecal)(treadMark_t* treadMark, qboolean startSegment, qboolean doLighting, markFragment_t* markFragments, void* polyVerts); + int (*CG_PermanentUpdateTreadMark)(treadMark_t* treadMark, float alpha, float minSegment, float maxSegment, float maxOffset, float texScale); + void (*CG_ProcessInitCommands)(dtiki_t* tiki, refEntity_t* ent); + void (*CG_EndTiki)(dtiki_t* tiki); + void (*SetPerformanceCounters)(int totalTris, int totalVerts, int totalTexels, int worldTris, int worldVerts, int characterLights); + + debugline_t** DebugLines; + int* numDebugLines; + debugstring_t** DebugStrings; + int* numDebugStrings; + + orientation_t (*TIKI_OrientationInternal)(dtiki_t* tiki, int entNum, int tagNum, float scale); + qboolean (*TIKI_IsOnGroundInternal)(dtiki_t* tiki, int entNum, int tagNum, float thresHold); + void (*TIKI_SetPoseInternal)(void* skeletor, const frameInfo_t* frameInfo, const int* boneTag, const vec4_t *boneQuat, float actionWeight); + void* (*TIKI_Alloc)(size_t size); + float (*GetRadiusInternal)(dtiki_t* tiki, int entNum, float scale); + float (*GetCentroidRadiusInternal)(dtiki_t* tiki, int entNum, float scale, vec3_t centroid); + void (*GetFrameInternal)(dtiki_t* tiki, int entNum, skelAnimFrame_t* newFrame); +} refimport_new_t; + +qboolean R_ImageExists(const char* name); + +#ifdef __cplusplus +} +#endif diff --git a/code/renderercommon/tr_public.h b/code/renderercommon/tr_public.h index 8573860b..f280fce1 100644 --- a/code/renderercommon/tr_public.h +++ b/code/renderercommon/tr_public.h @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define __TR_PUBLIC_H #include "tr_types.h" +#include "new/tr_public_new.h" #define REF_API_VERSION 8 @@ -99,6 +100,8 @@ typedef struct { qboolean (*inPVS)( const vec3_t p1, const vec3_t p2 ); void (*TakeVideoFrame)( int h, int w, byte* captureBuffer, byte *encodeBuffer, qboolean motionJpeg ); + + refexport_new_t newre; } refexport_t; // @@ -180,6 +183,8 @@ typedef struct { void (*Sys_GLimpSafeInit)( void ); void (*Sys_GLimpInit)( void ); qboolean (*Sys_LowPhysicalMemory)( void ); + + refimport_new_t newri; } refimport_t; diff --git a/code/renderergl2/glsl/shaders.cmake b/code/renderergl2/glsl/shaders.cmake new file mode 100644 index 00000000..925f3513 --- /dev/null +++ b/code/renderergl2/glsl/shaders.cmake @@ -0,0 +1,14 @@ +file(GLOB_RECURSE SHADER_GLSL_SRCS "code/renderergl2/glsl/*.glsl") + +add_executable(stringify "code/tools/stringify.cpp") + +foreach (shader ${SHADER_GLSL_SRCS}) + get_filename_component(shaderfile ${shader} NAME_WE) + list(APPEND SHADER_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${shaderfile}.c) + set_source_files_properties(${shaderfile}.c PROPERTIES GENERATED TRUE) + add_custom_command(OUTPUT ${shaderfile}.c + DEPENDS stringify ${shader} + COMMAND stringify ${shader} ${CMAKE_CURRENT_BINARY_DIR}/${shaderfile}.c + COMMENT "Generate c source for ${shader}: ${shaderfile}.c" + ) +endforeach() diff --git a/code/renderergl2/new/tr_image_new.c b/code/renderergl2/new/tr_image_new.c new file mode 100644 index 00000000..c8106ae3 --- /dev/null +++ b/code/renderergl2/new/tr_image_new.c @@ -0,0 +1,23 @@ +/* +=========================================================================== +Copyright (C) 2023 the OpenMoHAA team + +This file is part of OpenMoHAA source code. + +OpenMoHAA source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +OpenMoHAA source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with OpenMoHAA source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#include "../tr_local.h" diff --git a/code/renderergl2/tr_image.c b/code/renderergl2/tr_image.c index 09ceff08..de4a38c0 100644 --- a/code/renderergl2/tr_image.c +++ b/code/renderergl2/tr_image.c @@ -3227,3 +3227,32 @@ void R_SkinList_f( void ) { } + +/* +================ +R_ImageExists +================ +*/ +qboolean R_ImageExists(const char* name) { + image_t* image; + long int hash; + + if (name) + { + hash = generateHashValue(name); + image = hashTable[hash]; + + if (hash) + { + for (; image != NULL; image = image->next) + { + if (!strcmp(name, image->imgName)) { + return qtrue; + } + } + } + } + + return qfalse; +} + diff --git a/code/tools/stringify.cpp b/code/tools/stringify.cpp new file mode 100644 index 00000000..f52c3b2f --- /dev/null +++ b/code/tools/stringify.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +#include +#include + +// Because the ioQuake3 crew is unable to rely on anything else +// other than this sh*tty POSIX for portable development +// I'm doing this + +int main(int argc, const char** argv) +{ + std::ifstream ifp; + std::ofstream ofp; + std::string buffer; + + if (argc < 3) + return 1; + + std::string inFile = argv[1]; + std::string outFile = argv[2]; + + ifp.open(inFile, std::ios_base::in); + if (!ifp.is_open()) + return 2; + + ofp.open(outFile, std::ios_base::out); + if (!ofp.is_open()) + return 3; + + // Strip extension + const size_t lastSlash = inFile.find_last_of("/\\") + 1; + const size_t lastDot = inFile.find_last_of("."); + std::string base = inFile.substr(lastSlash, lastDot - lastSlash); + ofp << "const char *fallbackShader_" << base << " = " << std::endl; + + while (std::getline(ifp, buffer)) + { + // Strip trailing whitespace from line + const char* end = buffer.c_str() + buffer.length() - 1; + while (end >= buffer.c_str() && isspace(*end)) { + end--; + } + + std::string value = buffer.substr(0, buffer.c_str() - end); + + // Write line enquoted, with a newline + ofp << "\"" << value << "\\n" << "\"" << std::endl; + } + + ofp << ";" << std::endl; + + ifp.close(); + ofp.close(); + + return 0; +} diff --git a/code/uilib/ui_public.h b/code/uilib/ui_public.h index 4b19ac80..24794e31 100644 --- a/code/uilib/ui_public.h +++ b/code/uilib/ui_public.h @@ -73,7 +73,7 @@ typedef struct uiimport_s { int( *Rend_GetShaderHeight )( qhandle_t hShader ); void ( *File_PickFile )( const char *name, Listener *obj, Event& event ); void ( *File_ListFiles )( const char *filespec ); - int ( *File_OpenFile )( const char *qpath, void **buffer ); + long ( *File_OpenFile )( const char *qpath, void **buffer ); void ( *File_FreeFile )( void *buffer ); void ( *File_WriteFile )( const char *qpath, const void *buffer, int size ); uihandle_t ( *Snd_RegisterSound )( const char *sample, qboolean streamed );