mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-14 08:30:50 +00:00
Implement SDL present functions
This commit is contained in:
parent
0f6aec5e99
commit
e4bd2483e5
4 changed files with 142 additions and 12 deletions
|
@ -955,3 +955,20 @@ bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
|
||||||
return result == VK_SUCCESS;
|
return result == VK_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void I_PolyPresentInit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void I_PolyPresentUnlock(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void I_PolyPresentDeinit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -57,6 +57,8 @@
|
||||||
#include "rendering/vulkan/system/vk_framebuffer.h"
|
#include "rendering/vulkan/system/vk_framebuffer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "rendering/polyrenderer/backend/poly_framebuffer.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
// TYPES -------------------------------------------------------------------
|
// TYPES -------------------------------------------------------------------
|
||||||
|
@ -113,6 +115,7 @@ namespace Priv
|
||||||
|
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
bool vulkanEnabled;
|
bool vulkanEnabled;
|
||||||
|
bool softpolyEnabled;
|
||||||
bool fullscreenSwitch;
|
bool fullscreenSwitch;
|
||||||
|
|
||||||
void CreateWindow(uint32_t extraFlags)
|
void CreateWindow(uint32_t extraFlags)
|
||||||
|
@ -230,6 +233,101 @@ bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
SDL_Surface* polysurface = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void I_PolyPresentInit()
|
||||||
|
{
|
||||||
|
assert(Priv::softpolyEnabled);
|
||||||
|
assert(Priv::window != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch)
|
||||||
|
{
|
||||||
|
if (!polysurface || polysurface->w != w || polysurface->h != h)
|
||||||
|
{
|
||||||
|
if (polysurface)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(polysurface);
|
||||||
|
polysurface = nullptr;
|
||||||
|
}
|
||||||
|
polysurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
|
||||||
|
SDL_SetSurfaceBlendMode(polysurface, SDL_BLENDMODE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LockSurface(polysurface);
|
||||||
|
pitch = polysurface->pitch;
|
||||||
|
return (uint8_t*)polysurface->pixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
void I_PolyPresentUnlock(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
SDL_UnlockSurface(polysurface);
|
||||||
|
|
||||||
|
SDL_Surface* windowsurface = SDL_GetWindowSurface(Priv::window);
|
||||||
|
int ClientWidth = windowsurface->w;
|
||||||
|
int ClientHeight = windowsurface->h;
|
||||||
|
|
||||||
|
SDL_Rect clearrects[4];
|
||||||
|
int count = 0;
|
||||||
|
if (y > 0)
|
||||||
|
{
|
||||||
|
clearrects[count].x = 0;
|
||||||
|
clearrects[count].y = 0;
|
||||||
|
clearrects[count].w = ClientWidth;
|
||||||
|
clearrects[count].h = y;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (y + height < ClientHeight)
|
||||||
|
{
|
||||||
|
clearrects[count].x = 0;
|
||||||
|
clearrects[count].y = y + height;
|
||||||
|
clearrects[count].w = ClientWidth;
|
||||||
|
clearrects[count].h = ClientHeight - clearrects[count].y;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (x > 0)
|
||||||
|
{
|
||||||
|
clearrects[count].x = 0;
|
||||||
|
clearrects[count].y = y;
|
||||||
|
clearrects[count].w = x;
|
||||||
|
clearrects[count].h = height;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (x + width < ClientWidth)
|
||||||
|
{
|
||||||
|
clearrects[count].x = x + width;
|
||||||
|
clearrects[count].y = y;
|
||||||
|
clearrects[count].x = ClientWidth - clearrects[count].x;
|
||||||
|
clearrects[count].y = height - clearrects[count].y;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
SDL_FillRects(windowsurface, clearrects, count, 0xff000000);
|
||||||
|
|
||||||
|
SDL_Rect dstrect;
|
||||||
|
dstrect.x = x;
|
||||||
|
dstrect.y = y;
|
||||||
|
dstrect.w = width;
|
||||||
|
dstrect.h = height;
|
||||||
|
SDL_BlitScaled(polysurface, nullptr, windowsurface, &dstrect);
|
||||||
|
|
||||||
|
SDL_UpdateWindowSurface(Priv::window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void I_PolyPresentDeinit()
|
||||||
|
{
|
||||||
|
if (polysurface)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(polysurface);
|
||||||
|
polysurface = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SDLVideo::SDLVideo ()
|
SDLVideo::SDLVideo ()
|
||||||
{
|
{
|
||||||
|
@ -248,6 +346,7 @@ SDLVideo::SDLVideo ()
|
||||||
#ifdef HAVE_VULKAN
|
#ifdef HAVE_VULKAN
|
||||||
Priv::vulkanEnabled = vid_preferbackend == 1
|
Priv::vulkanEnabled = vid_preferbackend == 1
|
||||||
&& Priv::Vulkan_GetDrawableSize && Priv::Vulkan_GetInstanceExtensions && Priv::Vulkan_CreateSurface;
|
&& Priv::Vulkan_GetDrawableSize && Priv::Vulkan_GetInstanceExtensions && Priv::Vulkan_CreateSurface;
|
||||||
|
Priv::softpolyEnabled = vid_preferbackend == 2;
|
||||||
|
|
||||||
if (Priv::vulkanEnabled)
|
if (Priv::vulkanEnabled)
|
||||||
{
|
{
|
||||||
|
@ -258,6 +357,10 @@ SDLVideo::SDLVideo ()
|
||||||
Priv::vulkanEnabled = false;
|
Priv::vulkanEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (Priv::softpolyEnabled)
|
||||||
|
{
|
||||||
|
Priv::CreateWindow(SDL_WINDOW_HIDDEN);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +397,11 @@ DFrameBuffer *SDLVideo::CreateFrameBuffer ()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (Priv::softpolyEnabled)
|
||||||
|
{
|
||||||
|
fb = new PolyFrameBuffer(nullptr, fullscreen);
|
||||||
|
}
|
||||||
|
|
||||||
if (fb == nullptr)
|
if (fb == nullptr)
|
||||||
{
|
{
|
||||||
fb = new OpenGLRenderer::OpenGLFrameBuffer(0, fullscreen);
|
fb = new OpenGLRenderer::OpenGLFrameBuffer(0, fullscreen);
|
||||||
|
@ -325,6 +433,11 @@ int SystemBaseFrameBuffer::GetClientWidth()
|
||||||
{
|
{
|
||||||
int width = 0;
|
int width = 0;
|
||||||
|
|
||||||
|
if (Priv::softpolyEnabled)
|
||||||
|
{
|
||||||
|
return SDL_GetWindowSurface(Priv::window)->w;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_VULKAN
|
#ifdef HAVE_VULKAN
|
||||||
assert(Priv::vulkanEnabled);
|
assert(Priv::vulkanEnabled);
|
||||||
Priv::Vulkan_GetDrawableSize(Priv::window, &width, nullptr);
|
Priv::Vulkan_GetDrawableSize(Priv::window, &width, nullptr);
|
||||||
|
@ -337,6 +450,11 @@ int SystemBaseFrameBuffer::GetClientHeight()
|
||||||
{
|
{
|
||||||
int height = 0;
|
int height = 0;
|
||||||
|
|
||||||
|
if (Priv::softpolyEnabled)
|
||||||
|
{
|
||||||
|
return SDL_GetWindowSurface(Priv::window)->h;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_VULKAN
|
#ifdef HAVE_VULKAN
|
||||||
assert(Priv::vulkanEnabled);
|
assert(Priv::vulkanEnabled);
|
||||||
Priv::Vulkan_GetDrawableSize(Priv::window, nullptr, &height);
|
Priv::Vulkan_GetDrawableSize(Priv::window, nullptr, &height);
|
||||||
|
|
|
@ -22,6 +22,11 @@ void I_ShutdownGraphics();
|
||||||
|
|
||||||
extern IVideo *Video;
|
extern IVideo *Video;
|
||||||
|
|
||||||
|
void I_PolyPresentInit();
|
||||||
|
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch);
|
||||||
|
void I_PolyPresentUnlock(int x, int y, int w, int h);
|
||||||
|
void I_PolyPresentDeinit();
|
||||||
|
|
||||||
|
|
||||||
// Pause a bit.
|
// Pause a bit.
|
||||||
// [RH] Despite the name, it apparently never waited for the VBL, even in
|
// [RH] Despite the name, it apparently never waited for the VBL, even in
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "g_game.h"
|
#include "g_game.h"
|
||||||
#include "gamedata/fonts/v_text.h"
|
#include "gamedata/fonts/v_text.h"
|
||||||
|
|
||||||
|
#include "rendering/i_video.h"
|
||||||
|
|
||||||
#include "hwrenderer/utility/hw_clock.h"
|
#include "hwrenderer/utility/hw_clock.h"
|
||||||
#include "hwrenderer/utility/hw_vrmodes.h"
|
#include "hwrenderer/utility/hw_vrmodes.h"
|
||||||
#include "hwrenderer/utility/hw_cvars.h"
|
#include "hwrenderer/utility/hw_cvars.h"
|
||||||
|
@ -47,18 +49,6 @@ extern bool gpuStatActive;
|
||||||
extern bool keepGpuStatActive;
|
extern bool keepGpuStatActive;
|
||||||
extern FString gpuStatOutput;
|
extern FString gpuStatOutput;
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
void I_PolyPresentInit();
|
|
||||||
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch);
|
|
||||||
void I_PolyPresentUnlock(int x, int y, int w, int h);
|
|
||||||
void I_PolyPresentDeinit();
|
|
||||||
#else
|
|
||||||
void I_PolyPresentInit() { }
|
|
||||||
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch) { pitch = 0; return nullptr; }
|
|
||||||
void I_PolyPresentUnlock(int x, int y, int w, int h) { }
|
|
||||||
void I_PolyPresentDeinit() { }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PolyFrameBuffer::PolyFrameBuffer(void *hMonitor, bool fullscreen) : Super(hMonitor, fullscreen)
|
PolyFrameBuffer::PolyFrameBuffer(void *hMonitor, bool fullscreen) : Super(hMonitor, fullscreen)
|
||||||
{
|
{
|
||||||
I_PolyPresentInit();
|
I_PolyPresentInit();
|
||||||
|
|
Loading…
Reference in a new issue