mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-05-03 18:14:57 +00:00
stuff
This commit is contained in:
@@ -454,6 +454,7 @@ void BgfxGraphicsBackend::Initialize(void* window, const GraphicsConfig& config)
|
||||
if (initialized_) {
|
||||
return;
|
||||
}
|
||||
frameCount_ = 0;
|
||||
(void)config;
|
||||
|
||||
SDL_Window* sdlWindow = static_cast<SDL_Window*>(window);
|
||||
@@ -609,6 +610,7 @@ void BgfxGraphicsBackend::Shutdown() {
|
||||
DestroyUniforms();
|
||||
bgfx::shutdown();
|
||||
initialized_ = false;
|
||||
frameCount_ = 0;
|
||||
}
|
||||
|
||||
void BgfxGraphicsBackend::RecreateSwapchain(uint32_t width, uint32_t height) {
|
||||
@@ -700,6 +702,13 @@ bgfx::TextureHandle BgfxGraphicsBackend::LoadTextureFromFile(const std::string&
|
||||
if (logger_) {
|
||||
logger_->Trace("BgfxGraphicsBackend", "LoadTextureFromFile", "path=" + path);
|
||||
}
|
||||
if (!HasProcessedFrame()) {
|
||||
if (logger_) {
|
||||
logger_->Error("BgfxGraphicsBackend::LoadTextureFromFile: Attempted to load texture BEFORE first "
|
||||
"bgfx::frame(). Call BeginFrame()+EndFrame() before loading textures. path=" + path);
|
||||
}
|
||||
return BGFX_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
@@ -1063,7 +1072,12 @@ bool BgfxGraphicsBackend::EndFrame(GraphicsDeviceHandle device) {
|
||||
if (!initialized_) {
|
||||
return false;
|
||||
}
|
||||
bgfx::frame();
|
||||
const uint32_t frameNumber = bgfx::frame();
|
||||
frameCount_ = frameNumber + 1;
|
||||
if (logger_) {
|
||||
logger_->Trace("BgfxGraphicsBackend", "EndFrame",
|
||||
"frameNumber=" + std::to_string(frameNumber));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,10 @@ public:
|
||||
void* GetGraphicsQueue() const override;
|
||||
|
||||
private:
|
||||
friend bgfx::TextureHandle LoadTextureFromFileForTest(const BgfxGraphicsBackend& backend,
|
||||
const std::string& path,
|
||||
uint64_t samplerFlags);
|
||||
|
||||
// Texture memory budget tracker to prevent GPU memory exhaustion
|
||||
class TextureMemoryTracker {
|
||||
public:
|
||||
@@ -142,6 +146,7 @@ private:
|
||||
void ApplyMaterialXUniforms(const std::array<float, 16>& modelMatrix);
|
||||
void DestroyPipelines();
|
||||
void DestroyBuffers();
|
||||
bool HasProcessedFrame() const { return frameCount_ > 0; }
|
||||
|
||||
std::shared_ptr<IConfigService> configService_;
|
||||
std::shared_ptr<IPlatformService> platformService_;
|
||||
@@ -156,6 +161,7 @@ private:
|
||||
uint32_t viewportWidth_ = 0;
|
||||
uint32_t viewportHeight_ = 0;
|
||||
bool initialized_ = false;
|
||||
uint32_t frameCount_ = 0;
|
||||
bgfx::ViewId viewId_ = 0;
|
||||
PlatformHandleInfo platformHandleInfo_{};
|
||||
bgfx::PlatformData platformData_{};
|
||||
|
||||
@@ -113,6 +113,13 @@ void GraphicsService::UploadVertexData(const std::vector<core::Vertex>& vertices
|
||||
throw std::runtime_error("Graphics service not initialized");
|
||||
}
|
||||
|
||||
if (vertexBuffer_ && backend_) {
|
||||
logger_->Trace("GraphicsService", "UploadVertexData",
|
||||
"destroyingPreviousVertexBuffer=true");
|
||||
backend_->DestroyBuffer(device_, vertexBuffer_);
|
||||
vertexBuffer_ = nullptr;
|
||||
}
|
||||
|
||||
// Convert vertices to bytes
|
||||
std::vector<uint8_t> data(sizeof(core::Vertex) * vertices.size());
|
||||
std::memcpy(data.data(), vertices.data(), data.size());
|
||||
@@ -127,6 +134,13 @@ void GraphicsService::UploadIndexData(const std::vector<uint16_t>& indices) {
|
||||
throw std::runtime_error("Graphics service not initialized");
|
||||
}
|
||||
|
||||
if (indexBuffer_ && backend_) {
|
||||
logger_->Trace("GraphicsService", "UploadIndexData",
|
||||
"destroyingPreviousIndexBuffer=true");
|
||||
backend_->DestroyBuffer(device_, indexBuffer_);
|
||||
indexBuffer_ = nullptr;
|
||||
}
|
||||
|
||||
// Convert indices to bytes
|
||||
std::vector<uint8_t> data(sizeof(uint16_t) * indices.size());
|
||||
std::memcpy(data.data(), indices.data(), data.size());
|
||||
|
||||
Reference in New Issue
Block a user