Skip to content

Commit

Permalink
feat: add full screen support on demand
Browse files Browse the repository at this point in the history
bugfix: resolve broken normals/tangents for animated meshes
bugfix: fix memory corruption for GraphicsBufffer.

Signed-off-by: Michael Pollind <mpollind@gmail.com>
  • Loading branch information
pollend committed Nov 5, 2023
1 parent 5b18048 commit 1ae76a7
Show file tree
Hide file tree
Showing 25 changed files with 397 additions and 520 deletions.
4 changes: 0 additions & 4 deletions HPL2/include/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,9 @@ namespace hpl {
void CheckAndBroadcastDeviceChange();

bool mbGameIsDone;

bool mbRenderOnce;

bool mbPaused;

float mfFrameTime;

double mfGameTime;

iLowLevelEngineSetup *mpGameSetup;
Expand Down
9 changes: 5 additions & 4 deletions HPL2/include/graphics/GraphicsBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ namespace hpl {
break;
}
case BufferType::MappedBuffer: {
std::copy(buf.begin(), buf.end(), reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + m_byteOffset + targetOffset);
std::copy(buf.begin(), buf.end(), reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + targetOffset);
break;
}
}
Expand All @@ -360,7 +360,7 @@ namespace hpl {
break;
}
case BufferType::MappedBuffer: {
std::copy(buf.begin(), buf.end(), reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + m_byteOffset + targetOffset);
std::copy(buf.begin(), buf.end(), reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + targetOffset);
break;
}
}
Expand Down Expand Up @@ -393,10 +393,11 @@ namespace hpl {
}

T Get(uint32_t index) {
const size_t targetOffset = (m_byteOffset + (index * m_byteStride));
switch(m_asset->m_type) {
case BufferType::ResourceBuffer: {
ASSERT(m_asset->m_buffer.begin() + (m_byteOffset + (index * m_byteStride)) < m_asset->m_buffer.end());
return *reinterpret_cast<T*>(m_asset->m_buffer.data() + (m_byteOffset + (index * m_byteStride)));
ASSERT(m_asset->m_buffer.begin() + targetOffset < m_asset->m_buffer.end());
return *reinterpret_cast<T*>(m_asset->m_buffer.data() + targetOffset);
}
case BufferType::MappedBuffer: {
ASSERT(false);
Expand Down
23 changes: 0 additions & 23 deletions HPL2/include/graphics/LowLevelGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ namespace hpl {
public:
virtual ~iLowLevelGraphics(){}


/////////////////////////////////////////////////////
/////////////// GENERAL SETUP ///////////////////////
/////////////////////////////////////////////////////

virtual bool Init( int alWidth, int alHeight, int alDisplay, int alBpp, int abFullscreen, int alMultisampling,
eGpuProgramFormat aGpuProgramFormat, const tString& asWindowCaption,
const cVector2l &avWindowPos)=0;
Expand Down Expand Up @@ -354,11 +349,6 @@ namespace hpl {
[[deprecated("interface is deprecated")]]
virtual void DrawLineQuad(const cVector3f &avPos,const cVector2f &avSize, cColor aCol)=0;

/////////////////////////////////////////////////////
/////////// VERTEX BATCHING /////////////////////////
/////////////////////////////////////////////////////


[[deprecated("interface is deprecated")]]
virtual void AddVertexToBatch(const cVertex *apVtx)=0;

Expand Down Expand Up @@ -395,18 +385,5 @@ namespace hpl {

[[deprecated("interface is deprecated")]]
virtual void ClearBatch()=0;

/////////////////////////////////////////////////////
/////////// STATIC VARIABLES /////////////////////////
/////////////////////////////////////////////////////

[[deprecated("interface is deprecated")]]
static void SetForceShaderModel3And4Off(bool abX){ mbForceShaderModel3And4Off = abX;}

[[deprecated("interface is deprecated")]]
static bool GetForceShaderModel3And4Off(){ return mbForceShaderModel3And4Off;}

protected:
static bool mbForceShaderModel3And4Off;
};
};
5 changes: 0 additions & 5 deletions HPL2/include/impl/LowLevelGraphicsSDL.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ namespace hpl {
cLowLevelGraphicsSDL();
~cLowLevelGraphicsSDL();

/////////////////////////////////////////////////////
/////////////// GENERAL SETUP ///////////////////////
/////////////////////////////////////////////////////

[[deprecated("replaced with BGFX")]]
bool Init( int alWidth, int alHeight, int alDisplay, int alBpp, int abFullscreen, int alMultisampling,
eGpuProgramFormat aGpuProgramFormat,const tString& asWindowCaption,
Expand Down Expand Up @@ -114,7 +110,6 @@ namespace hpl {
[[deprecated("replaced with BGFX")]]
void ClearFrameBuffer(tClearFrameBufferFlag aFlags);

[[deprecated("replaced with BGFX")]]
void SetClearColor(const cColor& aCol);
[[deprecated("replaced with BGFX")]]
void SetClearDepth(float afDepth);
Expand Down
2 changes: 2 additions & 0 deletions HPL2/include/scene/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace hpl {
bool WorldExists(cWorld* apWorld);
cViewport* PrimaryViewport();

inline std::span<cViewport*> Viewports() { return m_viewports; }

private:
void Render3DGui(const ForgeRenderer::Frame&,cViewport* apViewPort,cFrustum *apFrustum,float afTimeStep);
void RenderScreenGui(const ForgeRenderer::Frame&, cViewport* apViewPort, float afTimeStep);
Expand Down
42 changes: 9 additions & 33 deletions HPL2/include/scene/Viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "Common_3/Utilities/Interfaces/ILog.h"
#include <FixPreprocessor.h>

#include "math/Uuid.h"

namespace hpl {

class cScene;
Expand All @@ -57,7 +59,9 @@ namespace hpl {
class cViewport final {
HPL_RTTI_CLASS(cViewport, "{f5d42b52-6e84-4486-afa0-a5888f3513a0}")
public:
static constexpr Uuid PrimaryViewportTag = hpl::detail::From("{f5d42b52-6e84-4486-afa0-a5888f3513a0}");
static constexpr size_t MaxViewportHandles = 9;

using ResizeEvent = hpl::Event<hpl::cVector2l&>;
using ViewportDispose = hpl::Event<>;
using ViewportChange = hpl::Event<>;
Expand Down Expand Up @@ -159,6 +163,9 @@ namespace hpl {
inline void SignalDraw(PostSolidDrawPacket& payload) { m_postSolidDraw.Signal(payload);}
inline void SignalDraw(PostTranslucenceDrawPacket& payload) { m_postTranslucenceDraw.Signal(payload);}

inline void SetTag(const Uuid& tag) { m_tag = tag; }
inline Uuid Tag() { return m_tag; }

private:
bool mbActive;
bool mbVisible;
Expand All @@ -176,6 +183,7 @@ namespace hpl {
std::shared_ptr<hpl::Image> m_image;

cVector2l m_size = { 0, 0 };
Uuid m_tag;

IUpdateEventLoop::UpdateEvent::Handler m_updateEventHandler;

Expand All @@ -191,6 +199,7 @@ namespace hpl {

std::unique_ptr<cRenderSettings> mpRenderSettings;


template<typename TData>
friend class UniqueViewportData;
};
Expand Down Expand Up @@ -267,37 +276,4 @@ namespace hpl {
std::array<std::unique_ptr<TData>, cViewport::MaxViewportHandles> m_targets;
};

class PrimaryViewport final {
HPL_RTTI_CLASS(PrimaryViewport, "{98010986-a128-44ec-b0f8-45e69e5a7786}")
public:
using ViewportChange = hpl::Event<>;

PrimaryViewport();
PrimaryViewport(window::NativeWindowWrapper& window);
PrimaryViewport(const PrimaryViewport& other) = delete;
PrimaryViewport(PrimaryViewport&& other) = delete;
PrimaryViewport& operator=(const PrimaryViewport& other) = delete;
PrimaryViewport& operator=(PrimaryViewport&& other) = delete;

inline void ConnectViewportChanged(ViewportChange::Handler& handler) {
handler.Connect(m_viewportChanged);
}

inline void SetSize(const cVector2l& size) {
m_size = size;
m_dirtyViewport = true;
}
private:

void CreateEventHandler();

cVector2l m_size = { 0, 0 };
// LegacyRenderTarget m_renderTarget;
bool m_dirtyViewport = false;

IUpdateEventLoop::UpdateEvent::Handler m_updateEventHandler;
window::WindowEvent::Handler m_windowEventHandler;
ViewportChange m_viewportChanged;
};

}; // namespace hpl
1 change: 0 additions & 1 deletion HPL2/include/system/Bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace hpl {
private:
static void BootstrapThreadHandler(void* _userData);

std::unique_ptr<PrimaryViewport> m_primaryViewport;
hpl::ForgeRenderer m_renderer;
std::unique_ptr<hpl::DebugDraw> m_debug;
std::unique_ptr<GraphicsAllocator> m_graphicsAlloc;
Expand Down
12 changes: 7 additions & 5 deletions HPL2/include/windowing/NativeWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace hpl::window {
WindowStatusWindowMaximized = 0x08,
WindowStatusVisible = 0x10,
};
enum class WindowFullscreen : uint8_t { Window, Fullscreen, Borderless };

struct InternalEvent {
union {
Expand All @@ -90,7 +91,6 @@ namespace hpl::window {
};
using WindowEvent = hpl::Event<WindowEventPayload&>;

enum class WindowType : uint8_t { Window, Fullscreen, Borderless };
namespace internal {

using WindowInternalEvent = hpl::Event<InternalEvent&>;
Expand All @@ -109,6 +109,7 @@ namespace hpl::window {
void SetWindowTitle(NativeWindowHandler& handler, const std::string_view title);
void SetWindowSize(NativeWindowHandler& handler, const cVector2l& size);
void SetWindowBrightness(NativeWindowHandler& handler, float brightness);
void SetWindowFullscreen(NativeWindowHandler& handler, WindowFullscreen flag);

WindowHandle ForgeWindowHandle(NativeWindowHandler& handler);
cVector2l GetWindowSize(NativeWindowHandler& handler);
Expand Down Expand Up @@ -175,6 +176,11 @@ namespace hpl::window {
internal::ConnectInternalEventHandler(m_impl, handler);
}

inline void SetWindowFullscreen(WindowFullscreen flag) {
ASSERT(m_impl && "NativeWindowHandle is null");
return internal::SetWindowFullscreen(m_impl, flag);
}

inline internal::WindowInternalEvent& NativeInternalEvent() {
ASSERT(m_impl && "NativeWindowHandle is null");
return internal::NativeInternalEvent(m_impl);
Expand Down Expand Up @@ -226,10 +232,6 @@ namespace hpl::window {
internal::UnconstrainCursor(m_impl);
}

inline WindowType GetWindowType() {
return WindowType::Window;
}

private:
internal::NativeWindowHandler m_impl = internal::NativeWindowHandler();
};
Expand Down
15 changes: 6 additions & 9 deletions HPL2/sources/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ namespace hpl {
//Init the resources
mpResources->Init(mpGraphics,mpSystem, mpSound,mpScene,mpGui, mpPhysics);

if(apVars->mGraphics.mbFullscreen) {
Interface<window::NativeWindowWrapper>::Get()->SetWindowFullscreen(window::WindowFullscreen::Borderless);
} else {
Interface<window::NativeWindowWrapper>::Get()->SetWindowFullscreen(window::WindowFullscreen::Window);
Interface<window::NativeWindowWrapper>::Get()->SetWindowSize(cVector2l(apVars->mGraphics.mvScreenSize.x, apVars->mGraphics.mvScreenSize.y));
}
//Init the graphics
mpGraphics->Init( apVars->mGraphics.mvScreenSize.x,
apVars->mGraphics.mvScreenSize.y,
Expand All @@ -289,7 +295,6 @@ namespace hpl {
apVars->mGraphics.msWindowCaption,
apVars->mGraphics.mvWindowPosition,
mpResources,alHplSetupFlags);
Interface<window::NativeWindowWrapper>::Get()->SetWindowSize(cVector2l(apVars->mGraphics.mvScreenSize.x, apVars->mGraphics.mvScreenSize.y));

//Init Sound
mpSound->Init(mpResources, apVars->mSound.mlSoundDeviceID,
Expand Down Expand Up @@ -403,14 +408,6 @@ namespace hpl {
Log("HPL Exit was successful!\n");
}

//-----------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////
// PUBLIC METHOD
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

int glClearUpdateCheck=0;
void cEngine::Run()
{
Expand Down
8 changes: 0 additions & 8 deletions HPL2/sources/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ namespace hpl {
Log("--------------------------------------------------------\n\n");
}

//-----------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

bool cGraphics::Init( int alWidth, int alHeight, int alDisplay, int alBpp, int abFullscreen,
int alMultisampling,eGpuProgramFormat aGpuProgramFormat,
Expand All @@ -135,7 +128,6 @@ namespace hpl {
// LowLevel Init
if(alHplSetupFlags & eHplSetup_Screen)
{
Log("Init lowlevel graphics: %dx%d disp:%d bpp:%d fs:%d ms:%d gpufmt:%d cap:'%s' pos:(%dx%d)\n",alWidth,alHeight,alDisplay,alBpp,abFullscreen,alMultisampling,aGpuProgramFormat, asWindowCaption.c_str(), avWindowPos.x,avWindowPos.y);
mpLowLevelGraphics->Init(alWidth,alHeight,alDisplay,alBpp,abFullscreen,alMultisampling,aGpuProgramFormat,asWindowCaption,
avWindowPos);
mbScreenIsSetup = true;
Expand Down
9 changes: 0 additions & 9 deletions HPL2/sources/graphics/LowLevelGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,4 @@

namespace hpl {

//////////////////////////////////////////////////////////////////////////
// STATIC DATA
//////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------

bool iLowLevelGraphics::mbForceShaderModel3And4Off = false;

//-----------------------------------------------------------------------
}
2 changes: 0 additions & 2 deletions HPL2/sources/impl/LowLevelGraphicsSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ namespace hpl {


SetWindowGrab(true);


//Turn off cursor as default
ShowCursor(false);

Expand Down
17 changes: 17 additions & 0 deletions HPL2/sources/platform/sdl2/SDL2NativeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@ namespace hpl::window::internal {
}


void SetWindowFullscreen(NativeWindowHandler& handler, WindowFullscreen flag) {
auto impl = static_cast<NativeWindowImpl*>(handler.Get());
InternalHandleCmd(*impl, [flag](NativeWindowImpl& impl) {
switch(flag) {
case WindowFullscreen::Fullscreen:
SDL_SetWindowFullscreen(impl.m_window, SDL_WINDOW_FULLSCREEN);
break;
case WindowFullscreen::Borderless:
SDL_SetWindowFullscreen(impl.m_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
break;
default:
SDL_SetWindowFullscreen(impl.m_window, 0);
break;
}
});
}

cVector2l GetWindowSize(NativeWindowHandler& handler) {
auto impl = static_cast<NativeWindowImpl*>(handler.Get());
ASSERT(impl->m_window && "Window is not initialized");
Expand Down
4 changes: 2 additions & 2 deletions HPL2/sources/scene/SubMeshEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ namespace hpl {
beginUpdateResource(&normalUpdateDesc);

GraphicsBuffer positionMapping(positionUpdateDesc);
GraphicsBuffer normalMapping(tangentUpdateDesc);
GraphicsBuffer tangentMapping(normalUpdateDesc);
GraphicsBuffer normalMapping(normalUpdateDesc);
GraphicsBuffer tangentMapping(tangentUpdateDesc);
auto targetPositionView = positionMapping.CreateStructuredView<float3>(0, targetPositionIt->stride());
auto targetTangentView = tangentMapping.CreateStructuredView<float3>(0, targetTangentIt->stride());
auto targetNormalView = normalMapping.CreateStructuredView<float3>(0, targetNormalIt->stride());
Expand Down
Loading

0 comments on commit 1ae76a7

Please sign in to comment.