Skip to content

Commit

Permalink
Tbui integration (#235)
Browse files Browse the repository at this point in the history
Initial Turbobadger integration by Robert Campbell
---------

Co-authored-by: Robert Campbell <waprave@gmail.com>
  • Loading branch information
kaffeewolf and jayrulez authored Dec 1, 2024
1 parent da5ff13 commit 739da61
Show file tree
Hide file tree
Showing 265 changed files with 5,438 additions and 2 deletions.
3 changes: 2 additions & 1 deletion authors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Radon Labs GmbH, Berlin/Germany

Johannes Hirche
Gustav Sterbrant
Fredrik Lindahl
Fredrik Lindahl
Robert Campbell
1 change: 1 addition & 0 deletions code/addons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ add_subdirectory(scripting)
#add_subdirectory(staticui)
add_subdirectory(tinyxml)
add_subdirectory(nsharp)
add_subdirectory(tbui)
2 changes: 1 addition & 1 deletion code/addons/graphicsfeature/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nebula_begin_module(graphicsfeature)
nebula_flatc(SYSTEM graphicsfeature/graphicsfeatureschema.fbs graphicsfeature/terrainschema.fbs graphicsfeature/vegetationschema.fbs)
fips_deps(render application dynui nflatbuffer)
fips_deps(render application dynui tbui nflatbuffer)
target_precompile_headers(graphicsfeature PRIVATE <application/stdneb.h>)
fips_ide_group(features)
fips_files(
Expand Down
4 changes: 4 additions & 0 deletions code/addons/graphicsfeature/graphicsfeatureunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "graphics/cameracontext.h"
#include "visibility/visibilitycontext.h"
#include "dynui/imguicontext.h"
#include "tbui/tbuicontext.h"
#include "characters/charactercontext.h"
#include "dynui/im3d/im3dcontext.h"
#include "appgame/gameapplication.h"
Expand Down Expand Up @@ -159,6 +160,7 @@ GraphicsFeatureUnit::OnActivate()
Im3d::Im3dContext::Create();
Dynui::ImguiContext::Create();
//StaticUI::StaticUIContext::Create();
TBUI::TBUIContext::Create();

CameraContext::Create();
ModelContext::Create();
Expand Down Expand Up @@ -290,6 +292,7 @@ GraphicsFeatureUnit::OnActivate()
Util::Array<Graphics::ViewIndependentCall> preLogicCalls =
{
Dynui::ImguiContext::NewFrame,
TBUI::TBUIContext::FrameUpdate,
CameraContext::UpdateCameras,
ModelContext::UpdateTransforms,
Characters::CharacterContext::UpdateAnimations,
Expand Down Expand Up @@ -380,6 +383,7 @@ GraphicsFeatureUnit::OnDeactivate()
Raytracing::RaytracingContext::Discard();
Im3d::Im3dContext::Discard();
Dynui::ImguiContext::Discard();
TBUI::TBUIContext::Discard();
FeatureUnit::OnDeactivate();
DestroyWindow(this->wnd);
this->gfxServer->DiscardStage(this->defaultStage);
Expand Down
37 changes: 37 additions & 0 deletions code/addons/tbui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#-------------------------------------------------------------------------------
# tbui module
#-------------------------------------------------------------------------------

nebula_begin_module(tbui)
fips_ide_group(addons)

fips_deps(render turbobadger)
target_precompile_headers(tbui PRIVATE <render/stdneb.h>)
target_include_directories(tbui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

fips_files(
tbuicontext.cc
tbuicontext.h
tbuiinputhandler.cc
tbuiinputhandler.h
tbuiview.cc
tbuiview.h
)

add_shaders(tbui.fx)

fips_dir(backend)
fips_files(
tbuibatch.h
tbuibitmap.cc
tbuibitmap.h
tbuiclipboard.cc
tbuifile.cc
tbuifile.h
tbuirenderer.cc
tbuirenderer.h
tbuisystem.cc
tbuivertex.h
)

nebula_end_module()
25 changes: 25 additions & 0 deletions code/addons/tbui/backend/tbuibatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
//------------------------------------------------------------------------------
/**
Turbobadger UI Batch
@copyright
(C) 2024 Individual contributors, see AUTHORS file
*/
//------------------------------------------------------------------------------
#include "coregraphics/buffer.h"
#include "coregraphics/texture.h"
#include "util/array.h"
#include "math/rectangle.h"
#include "tbuivertex.h"

//------------------------------------------------------------------------------
namespace TBUI
{
struct TBUIBatch
{
CoreGraphics::TextureId texture;
Util::Array<TBUIVertex> vertices;
Math::intRectangle clipRect;
};
} // namespace TBUI
85 changes: 85 additions & 0 deletions code/addons/tbui/backend/tbuibitmap.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//------------------------------------------------------------------------------
// backend/tbuibitmap.cc
// (C) 2024 Individual contributors, see AUTHORS file
//------------------------------------------------------------------------------
#include "render/stdneb.h"
#include "tbuibitmap.h"
#include "tbuirenderer.h"


namespace TBUI
{

//------------------------------------------------------------------------------
/*
*/
TBUIBitmap::TBUIBitmap(TBUIRenderer* renderer)
: renderer(renderer),
texture(CoreGraphics::InvalidTextureId)
{
}

//------------------------------------------------------------------------------
/*
*/
TBUIBitmap::~TBUIBitmap()
{
this->renderer->FlushBitmap(this);
CoreGraphics::DestroyTexture(this->texture);
this->texture = CoreGraphics::InvalidTextureId;
}

//------------------------------------------------------------------------------
/*
*/
bool
TBUIBitmap::Init(int width, int height, unsigned int* data)
{
this->width = width;
this->height = height;

CoreGraphics::TextureCreateInfo texInfo;
texInfo.name = "tbui_generated_texture"_atm;
texInfo.usage = CoreGraphics::TextureUsage::SampleTexture;
texInfo.tag = "tbui"_atm;
texInfo.data = data;
texInfo.dataSize = width * height * CoreGraphics::PixelFormat::ToSize(CoreGraphics::PixelFormat::SRGBA8);
texInfo.type = CoreGraphics::TextureType::Texture2D;
texInfo.format = CoreGraphics::PixelFormat::SRGBA8;
texInfo.width = width;
texInfo.height = height;

this->texture = CoreGraphics::CreateTexture(texInfo);

//SetData(data);
return true;
}

//------------------------------------------------------------------------------
/*
*/
int
TBUIBitmap::Width()
{
return this->width;
}

//------------------------------------------------------------------------------
/*
*/
int
TBUIBitmap::Height()
{
return this->height;
}

//------------------------------------------------------------------------------
/*
*/
void
TBUIBitmap::SetData(unsigned int* data)
{
const SizeT dataSize = this->width * this->height * CoreGraphics::PixelFormat::ToSize(CoreGraphics::PixelFormat::SRGBA8);
CoreGraphics::TextureUpdate(this->renderer->GetCmdBufferId(), this->texture, this->width, this->height, 0, 0, data, dataSize);
}
} // namespace TBUI
62 changes: 62 additions & 0 deletions code/addons/tbui/backend/tbuibitmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once
//------------------------------------------------------------------------------
/**
Turbobadger UI Bitmap
@copyright
(C) 2024 Individual contributors, see AUTHORS file
*/
//------------------------------------------------------------------------------
#include "coregraphics/texture.h"
#include "tb_renderer.h"

//------------------------------------------------------------------------------
namespace TBUI
{

class TBUIRenderer;

//------------------------------------------------------------------------------
class TBUIBitmap : public tb::TBBitmap
{
public:

///
TBUIBitmap(TBUIRenderer* renderer);

/** Note: Implementations for batched renderers should call TBRenderer::FlushBitmap
to make sure any active batch is being flushed before the bitmap is deleted. */
~TBUIBitmap() override;

///
bool Init(int width, int height, unsigned int* data);

///
int Width() override;
///
int Height() override;

/** Update the bitmap with the given data (in BGRA32 format).
Note: Implementations for batched renderers should call TBRenderer::FlushBitmap
to make sure any active batch is being flushed before the bitmap is changed. */
void SetData(unsigned int* data) override;

///
CoreGraphics::TextureId GetTexture() const;

private:
TBUIRenderer* renderer;
int width = 0;
int height = 0;
CoreGraphics::TextureId texture;
};

//------------------------------------------------------------------------------
/*
*/
inline CoreGraphics::TextureId
TBUIBitmap::GetTexture() const
{
return this->texture;
}
} // namespace TBUI
39 changes: 39 additions & 0 deletions code/addons/tbui/backend/tbuiclipboard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//------------------------------------------------------------------------------
// backend/tbuiclipboard.cc
// (C) 2024 Individual contributors, see AUTHORS file
//------------------------------------------------------------------------------
#include "render/stdneb.h"
#include "tb_system.h"

namespace tb
{

// == TBClipboard =====================================

TBStr clipboard; ///< Obviosly not a full implementation since it ignores the OS :)

void
TBClipboard::Empty()
{
clipboard.Clear();
}

bool
TBClipboard::HasText()
{
return !clipboard.IsEmpty();
}

bool
TBClipboard::SetText(const char* text)
{
return clipboard.Set(text);
}

bool
TBClipboard::GetText(TBStr& text)
{
return text.Set(clipboard);
}

} // namespace tb
76 changes: 76 additions & 0 deletions code/addons/tbui/backend/tbuifile.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//------------------------------------------------------------------------------
// backend/tbuifile.cc
// (C) 2024 Individual contributors, see AUTHORS file
//------------------------------------------------------------------------------
#include "render/stdneb.h"
#include "io/ioserver.h"
#include "io/stream.h"
#include "tbuifile.h"
#include "tb_system.h"

namespace tb
{
//------------------------------------------------------------------------------
/**
*/
TBFile*
TBFile::Open(const char* filename, TBFileMode mode)
{
if (mode != TBFileMode::MODE_READ)
return nullptr;

TBUI::TBUIFile* file = new ::TBUI::TBUIFile(filename, IO::Stream::AccessMode::ReadAccess);
if (!file->IsOpen())
{
file = nullptr;
}

return file;
}
} // namespace tb

namespace TBUI
{
//------------------------------------------------------------------------------
/**
*/
TBUIFile::TBUIFile(const Util::String& filePath, IO::Stream::AccessMode accessMode)
: fileStream(nullptr)
{
this->fileStream = IO::IoServer::Instance()->CreateStream(filePath).downcast<IO::FileStream>();
this->fileStream->SetAccessMode(accessMode);
if (!this->fileStream->Open())
{
this->fileStream = nullptr;
}
}

//------------------------------------------------------------------------------
/**
*/
TBUIFile::~TBUIFile()
{
if (this->fileStream->IsOpen())
{
this->fileStream->Close();
}
}

//------------------------------------------------------------------------------
/**
*/
long
TBUIFile::Size()
{
return this->fileStream->GetSize();
}

//------------------------------------------------------------------------------
/**
*/
size_t
TBUIFile::Read(void* buf, size_t elemSize, size_t count)
{
return this->fileStream->Read(buf, count);
}
} // namespace TBUI
Loading

0 comments on commit 739da61

Please sign in to comment.