diff --git a/src/core/common.h b/src/core/common.h index f1b9cada..1a63bd86 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -187,8 +187,8 @@ __always_inline uint32 ldb(uint32 p, uint32 s, uint32 w) #define SCREEN_HEIGHT ((float)448) #endif #else -#define SCREEN_WIDTH ((float)640) -#define SCREEN_HEIGHT ((float)480) +extern float SCREEN_WIDTH; +extern float SCREEN_HEIGHT; #endif #define SCREEN_HEIGHT_PAL ((float)512) diff --git a/src/core/config.h b/src/core/config.h index 1da628f8..fcf8f699 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -311,7 +311,7 @@ enum Config { #define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch) // #define USE_TXD_CDIMAGE // generate and load textures from txd.img // #define PS2_ALPHA_TEST // emulate ps2 alpha test -#define IMPROVED_VIDEOMODE // save and load videomode parameters instead of a magic number +//#define IMPROVED_VIDEOMODE // save and load videomode parameters instead of a magic number // #define DISABLE_LOADING_SCREEN // disable the loading screen which vastly improves the loading time #ifdef DISABLE_LOADING_SCREEN // enable the PC splash @@ -327,7 +327,7 @@ enum Config { //#define NEW_RENDERER // leeds-like world rendering, needs librw #endif -#define FIX_SPRITES // fix sprites aspect ratio(moon, coronas, particle etc) +// #define FIX_SPRITES // fix sprites aspect ratio(moon, coronas, particle etc) // JP - Disabled this as it produces incorrect aspect ratio with custom screen resolutions and is not needed otherwise #ifndef EXTENDED_COLOURFILTER #undef SCREEN_DROPLETS // we need the backbuffer for this effect diff --git a/src/renderer/Draw.cpp b/src/renderer/Draw.cpp index f702f188..e94bfad5 100644 --- a/src/renderer/Draw.cpp +++ b/src/renderer/Draw.cpp @@ -41,7 +41,11 @@ CDraw::FindAspectRatio(void) #else switch (FrontEndMenuManager.m_PrefsUseWideScreen) { case AR_AUTO: +#ifdef DC_SH4 + return 4.0f / 3.0f; +#else return SCREEN_WIDTH / SCREEN_HEIGHT; +#endif default: case AR_4_3: return 4.0f / 3.0f; diff --git a/src/renderer/MBlur.cpp b/src/renderer/MBlur.cpp index 359bcc79..1b3e57e5 100644 --- a/src/renderer/MBlur.cpp +++ b/src/renderer/MBlur.cpp @@ -134,7 +134,7 @@ CMBlur::MotionBlurOpen(RwCamera *cam) return TRUE; #else - RwRect rect = { 0, 0, 640, 480 }; + RwRect rect = { 0, 0, (rw::int32)SCREEN_WIDTH, (rw::int32)SCREEN_HEIGHT }; CreateImmediateModeData(cam, &rect); return TRUE; #endif diff --git a/src/skel/dc/dc.cpp b/src/skel/dc/dc.cpp index 4f2e8ccb..e25ad9af 100644 --- a/src/skel/dc/dc.cpp +++ b/src/skel/dc/dc.cpp @@ -877,10 +877,6 @@ psSelectDevice() /* Get the default selection */ GcurSel = RwEngineGetCurrentSubSystem(); -#ifdef IMPROVED_VIDEOMODE - if(FrontEndMenuManager.m_nPrefsSubsystem < GnumSubSystems) - GcurSel = FrontEndMenuManager.m_nPrefsSubsystem; -#endif } /* Set the driver to use the correct sub system */ @@ -889,11 +885,6 @@ psSelectDevice() return FALSE; } -#ifdef IMPROVED_VIDEOMODE - FrontEndMenuManager.m_nPrefsSubsystem = GcurSel; -#endif - -#ifndef IMPROVED_VIDEOMODE if ( !useDefault ) { if ( _psGetVideoModeList()[FrontEndMenuManager.m_nDisplayVideoMode] && FrontEndMenuManager.m_nDisplayVideoMode ) @@ -903,97 +894,11 @@ psSelectDevice() } else { -#ifdef DEFAULT_NATIVE_RESOLUTION - // get the native video mode - HDC hDevice = GetDC(NULL); - int w = GetDeviceCaps(hDevice, HORZRES); - int h = GetDeviceCaps(hDevice, VERTRES); - int d = GetDeviceCaps(hDevice, BITSPIXEL); -#else - const int w = 640; - const int h = 480; - const int d = 16; -#endif - while ( !modeFound && GcurSelVM < RwEngineGetNumVideoModes() ) - { - RwEngineGetVideoModeInfo(&vm, GcurSelVM); - if ( defaultFullscreenRes && vm.width != w - || vm.height != h - || vm.depth != d - || !(vm.flags & rwVIDEOMODEEXCLUSIVE) ) - ++GcurSelVM; - else - modeFound = TRUE; - } - - if ( !modeFound ) - { -#ifdef DEFAULT_NATIVE_RESOLUTION - GcurSelVM = 1; -#else - printf("WARNING: Cannot find 640x480 video mode, selecting device cancelled\n"); - return FALSE; -#endif - } + GcurSelVM = 0; } } -#else - if ( !useDefault ) - { - if(FrontEndMenuManager.m_nPrefsWidth == 0 || - FrontEndMenuManager.m_nPrefsHeight == 0 || - FrontEndMenuManager.m_nPrefsDepth == 0){ - // Defaults if nothing specified - //const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - FrontEndMenuManager.m_nPrefsWidth = 640; //mode->width; - FrontEndMenuManager.m_nPrefsHeight = 480; //mode->height; - FrontEndMenuManager.m_nPrefsDepth = 16; - FrontEndMenuManager.m_nPrefsWindowed = 0; - } - - // Find the videomode that best fits what we got from the settings file - RwInt32 bestFsMode = -1; - RwInt32 bestWidth = -1; - RwInt32 bestHeight = -1; - RwInt32 bestDepth = -1; - for(GcurSelVM = 0; GcurSelVM < RwEngineGetNumVideoModes(); GcurSelVM++){ - RwEngineGetVideoModeInfo(&vm, GcurSelVM); - bestWndMode = GcurSelVM; - bestWidth = vm.width; - bestHeight = vm.height; - bestDepth = vm.depth; - bestFsMode = GcurSelVM; - break; - } - - if(bestFsMode < 0){ - printf("WARNING: Cannot find desired video mode, selecting device cancelled\n"); - return FALSE; - } - GcurSelVM = bestFsMode; - - FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM; - FrontEndMenuManager.m_nPrefsVideoMode = FrontEndMenuManager.m_nDisplayVideoMode; - - FrontEndMenuManager.m_nSelectedScreenMode = FrontEndMenuManager.m_nPrefsWindowed; - } -#endif RwEngineGetVideoModeInfo(&vm, GcurSelVM); - -#ifdef IMPROVED_VIDEOMODE - if (FrontEndMenuManager.m_nPrefsWindowed) - GcurSelVM = bestWndMode; - - // Now GcurSelVM is 0 but vm has sizes(and fullscreen flag) of the video mode we want, that's why we changed the rwVIDEOMODEEXCLUSIVE conditions below - FrontEndMenuManager.m_nPrefsWidth = vm.width; - FrontEndMenuManager.m_nPrefsHeight = vm.height; - FrontEndMenuManager.m_nPrefsDepth = vm.depth; -#endif - -#ifndef PS2_MENU - FrontEndMenuManager.m_nCurrOption = 0; -#endif /* Set up the video mode and set the apps window * dimensions to match */ @@ -1016,25 +921,6 @@ psSelectDevice() } } */ -#ifndef IMPROVED_VIDEOMODE - if (vm.flags & rwVIDEOMODEEXCLUSIVE) - { - RsGlobal.maximumWidth = vm.width; - RsGlobal.maximumHeight = vm.height; - RsGlobal.width = vm.width; - RsGlobal.height = vm.height; - - PSGLOBAL(fullScreen) = TRUE; - } -#else - RsGlobal.maximumWidth = FrontEndMenuManager.m_nPrefsWidth; - RsGlobal.maximumHeight = FrontEndMenuManager.m_nPrefsHeight; - RsGlobal.width = FrontEndMenuManager.m_nPrefsWidth; - RsGlobal.height = FrontEndMenuManager.m_nPrefsHeight; - - PSGLOBAL(fullScreen) = !FrontEndMenuManager.m_nPrefsWindowed; -#endif - #ifdef MULTISAMPLING RwD3D8EngineSetMultiSamplingLevels(1 << FrontEndMenuManager.m_nPrefsMSAALevel); #endif diff --git a/vendor/librw/src/dc/rwdc.cpp b/vendor/librw/src/dc/rwdc.cpp index 54d2cf83..e9b3ea8c 100644 --- a/vendor/librw/src/dc/rwdc.cpp +++ b/vendor/librw/src/dc/rwdc.cpp @@ -29,6 +29,7 @@ extern const char* currentFile; #include "rwdc.h" #include "vq.h" #include "tex-util.h" +#include "common.h" #include #include @@ -56,6 +57,12 @@ bool doEnvironmentMaps = true; #define fclamp0_1(n) ((n) > 1.0f ? 1.0f : n < 0.0f ? 0.0f : n) #define fclamp1(n) ((n) > 1.0f ? 1.0f : n) +const unsigned short VIDEO_MODES = 2; +unsigned short VIDEO_MODE = 0; +rw::VideoMode videoModes[VIDEO_MODES]; +float SCREEN_WIDTH = 640; +float SCREEN_HEIGHT = 480; + struct alignas(32) pvr_vertex16_t { uint32_t flags; /**< \brief TA command (vertex flags) */ float x; /**< \brief X coordinate */ @@ -176,8 +183,6 @@ static pvr_dr_state_t drState; #if !defined(DC_TEXCONV) && !defined(DC_SIM) #include -#define VIDEO_MODE_WIDTH vid_mode->width -#define VIDEO_MODE_HEIGHT vid_mode->height #define mat_trans_nodiv_nomod(x, y, z, x2, y2, z2, w2) do { \ register float __x __asm__("fr12") = (x); \ @@ -288,8 +293,6 @@ void rw_mat_load_4x4(rw::Matrix* mtx) { } #include -#define VIDEO_MODE_WIDTH 640 -#define VIDEO_MODE_HEIGHT 480 #define frsqrt(a) (1.0f/sqrt(a)) #define dcache_pref_block(a) __builtin_prefetch(a) @@ -545,7 +548,7 @@ void DCE_MatrixViewport(float x, float y, float width, float height) { DCE_MAT_SCREENVIEW[1][1] = height * 0.5f; DCE_MAT_SCREENVIEW[2][2] = 1; DCE_MAT_SCREENVIEW[3][0] = -DCE_MAT_SCREENVIEW[0][0] + x; - DCE_MAT_SCREENVIEW[3][1] = VIDEO_MODE_HEIGHT - (DCE_MAT_SCREENVIEW[1][1] + y); + DCE_MAT_SCREENVIEW[3][1] = height - (DCE_MAT_SCREENVIEW[1][1] + y); } void DCE_InitMatrices() { @@ -554,7 +557,7 @@ void DCE_InitMatrices() { mat_store(&DCE_MAT_SCREENVIEW); - DCE_MatrixViewport(0, 0, VIDEO_MODE_WIDTH, VIDEO_MODE_HEIGHT); + DCE_MatrixViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); } } @@ -804,8 +807,9 @@ std::vector> blendCallbacks; std::vector> ptCallbacks; void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { - uint32_t col = (a << 24) | (r << 16) | (g << 8) | b; + int strip_width = SCREEN_WIDTH / 320; + int strip_mult = SCREEN_WIDTH / 640; blendCallbacks.emplace_back([=]() { pvr_poly_cxt_t cxt; @@ -821,8 +825,6 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { auto addr2 = (pvr_ptr_t)&emu_vram[addr64b + 640 * 2]; #endif - - PVR_SET(PVR_TEXTURE_MODULO, 640/32); auto doquad = [=](float x, float y, float w, float h, float tx, float ty, float tw, float th) { @@ -847,23 +849,23 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_dr_commit(vtx); vtx = reinterpret_cast(pvr_dr_target(drState)); - vtx->flags = PVR_CMD_VERTEX; + //vtx->flags = PVR_CMD_VERTEX; vtx->x = x; vtx->y = y+h; - vtx->z = 1000000.0f; + //vtx->z = 1000000.0f; vtx->u = tx/1024.f; vtx->v = (ty+th)/512.0f; - vtx->argb = col; + //vtx->argb = col; pvr_dr_commit(vtx); vtx = reinterpret_cast(pvr_dr_target(drState)); vtx->flags = PVR_CMD_VERTEX_EOL; vtx->x = x+w; vtx->y = y+h; - vtx->z = 1000000.0f; + //vtx->z = 1000000.0f; vtx->u = (tx+tw)/1024.f; vtx->v = (ty+th)/512.0f; - vtx->argb = col; + //vtx->argb = col; pvr_dr_commit(vtx); }; { @@ -886,7 +888,7 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_dr_commit(hdr); } for (int x = 0; x < 320; x+=2) { - doquad(x, 0, 2, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480); + doquad(x*strip_mult, 0, strip_width, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480); } { pvr_poly_cxt_txr(&cxt, @@ -908,7 +910,7 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_dr_commit(hdr); } for (int x = 0; x < 320; x+=2) { - doquad(320+x, 0, 2, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480); + doquad(SCREEN_WIDTH/2 + x*strip_mult, 0, strip_width, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480); } }); } @@ -951,23 +953,23 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_dr_commit(vtx); vtx = reinterpret_cast(pvr_dr_target(drState)); - vtx->flags = PVR_CMD_VERTEX; + //vtx->flags = PVR_CMD_VERTEX; vtx->x = x; vtx->y = y+h; - vtx->z = z; + //vtx->z = z; vtx->u = umin; vtx->v = vmax; - vtx->argb = col; + //vtx->argb = col; pvr_dr_commit(vtx); vtx = reinterpret_cast(pvr_dr_target(drState)); vtx->flags = PVR_CMD_VERTEX_EOL; vtx->x = x+w; vtx->y = y+h; - vtx->z = z; + //vtx->z = z; vtx->u = umax; vtx->v = vmax; - vtx->argb = col; + //vtx->argb = col; pvr_dr_commit(vtx); }; @@ -986,7 +988,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 1e6f, 640.0f, 480.0f, + doquad(0.0f, 0.0f, 1e6f, SCREEN_WIDTH, 480.0f, 0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, mask_col); pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, @@ -1005,10 +1007,10 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 2e6f, 320.0f, 480.0f, + doquad(0.0f, 0.0f, 2e6f, SCREEN_WIDTH / 2.0f, 480.0f, 0.0f, 640.0f / 1024.0f, 0.0f, 960.0f / 1024.0f, col); - doquad(320.0f, 0.0f, 2e6f, 320.0f, 480.0f, + doquad(SCREEN_WIDTH / 2.0f, 0.0f, 2e6f, SCREEN_WIDTH / 2.0f, 480.0f, 0.0f, 640.0f / 1024.0f, 1.0f / 1024.0f, 961.0f / 1024.0f, col); @@ -1019,10 +1021,10 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 3e6f, 320.0f, 480.0f, + doquad(0.0f, 0.0f, 3e6f, SCREEN_WIDTH / 2.0f, 480.0f, -1.0f / 1024.0f, 639.0f / 1024.0f, 0.0f, 960.0f / 1024.0f, col); - doquad(320.0f, 0.0f, 3e6f, 320.0f, 480.0f, + doquad(SCREEN_WIDTH / 2.0f, 0.0f, 3e6f, SCREEN_WIDTH / 2.0f, 480.0f, -1.0f / 1024.0f, 639.0f / 1024.0f, 1.0f / 1024.0f, 961.0f / 1024.0f, col); @@ -1038,7 +1040,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f, + doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f, 0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0xffffffff); cxt.blend.src = PVR_BLEND_ONE; @@ -1048,7 +1050,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f, + doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f, 0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0x000f0f0f); cxt.blend.src = PVR_BLEND_INVDESTCOLOR; @@ -1058,7 +1060,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f, + doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f, 0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0xffffffff); cxt.blend.dst_enable = PVR_BLEND_DISABLE; @@ -1070,7 +1072,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { pvr_poly_compile(hdr, &cxt); pvr_dr_commit(hdr); - doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f, + doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f, 0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0xffffffff); }); } @@ -4521,6 +4523,32 @@ rasterToImage(Raster*) return nil; } +static pvr_init_params_t pvr_params = { + .opb_sizes = { + PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_8, PVR_BINSIZE_0, + PVR_BINSIZE_8 + }, + .vertex_buf_size = (1024 + 1024) * 1024, + .dma_enabled = 0, + .fsaa_enabled = 0, + .autosort_disabled = true, + .opb_overflow_count = 7 // 268800 bytes +}; + +static void makeVideoModeList() { + videoModes[0].width = 640; + videoModes[0].height = 480; + videoModes[0].depth = 16; + videoModes[0].flags = VIDEOMODEEXCLUSIVE; + + videoModes[1].width = 1280; + videoModes[1].height = 480; + videoModes[1].depth = 16; + videoModes[1].flags = VIDEOMODEEXCLUSIVE; + + +} + int deviceSystem(DeviceReq req, void *arg0, int32 n) { @@ -4549,14 +4577,14 @@ deviceSystem(DeviceReq req, void *arg0, int32 n) // TODO: implement subsystems case DEVICEGETVIDEOMODEINFO:{ + makeVideoModeList(); // On startup this is not yet called auto rwmode = (VideoMode*)arg0; - rwmode->width = 640; - rwmode->height = 480; - rwmode->depth = 16; - rwmode->flags = VIDEOMODEEXCLUSIVE; + rwmode->width = videoModes[n].width; + rwmode->height = videoModes[n].height; + rwmode->depth = videoModes[n].depth; + rwmode->flags = videoModes[n].flags; return 1; - } - + } case DEVICEGETMAXMULTISAMPLINGLEVELS: { @@ -4569,11 +4597,21 @@ deviceSystem(DeviceReq req, void *arg0, int32 n) case DEVICESETSUBSYSTEM: return 1; case DEVICEGETNUMVIDEOMODES: - return 1; + return VIDEO_MODES; case DEVICEGETCURRENTVIDEOMODE: - return 0; + return VIDEO_MODE; case DEVICESETVIDEOMODE: - return 1; + { + makeVideoModeList(); // On startup this is called before driverOpen + + VIDEO_MODE = n; + SCREEN_WIDTH = videoModes[VIDEO_MODE].width; + SCREEN_HEIGHT = videoModes[VIDEO_MODE].height; + pvr_params.fsaa_enabled = n; + + return 1; + } + default: assert(0 && "not implemented"); return 0; @@ -4601,15 +4639,7 @@ Device renderdevice = { deviceSystem }; -static pvr_init_params_t pvr_params = { - .opb_sizes = { - PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_8, PVR_BINSIZE_0, - PVR_BINSIZE_8 - }, - .vertex_buf_size = (1024 + 1024) * 1024, - .autosort_disabled = true, - .opb_overflow_count = 7 // 268800 bytes -}; + void defaultInstance(ObjPipeline *pipe, Atomic *atomic) { #if defined(DC_TEXCONV) @@ -4635,6 +4665,8 @@ ObjPipeline* makeDefaultPipeline(void) static void* driverOpen(void *o, int32, int32) { + makeVideoModeList(); + #if defined(DC_SH4) OCR_SPACE = (uint8_t*)0x92000000; @@ -4698,6 +4730,8 @@ driverClose(void *o, int32, int32) { pvr_mem_free(fake_tex); + pvr_shutdown(); + return o; }