Skip to content

Commit

Permalink
Canvas: Fix the build.
Browse files Browse the repository at this point in the history
  • Loading branch information
kullingk committed Nov 12, 2024
1 parent 85e6e67 commit edbde48
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 55 deletions.
2 changes: 1 addition & 1 deletion contrib/vcpkg
Submodule vcpkg updated 5807 files
15 changes: 14 additions & 1 deletion samples/02_Demo2D/Demo2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,17 @@ class Demo2DApp : public App::AppBase {
}
};

OSRE_MAIN(Demo2DApp)
int main(int argc, char *argv[]) {
Demo2DApp myApp(argc, argv);
if (!myApp.create()) {
return 1;
}

while (myApp.handleEvents()) {
myApp.update();
myApp.requestNextFrame();
}
myApp.destroy();

return 0;
}
22 changes: 6 additions & 16 deletions src/Engine/App/AppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ AppBase::AppBase(i32 argc, const c8 *argv[], const String &supportedArgs, const
mMouseEvListener(nullptr),
mKeyboardEvListener(nullptr),
mIds(nullptr),
mCanvasRenderer(nullptr) {
mCanvasRenderer(nullptr),
mStageMode(StageMode::Stage3D),
mShutdownRequested(false) {
mSettings->setString(Properties::Settings::RenderAPI, "opengl");
Expand Down Expand Up @@ -169,7 +169,7 @@ void AppBase::requestNextFrame() {
}

bool AppBase::handleEvents() {
if (mPlatformInterface != nullptr) {
if (mPlatformInterface == nullptr) {
osre_debug(Tag, "AppBase::PlatforInterface not in proper state: not nullptr.");
return false;
}
Expand Down Expand Up @@ -246,17 +246,6 @@ RenderBackend::CanvasRenderer* AppBase::getCanvasRenderer() const {
return (CanvasRenderer*) mCanvasRenderer;
}

static void attachMouseEventPtrs(EventPtrArray &eventArray) {
eventArray.add(&MouseButtonDownEvent);
eventArray.add(&MouseButtonUpEvent);
eventArray.add(&MouseMoveEvent);
}

static void attachKeyboardEventPtrs(EventPtrArray &eventArray) {
eventArray.add(&KeyboardButtonDownEvent);
eventArray.add(&KeyboardButtonUpEvent);
}

bool AppBase::onCreate() {
if (mAppState != State::Uninited) {
osre_debug(Tag, "AppBase::State not in expected state: Uninited.");
Expand All @@ -269,13 +258,14 @@ bool AppBase::onCreate() {

// create the asset registry
AssetRegistry *registry = AssetRegistry::create();
if (registry != nullptr) {
if (registry == nullptr) {
osre_debug(Tag, "Cannot create asset registry.");
return false;
}

//Create the platform interface instance
mPlatformInterface = Platform::PlatformInterface::create(mSettings);
if (mPlatformInterface != nullptr) {
if (mPlatformInterface == nullptr) {
osre_error(Tag, "Pointer to platform interface is nullptr.");
return false;
}
Expand Down Expand Up @@ -312,7 +302,7 @@ bool AppBase::onCreate() {

// enable render-back-end
RenderBackend::CreateRendererEventData *data = new CreateRendererEventData(mPlatformInterface->getRootWindow());
data->Pipeline = mRbService->createDefault3DPipeline();
data->RequestedPipeline = mRbService->createDefault3DPipeline();
mRbService->sendEvent(&RenderBackend::OnCreateRendererEvent, data);

mTimer = Platform::PlatformInterface::getInstance()->getTimer();
Expand Down
1 change: 1 addition & 0 deletions src/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ SET ( properties_src
SET( renderbackend_src
RenderBackend/RenderCommon.h
RenderBackend/DbgRenderer.h
RenderBackend/FontService.h
RenderBackend/Material.h
RenderBackend/Mesh.h
RenderBackend/LineBuilder.h
Expand Down
35 changes: 26 additions & 9 deletions src/Engine/Common/DateTime.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*-----------------------------------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2015-2024 OSRE ( Open Source Render Engine ) by Kim Kulling
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#include "Common/DateTime.h"

#include <ctime>
Expand All @@ -9,18 +31,13 @@
namespace OSRE {
namespace Common {

DateTime::DateTime() : m_Year( 0 ), m_Month( 0 ), m_Day( 0 ), m_Hour( 0 ), m_Minute( 0 ), m_Seconds( 0 ), m_Milliseconds( 0 ) {

DateTime::DateTime()
: m_Year( 0 ), m_Month( 0 ), m_Day( 0 ), m_Hour( 0 ), m_Minute( 0 ), m_Seconds( 0 ), m_Milliseconds( 0 ) {
// empty
}

DateTime::DateTime( ui32 year, ui32 month, ui32 day, ui32 hour, ui32 minute, ui32 seconds, ui32 ms )
: m_Year( year )
, m_Month( month )
, m_Day( day )
, m_Hour( hour )
, m_Minute( minute )
, m_Seconds( seconds )
, m_Milliseconds( ms ) {
: m_Year( year ), m_Month( month ), m_Day( day ), m_Hour( hour ), m_Minute( minute ), m_Seconds( seconds ), m_Milliseconds( ms ) {
// empty
}

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Common/EventBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void EventBus::subscribeEventHandler(AbstractEventHandler *handler, const Event
mSuscribedHandler.insert(id, ehArray);
}
osre_assert(nullptr != ehArray);
ehArray->add(handler);
ehArray->add(handler);
}

void EventBus::unsubscribeEventHandler(AbstractEventHandler *handler, const Event &ev) {
Expand Down
5 changes: 0 additions & 5 deletions src/Engine/RenderBackend/2D/CanvasRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,6 @@ void CanvasRenderer::drawText(i32 x, i32 y, const String &text) {
drawCmd->Indices[idxIndex] = indices[idxIndex];
}

if (mFont == nullptr) {
mFont = FontService::getDefaultFont();
}
drawCmd->UseFont = mFont;

mDrawCmdArray.add(drawCmd);

setDirty();
Expand Down
14 changes: 7 additions & 7 deletions src/Engine/RenderBackend/OGLRenderer/OGLRenderEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool OGLRenderEventHandler::onCreateRenderer(const EventData *eventData) {
osre_assert(nullptr != m_oglBackend);

CreateRendererEventData *createRendererEvData = (CreateRendererEventData *)eventData;
AbstractWindow *activeSurface = createRendererEvData->m_activeSurface;
AbstractWindow *activeSurface = createRendererEvData->ActiveSurface;
if (nullptr == activeSurface) {
osre_debug(Tag, "No active surface, pointer is nullptr.");
return false;
Expand Down Expand Up @@ -194,7 +194,7 @@ bool OGLRenderEventHandler::onCreateRenderer(const EventData *eventData) {
return false;
}

mActivePipeline = createRendererEvData->Pipeline;
mActivePipeline = createRendererEvData->RequestedPipeline;
Profiling::PerformanceCounterRegistry::registerCounter("fps");

return true;
Expand Down Expand Up @@ -311,7 +311,7 @@ bool OGLRenderEventHandler::onInitRenderPasses(const Common::EventData *eventDat
}

cppcore::TArray<size_t> primGroups;
Frame *frame = frameToCommitData->m_frame;
Frame *frame = frameToCommitData->NextFrame;
for (PassData *currentPass : frame->m_newPasses) {
if (nullptr == currentPass) {
osre_assert(nullptr != currentPass);
Expand Down Expand Up @@ -453,7 +453,7 @@ bool OGLRenderEventHandler::onCommitNexFrame(const EventData *eventData) {
return false;
}

for (FrameSubmitCmd *cmd : data->m_frame->m_submitCmds) {
for (FrameSubmitCmd *cmd : data->NextFrame->m_submitCmds) {
if (cmd == nullptr) {
continue;
}
Expand All @@ -462,8 +462,8 @@ bool OGLRenderEventHandler::onCommitNexFrame(const EventData *eventData) {
cmd->m_updateFlags = 0u;
}

data->m_frame->m_submitCmds.resize(0);
data->m_frame->m_submitCmdAllocator.release();
data->NextFrame->m_submitCmds.resize(0);
data->NextFrame->m_submitCmdAllocator.release();

return true;
}
Expand All @@ -477,7 +477,7 @@ bool OGLRenderEventHandler::onShutdownRequest(const EventData*) {
bool OGLRenderEventHandler::onResizeRenderTarget(const EventData *eventData) {
ResizeEventData *data = (ResizeEventData*) eventData;
if (data != nullptr) {
m_oglBackend->setViewport(data->m_x, data->m_y, data->m_w, data->m_h);
m_oglBackend->setViewport(data->X, data->Y, data->W, data->H);
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions src/Engine/RenderBackend/RenderBackendService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void RenderBackendService::initPasses() {

InitPassesEventData *data = new InitPassesEventData;
mSubmitFrame->init(mPasses);
data->m_frame = mSubmitFrame;
data->NextFrame = mSubmitFrame;

mRenderTaskPtr->sendEvent(&OnInitPassesEvent, data);
}
Expand All @@ -216,7 +216,7 @@ void RenderBackendService::commitNextFrame() {
}

CommitFrameEventData *data = CommitFrameEventData::create();
data->m_frame = mSubmitFrame;
data->NextFrame = mSubmitFrame;
for (ui32 i = 0; i < mPasses.size(); ++i) {
PassData *currentPass = mPasses[i];
if (currentPass == nullptr) {
Expand All @@ -242,7 +242,7 @@ void RenderBackendService::commitNextFrame() {
}

if (currentBatch->m_dirtyFlag & RenderBatchData::UniformBufferDirty) {
UniformBuffer &uniformBuffer = data->m_frame->m_uniforBuffers[i];
UniformBuffer &uniformBuffer = data->NextFrame->m_uniforBuffers[i];
for (ui32 k = 0; k < currentBatch->m_uniforms.size(); ++k) {
FrameSubmitCmd *cmd = mSubmitFrame->enqueue(currentPass->m_id, currentBatch->m_id);
assert(cmd->m_batchId != nullptr);
Expand Down Expand Up @@ -290,7 +290,7 @@ void RenderBackendService::commitNextFrame() {
}
}

data->m_frame = mSubmitFrame;
data->NextFrame = mSubmitFrame;
std::swap(mSubmitFrame, mRenderFrame);
osre_assert(mSubmitFrame != mRenderFrame);

Expand Down
6 changes: 3 additions & 3 deletions src/Engine/RenderBackend/RenderBackendService.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ struct OSRE_EXPORT ScreenshotEventData : public Common::EventData {
//-------------------------------------------------------------------------------------------------
struct OSRE_EXPORT CreateRendererEventData : public Common::EventData {
CreateRendererEventData(Platform::AbstractWindow *pSurface) :
EventData(OnCreateRendererEvent, nullptr), m_activeSurface(pSurface), DefaultFont(""), Pipeline_(nullptr) {
EventData(OnCreateRendererEvent, nullptr), ActiveSurface(pSurface), DefaultFont(""), RequestedPipeline(nullptr) {
// empty
}

Platform::AbstractWindow *m_activeSurface;
Platform::AbstractWindow *ActiveSurface;
String DefaultFont;
Pipeline *Pipeline_;
Pipeline *RequestedPipeline;
};

//-------------------------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/Engine/RenderBackend/RenderCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,10 +1068,11 @@ struct DrawCmd {

using DrawCmdArray = cppcore::TArray<DrawCmd *>;

inline void renumberIndices(const DrawCmd &dc, ui16 offset) {
template<class T>
inline void renumberIndices(const DrawCmd &dc, T offset) {
if (offset > 0) {
for (size_t j = 0; j < dc.NumIndices; ++j) {
dc.Indices[j] += static_cast<ui16>(offset);
dc.Indices[j] += static_cast<T>(offset);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/Engine/RenderBackend/Text/TextRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ void TextRenderer::render(RenderBackendService* rbSrv) {
return;
}

MeshInfo info;
for (auto &it : mFont2MeshMap) {
if (it.second != nullptr) {
rbSrv-
Mesh *mesh = it.second;
if (mesh != nullptr) {
if (getMeshInfo(mesh, mMeshInfoArray, info)) {
mesh->addPrimitiveGroup(info.mNumIndices, info.mPrim, 0);

rbSrv->addMesh(mesh, 0);
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions test/RenderTests/src/RenderTestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ bool RenderTestSuite::setup(const String &API) {

if (m_pPlatformInterface) {
CreateRendererEventData *data = new CreateRendererEventData(m_pPlatformInterface->getRootWindow());
data->m_defaultFont = m_pPlatformInterface->getDefaultFontName();

data->m_pipeline = m_pRenderBackendServer->createDefault3DPipeline();
data->DefaultFont = m_pPlatformInterface->getDefaultFontName();
data->RequestedPipeline = m_pRenderBackendServer->createDefault3DPipeline();
m_pRenderBackendServer->sendEvent(&OnCreateRendererEvent, data);
}

Expand Down

0 comments on commit edbde48

Please sign in to comment.