-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Created by Marc Rousavy on 21.02.24. | ||
// | ||
|
||
#include "EngineWrapper.h" | ||
|
||
#include <filament/Engine.h> | ||
#include <filament/SwapChain.h> | ||
|
||
namespace margelo { | ||
|
||
EngineWrapper::EngineWrapper() { | ||
_engine = Engine::create(filament::Engine::Backend::OPENGL); | ||
} | ||
|
||
EngineWrapper::~EngineWrapper() { | ||
if (_swapChain) { | ||
_engine->destroy(_swapChain); | ||
} | ||
_engine->destroy(&_engine); | ||
} | ||
|
||
void EngineWrapper::setSurfaceProvider(std::shared_ptr<SurfaceProvider> surfaceProvider) { | ||
_surfaceProvider = surfaceProvider; | ||
std::shared_ptr<Surface> surface = surfaceProvider->getSurfaceOrNull(); | ||
if (surface != nullptr) { | ||
setSurface(surface); | ||
} | ||
|
||
Listener listener = surfaceProvider->addOnSurfaceChangedListener(SurfaceProvider::Callback { | ||
.onSurfaceCreated = [=] (std::shared_ptr<Surface> surface) { | ||
this->setSurface(surface); | ||
}, | ||
.onSurfaceDestroyed = [=] (std::shared_ptr<Surface> surface) { | ||
this->destroySurface(); | ||
} | ||
}); | ||
_listener = std::make_unique<Listener>(std::move(listener)); | ||
} | ||
|
||
void EngineWrapper::setSurface(std::shared_ptr<Surface> surface) { | ||
void* nativeWindow = surface->getSurface(); | ||
if (_swapChain == nullptr || _swapChain->getNativeWindow() != nativeWindow) { | ||
destroySurface(); | ||
_swapChain = _engine->createSwapChain(nativeWindow); | ||
} | ||
} | ||
|
||
void EngineWrapper::destroySurface() { | ||
if (_swapChain != nullptr) { | ||
_engine->destroy(_swapChain); | ||
_swapChain = nullptr; | ||
} | ||
} | ||
|
||
} // margelo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Created by Marc Rousavy on 21.02.24. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <filament/Engine.h> | ||
#include <filament/SwapChain.h> | ||
#include "Surface.h" | ||
#include "SurfaceProvider.h" | ||
|
||
namespace margelo { | ||
|
||
using namespace filament; | ||
|
||
class EngineWrapper { | ||
public: | ||
explicit EngineWrapper(); | ||
~EngineWrapper(); | ||
|
||
void setSurfaceProvider(std::shared_ptr<SurfaceProvider> surfaceProvider); | ||
|
||
private: | ||
void setSurface(std::shared_ptr<Surface> surface); | ||
void destroySurface(); | ||
|
||
private: | ||
Engine* _engine; | ||
SwapChain* _swapChain; | ||
std::shared_ptr<SurfaceProvider> _surfaceProvider; | ||
std::unique_ptr<Listener> _listener; | ||
}; | ||
|
||
} // margelo |