From 0e6af7137615eeeb70f8ed42b520771d6abfe1bd Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 4 Sep 2018 13:03:15 +0300 Subject: [PATCH 1/2] - improved SDL_GetWindowBordersSize() pointer loading https://forum.zdoom.org/viewtopic.php?t=61913 --- src/posix/sdl/gl_sysfb.h | 6 +----- src/posix/sdl/sdlglvideo.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/posix/sdl/gl_sysfb.h b/src/posix/sdl/gl_sysfb.h index ee2713bc5..44b92cf1a 100644 --- a/src/posix/sdl/gl_sysfb.h +++ b/src/posix/sdl/gl_sysfb.h @@ -52,11 +52,7 @@ protected: static const int MIN_WIDTH = 320; static const int MIN_HEIGHT = 200; - - typedef DECLSPEC int SDLCALL (*SDL_GetWindowBordersSizePtr)(SDL_Window *, int *, int *, int *, int *); - - SDL_GetWindowBordersSizePtr SDL_GetWindowBordersSize_; - void *sdl_lib; }; #endif // __POSIX_SDL_GL_SYSFB_H__ + diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 15c0e4944..b270fcdab 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -35,6 +35,7 @@ #include "doomtype.h" +#include "i_module.h" #include "i_system.h" #include "i_video.h" #include "m_argv.h" @@ -172,6 +173,11 @@ IVideo *gl_CreateVideo() // FrameBuffer implementation ----------------------------------------------- +FModule sdl_lib("SDL2"); + +typedef int (*SDL_GetWindowBordersSizePtr)(SDL_Window *, int *, int *, int *, int *); +static TOptProc SDL_GetWindowBordersSize_("SDL_GetWindowBordersSize"); + SystemGLFrameBuffer::SystemGLFrameBuffer (void *, bool fullscreen) : DFrameBuffer (vid_defwidth, vid_defheight) { @@ -180,10 +186,9 @@ SystemGLFrameBuffer::SystemGLFrameBuffer (void *, bool fullscreen) // SDL_GetWindowBorderSize() is only available since 2.0.5, but because // GZDoom supports platforms with older SDL2 versions, this function // has to be dynamically loaded - sdl_lib = SDL_LoadObject("libSDL2.so"); - if (sdl_lib != nullptr) + if (!sdl_lib.IsLoaded()) { - SDL_GetWindowBordersSize_ = (SDL_GetWindowBordersSizePtr)SDL_LoadFunction(sdl_lib,"SDL_GetWindowBordersSize"); + sdl_lib.Load({ "libSDL2.so", "libSDL2-2.0.so" }); } // NOTE: Core profiles were added with GL 3.2, so there's no sense trying @@ -261,11 +266,6 @@ SystemGLFrameBuffer::SystemGLFrameBuffer (void *, bool fullscreen) SystemGLFrameBuffer::~SystemGLFrameBuffer () { - if (sdl_lib != nullptr) - { - SDL_UnloadObject(sdl_lib); - } - if (Screen) { ResetGammaTable(); @@ -391,7 +391,7 @@ void SystemGLFrameBuffer::SetWindowSize(int w, int h) void SystemGLFrameBuffer::GetWindowBordersSize(int &top, int &left) { - if (SDL_GetWindowBordersSize_ != nullptr) + if (SDL_GetWindowBordersSize_) { SDL_GetWindowBordersSize_(Screen, &top, &left, nullptr, nullptr); } From dd971805af003e481b1ef6b789a330e27f7ae223 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Aug 2018 22:29:22 +0200 Subject: [PATCH 2/2] - fixed: The viewpoint buffer was mapped write only but read from. On old hardware it wasn't even mapped. Changed to cache the needed value in a CPU-side array so that the buffer access is not needed. --- src/gl/data/gl_viewpointbuffer.cpp | 6 ++++-- src/gl/data/gl_viewpointbuffer.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gl/data/gl_viewpointbuffer.cpp b/src/gl/data/gl_viewpointbuffer.cpp index 7b9039bf3..611db9e40 100644 --- a/src/gl/data/gl_viewpointbuffer.cpp +++ b/src/gl/data/gl_viewpointbuffer.cpp @@ -41,6 +41,7 @@ GLViewpointBuffer::GLViewpointBuffer() Allocate(); Clear(); mLastMappedIndex = UINT_MAX; + mClipPlaneInfo.Push(0); } GLViewpointBuffer::~GLViewpointBuffer() @@ -121,10 +122,9 @@ int GLViewpointBuffer::Bind(unsigned int index) glBindBufferRange(GL_UNIFORM_BUFFER, VIEWPOINT_BINDINGPOINT, mBufferId, index * mBlockAlign, mBlockAlign); // Update the viewpoint-related clip plane setting. - auto *vp = (HWViewpointUniforms*)(((char*)mBufferPointer) + mUploadIndex * mBlockAlign); if (!(gl.flags & RFL_NO_CLIP_PLANES)) { - if (index > 0 && (vp->mClipHeightDirection != 0.f || vp->mClipLine.X > -10000000.0f)) + if (mClipPlaneInfo[index]) { glEnable(GL_CLIP_DISTANCE0); } @@ -162,6 +162,7 @@ int GLViewpointBuffer::SetViewpoint(HWViewpointUniforms *vp) memcpy(((char*)mBufferPointer) + mUploadIndex * mBlockAlign, vp, sizeof(*vp)); Unmap(); + mClipPlaneInfo.Push(vp->mClipHeightDirection != 0.f || vp->mClipLine.X > -10000000.0f); return Bind(mUploadIndex++); } @@ -169,5 +170,6 @@ void GLViewpointBuffer::Clear() { // Index 0 is reserved for the 2D projection. mUploadIndex = 1; + mClipPlaneInfo.Resize(1); } diff --git a/src/gl/data/gl_viewpointbuffer.h b/src/gl/data/gl_viewpointbuffer.h index 208a42a5d..3ec1093df 100644 --- a/src/gl/data/gl_viewpointbuffer.h +++ b/src/gl/data/gl_viewpointbuffer.h @@ -12,6 +12,7 @@ class GLViewpointBuffer unsigned int mLastMappedIndex; unsigned int mByteSize; void * mBufferPointer; + TArray mClipPlaneInfo; unsigned int m2DWidth = ~0u, m2DHeight = ~0u;