Rename ExternalContext to Platform

Rename everything related.

Also Platform::create() returns a raw Driver* 
instead of a unique_ptr<Driver>. This is to
remove a dependency on <memory> in public
headers.
This commit is contained in:
Mathias Agopian
2018-10-03 16:58:39 -07:00
committed by Mathias Agopian
parent af5a168277
commit 8a0c714108
33 changed files with 273 additions and 287 deletions

View File

@@ -9,7 +9,7 @@ set(PUBLIC_HDR_DIR include)
# ==================================================================================================
set(PUBLIC_HDRS
include/filament/driver/BufferDescriptor.h
include/filament/driver/ExternalContext.h
include/filament/driver/Platform.h
include/filament/driver/PixelBufferDescriptor.h
include/filament/Box.h
include/filament/Camera.h
@@ -53,7 +53,7 @@ set(SRCS
src/driver/CircularBuffer.cpp
src/driver/Driver.cpp
src/driver/DriverAPI.inc
src/driver/ExternalContext.cpp
src/driver/Platform.cpp
src/driver/GPUBuffer.cpp
src/driver/Handle.cpp
src/driver/Program.cpp
@@ -165,17 +165,17 @@ endif()
if (USE_EXTERNAL_GLES3)
# Experimental feature; clients provide their own Context Manager.
elseif (ANDROID)
list(APPEND SRCS src/driver/opengl/ContextManagerEGL.cpp)
list(APPEND SRCS src/driver/opengl/PlatformEGL.cpp)
elseif (APPLE)
list(APPEND SRCS src/driver/opengl/ContextManagerCocoa.mm)
list(APPEND SRCS src/driver/opengl/PlatformCocoaGL.mm)
elseif (WEBGL)
list(APPEND SRCS src/driver/opengl/ContextManagerWebGL.cpp)
list(APPEND SRCS src/driver/opengl/PlatformWebGL.cpp)
elseif (LINUX)
list(APPEND SRCS src/driver/opengl/ContextManagerGLX.cpp)
list(APPEND SRCS src/driver/opengl/PlatformGLX.cpp)
elseif (WIN32)
list(APPEND SRCS src/driver/opengl/ContextManagerWGL.cpp)
list(APPEND SRCS src/driver/opengl/PlatformWGL.cpp)
else()
list(APPEND SRCS src/driver/opengl/ContextManagerDummy.cpp)
list(APPEND SRCS src/driver/opengl/PlatformDummyGL.cpp)
endif()
# ==================================================================================================
@@ -203,13 +203,13 @@ if (FILAMENT_SUPPORTS_VULKAN)
src/driver/vulkan/VulkanStagePool.cpp
)
if (LINUX)
list(APPEND SRCS src/driver/vulkan/ContextManagerVkLinux.cpp)
list(APPEND SRCS src/driver/vulkan/PlatformVkLinux.cpp)
elseif (APPLE)
list(APPEND SRCS src/driver/vulkan/ContextManagerVkCocoa.mm)
list(APPEND SRCS src/driver/vulkan/PlatformVkCocoa.mm)
elseif (ANDROID)
list(APPEND SRCS src/driver/vulkan/ContextManagerVkAndroid.cpp)
list(APPEND SRCS src/driver/vulkan/PlatformVkAndroid.cpp)
elseif (WIN32)
list(APPEND SRCS src/driver/vulkan/ContextManagerVkWindows.cpp)
list(APPEND SRCS src/driver/vulkan/PlatformVkWindows.cpp)
endif()
endif()

View File

@@ -21,7 +21,7 @@
#include <filament/Fence.h>
#include <filament/SwapChain.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
#include <utils/compiler.h>
#include <utils/EntityManager.h>
@@ -142,29 +142,29 @@ class TransformManager;
*/
class UTILS_PUBLIC Engine {
public:
using ExternalContext = driver::ExternalContext;
using Platform = driver::Platform;
using Backend = driver::Backend;
/**
* Creates an instance of Engine
*
* @param externalContext A pointer to an object that implements ExternalContext. If this is
* provided, then this object is used to manage the hardware context
* (e.g. OpenGL) lifecycle for filament.
* @param platform A pointer to an object that implements Platform. If this is
* provided, then this object is used to create the hardware context
* and expose platform features to it.
*
* If not provided (or nullptr is used), an appropriate hardware
* context is created automatically.
* If not provided (or nullptr is used), an appropriate Platform
* is created automatically.
*
* All methods of this interface are called from filament's
* render thread, which is different from the main thread.
*
* The lifetime of \p externalContext must exceed the life time of
* The lifetime of \p platform must exceed the lifetime of
* the Engine object.
*
* @param sharedGLContext A platform-dependant OpenGL context used as a shared context
* when creating filament's internal context.
* Setting this parameter will force filament to use the OpenGL
* implementation (instead of Vulkaan for instance).
* implementation (instead of Vulkan for instance).
*
*
* @return A pointer to the newly created Engine, or nullptr if the Engine couldn't be created.
@@ -180,7 +180,7 @@ public:
* This method is thread-safe.
*/
static Engine* create(Backend backend = Backend::DEFAULT,
ExternalContext* externalContext = nullptr, void* sharedGLContext = nullptr);
Platform* platform = nullptr, void* sharedGLContext = nullptr);
/**
* Destroy the Engine instance and all associated resources.

View File

@@ -35,7 +35,7 @@ namespace filament {
* SwapChain* swapChain = engine->createSwapChain(nativeWindow);
* \endcode
*
* When Engine::create() is used without specifying an ExternalContext, the `nativeWindow`
* When Engine::create() is used without specifying a Platform, the `nativeWindow`
* parameter above must be of type:
*
* Platform | nativeWindow type
@@ -46,7 +46,7 @@ namespace filament {
* X11 | Window
* Windows | HWND
*
* Otherwise, the `nativeWindow` is defined by the concrete implementation of ExternalContext.
* Otherwise, the `nativeWindow` is defined by the concrete implementation of Platform.
*
*
* Examples:

View File

@@ -14,10 +14,8 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_EXTERNALCONTEXT_H
#define TNT_FILAMENT_DRIVER_EXTERNALCONTEXT_H
#include <memory>
#ifndef TNT_FILAMENT_DRIVER_PLATFORM_H
#define TNT_FILAMENT_DRIVER_PLATFORM_H
#include <filament/driver/DriverEnums.h>
@@ -32,7 +30,7 @@ class Driver;
namespace driver {
class UTILS_PUBLIC ExternalContext {
class UTILS_PUBLIC Platform {
public:
struct SwapChain {};
struct Fence {};
@@ -43,22 +41,23 @@ public:
virtual int getOSVersion() const noexcept = 0;
virtual ~ExternalContext() noexcept;
virtual ~Platform() noexcept;
protected:
// Creates and and initializes the low-level API (e.g. an OpenGL context or Vulkan instance),
// then creates the concrete Driver. Returns null on failure.
virtual std::unique_ptr<Driver> createDriver(void* sharedGLContext) noexcept = 0;
// The caller takes ownership of the returned Driver* and must destroy it with delete.
virtual Driver* createDriver(void* sharedContext) noexcept = 0;
private:
friend class details::FEngine;
static ExternalContext* create(driver::Backend* backendHint) noexcept;
static void destroy(ExternalContext** context) noexcept;
static Platform* create(driver::Backend* backendHint) noexcept;
static void destroy(Platform** context) noexcept;
};
class UTILS_PUBLIC ContextManagerGL : public ExternalContext {
class UTILS_PUBLIC OpenGLPlatform : public Platform {
public:
~ContextManagerGL() noexcept override;
~OpenGLPlatform() noexcept override;
// Called to destroy the OpenGL context. This should clean up any windows
// or buffers from initialization.
@@ -103,9 +102,9 @@ public:
virtual void destroyExternalTextureStorage(ExternalTexture* ets) noexcept = 0;
};
class UTILS_PUBLIC ContextManagerVk : public ExternalContext {
class UTILS_PUBLIC VulkanPlatform : public Platform {
public:
~ContextManagerVk() noexcept override;
~VulkanPlatform() noexcept override;
// Given a Vulkan instance and native window handle, creates the platform-specific surface.
virtual void* createVkSurfaceKHR(void* nativeWindow, void* instance,
@@ -115,4 +114,4 @@ public:
} // namespace driver
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_EXTERNALCONTEXT_H
#endif // TNT_FILAMENT_DRIVER_PLATFORM_H

View File

@@ -71,8 +71,8 @@ namespace details {
static std::unordered_map<Engine const*, std::unique_ptr<FEngine>> sEngines;
static std::mutex sEnginesLock;
FEngine* FEngine::create(Backend backend, ExternalContext* externalContext, void* sharedGLContext) {
FEngine* instance = new FEngine(backend, externalContext, sharedGLContext);
FEngine* FEngine::create(Backend backend, Platform* platform, void* sharedGLContext) {
FEngine* instance = new FEngine(backend, platform, sharedGLContext);
slog.i << "FEngine (" << sizeof(void*) * 8 << " bits) created at " << instance << " "
<< "(threading is " << (UTILS_HAS_THREADING ? "enabled)" : "disabled)") << io::endl;
@@ -84,12 +84,12 @@ FEngine* FEngine::create(Backend backend, ExternalContext* externalContext, void
// In the single-threaded case, we do so in the here and now.
if (!UTILS_HAS_THREADING) {
// we don't own the external context at that point, set it to null
instance->mExternalContext = nullptr;
if (externalContext == nullptr) {
externalContext = ExternalContext::create(&instance->mBackend);
instance->mExternalContext = externalContext;
instance->mPlatform = nullptr;
if (platform == nullptr) {
platform = Platform::create(&instance->mBackend);
instance->mPlatform = platform;
}
instance->mDriver = externalContext->createDriver(sharedGLContext);
instance->mDriver = platform->createDriver(sharedGLContext);
instance->init();
instance->execute();
return instance;
@@ -143,9 +143,9 @@ static const half4 sFullScreenTriangleVertices[3] = {
// these must be static because only a pointer is copied to the render stream
static const uint16_t sFullScreenTriangleIndices[3] = { 0, 1, 2 };
FEngine::FEngine(Backend backend, ExternalContext* externalContext, void* sharedGLContext) :
FEngine::FEngine(Backend backend, Platform* platform, void* sharedGLContext) :
mBackend(backend),
mExternalContext(externalContext),
mPlatform(platform),
mSharedGLContext(sharedGLContext),
mEntityManager(EntityManager::get()),
mRenderableManager(*this),
@@ -245,6 +245,8 @@ void FEngine::init() {
FEngine::~FEngine() noexcept {
ASSERT_DESTRUCTOR(mTerminated, "Engine destroyed but not terminated!");
delete mDriver;
Platform::destroy(&mPlatform);
}
void FEngine::shutdown() {
@@ -324,8 +326,6 @@ void FEngine::shutdown() {
// detach this thread from the jobsystem
mJobSystem.emancipate();
ExternalContext::destroy(&mExternalContext);
mTerminated = true;
}
@@ -369,18 +369,18 @@ void FEngine::flush() {
int FEngine::loop() {
// we don't own the external context at that point, set it to null
ExternalContext* externalContext = mExternalContext;
mExternalContext = nullptr;
Platform* platform = mPlatform;
mPlatform = nullptr;
if (externalContext == nullptr) {
externalContext = ExternalContext::create(&mBackend);
mExternalContext = externalContext;
if (platform == nullptr) {
platform = Platform::create(&mBackend);
mPlatform = platform;
#if !defined(NDEBUG)
slog.d << "FEngine resolved backend: "
<< (mBackend == driver::Backend::VULKAN ? "Vulkan" : "OpenGL") << io::endl;
#endif
}
mDriver = externalContext->createDriver(mSharedGLContext);
mDriver = platform->createDriver(mSharedGLContext);
mDriverBarrier.latch();
if (UTILS_UNLIKELY(!mDriver)) {
// if we get here, it's because the driver couldn't be initialized and the problem has
@@ -771,8 +771,8 @@ EnginePerformanceTest::PFN EnginePerformanceTest::getDestroyUniverseApi() {
using namespace details;
Engine* Engine::create(Backend backend, ExternalContext* externalContext, void* sharedGLContext) {
std::unique_ptr<FEngine> engine(FEngine::create(backend, externalContext, sharedGLContext));
Engine* Engine::create(Backend backend, Platform* platform, void* sharedGLContext) {
std::unique_ptr<FEngine> engine(FEngine::create(backend, platform, sharedGLContext));
if (UTILS_UNLIKELY(!engine)) {
// something went wrong during the driver or engine initialization
return nullptr;

View File

@@ -180,7 +180,7 @@ public:
public:
static FEngine* create(Backend backend = Backend::DEFAULT,
ExternalContext* externalContext = nullptr, void* sharedGLContext = nullptr);
Platform* platform = nullptr, void* sharedGLContext = nullptr);
~FEngine() noexcept;
@@ -346,7 +346,7 @@ public:
bool execute();
private:
FEngine(Backend backend, ExternalContext* externalContext, void* sharedGLContext);
FEngine(Backend backend, Platform* platform, void* sharedGLContext);
void init();
int loop();
@@ -361,10 +361,10 @@ private:
Handle<HwProgram> createPostProcessProgram(filaflat::MaterialParser& parser,
driver::ShaderModel model, PostProcessStage stage) const noexcept;
std::unique_ptr<Driver> mDriver;
Driver* mDriver = nullptr;
Backend mBackend;
ExternalContext* mExternalContext = nullptr;
Platform* mPlatform = nullptr;
void* mSharedGLContext = nullptr;
bool mTerminated = false;
Handle<HwRenderPrimitive> mFullScreenTriangleRph;

View File

@@ -28,7 +28,7 @@
#include <filament/driver/PixelBufferDescriptor.h>
#include <filament/driver/BufferDescriptor.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
#include <filament/driver/DriverEnums.h>
#include "driver/Handle.h"

View File

@@ -126,17 +126,17 @@ struct HwRenderTarget : public HwBase {
};
struct HwFence : public HwBase {
driver::ExternalContext::Fence* fence;
driver::Platform::Fence* fence;
};
struct HwSwapChain : public HwBase {
driver::ExternalContext::SwapChain* swapChain;
driver::Platform::SwapChain* swapChain;
};
struct HwStream : public HwBase {
HwStream() = default;
explicit HwStream(driver::ExternalContext::Stream* stream) : stream(stream) { }
driver::ExternalContext::Stream* stream = nullptr;
explicit HwStream(driver::Platform::Stream* stream) : stream(stream) { }
driver::Platform::Stream* stream = nullptr;
uint32_t width = 0;
uint32_t height = 0;
};

View File

@@ -14,41 +14,41 @@
* limitations under the License.
*/
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
#if defined(ANDROID)
#ifndef USE_EXTERNAL_GLES3
#include "driver/opengl/ContextManagerEGL.h"
#include "driver/opengl/PlatformEGL.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "driver/vulkan/ContextManagerVkAndroid.h"
#include "driver/vulkan/PlatformVkAndroid.h"
#endif
#elif defined(__APPLE__)
#ifndef USE_EXTERNAL_GLES3
#include "driver/opengl/ContextManagerCocoa.h"
#include "driver/opengl/PlatformCocoaGL.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "driver/vulkan/ContextManagerVkCocoa.h"
#include "driver/vulkan/PlatformVkCocoa.h"
#endif
#elif defined(__linux__)
#ifndef USE_EXTERNAL_GLES3
#include "driver/opengl/ContextManagerGLX.h"
#include "driver/opengl/PlatformGLX.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "driver/vulkan/ContextManagerVkLinux.h"
#include "driver/vulkan/PlatformVkLinux.h"
#endif
#elif defined(WIN32)
#ifndef USE_EXTERNAL_GLES3
#include "driver/opengl/ContextManagerWGL.h"
#include "driver/opengl/PlatformWGL.h"
#endif
#if defined (FILAMENT_DRIVER_SUPPORTS_VULKAN)
#include "driver/vulkan/ContextManagerVkWindows.h"
#include "driver/vulkan/PlatformVkWindows.h"
#endif
#elif defined(__EMSCRIPTEN__)
#include "driver/opengl/ContextManagerWebGL.h"
#include "driver/opengl/PlatformWebGL.h"
#else
#ifndef USE_EXTERNAL_GLES3
#include "driver/opengl/ContextManagerDummy.h"
#include "driver/opengl/PlatformDummyGL.h"
#endif
#endif
@@ -56,16 +56,16 @@ namespace filament {
namespace driver {
// this generates the vtable in this translation unit
ExternalContext::~ExternalContext() noexcept = default;
Platform::~Platform() noexcept = default;
ContextManagerGL::~ContextManagerGL() noexcept = default;
OpenGLPlatform::~OpenGLPlatform() noexcept = default;
ContextManagerVk::~ContextManagerVk() noexcept = default;
VulkanPlatform::~VulkanPlatform() noexcept = default;
// Creates the platform-specific ExternalContext object. The caller takes ownership and is
// Creates the platform-specific Platform object. The caller takes ownership and is
// responsible for destroying it. Initialization of the backend API is deferred until
// createDriver(). The passed-in backend hint is replaced with the resolved backend.
ExternalContext* ExternalContext::create(Backend* backend) noexcept {
Platform* Platform::create(Backend* backend) noexcept {
assert(backend);
if (*backend == Backend::DEFAULT) {
*backend = Backend::OPENGL;
@@ -73,13 +73,13 @@ ExternalContext* ExternalContext::create(Backend* backend) noexcept {
if (*backend == Backend::VULKAN) {
#if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN)
#if defined(ANDROID)
return new ContextManagerVkAndroid();
return new PlatformVkAndroid();
#elif defined(__linux__)
return new ContextManagerVkLinux();
return new PlatformVkLinux();
#elif defined(__APPLE__)
return new ContextManagerVkCocoa();
return new PlatformVkCocoa();
#elif defined(WIN32)
return new ContextManagerVkWindows();
return new PlatformVkWindows();
#else
return nullptr;
#endif
@@ -90,23 +90,23 @@ ExternalContext* ExternalContext::create(Backend* backend) noexcept {
#if defined(USE_EXTERNAL_GLES3)
return nullptr;
#elif defined(ANDROID)
return new ContextManagerEGL();
return new PlatformEGL();
#elif defined(__APPLE__)
return new ContextManagerCocoa();
return new PlatformCocoaGL();
#elif defined(__linux__)
return new ContextManagerGLX();
return new PlatformGLX();
#elif defined(WIN32)
return new ContextManagerWGL();
return new PlatformWGL();
#elif defined(__EMSCRIPTEN__)
return new ContextManagerWebGL();
return new PlatformWebGL();
#else
return new ContextManagerDummy();
return new PlatformDummyGL();
#endif
return nullptr;
}
// destroys an ExternalContext create by create()
void ExternalContext::destroy(ExternalContext** context) noexcept {
// destroys an Platform create by create()
void Platform::destroy(Platform** context) noexcept {
delete *context;
*context = nullptr;
}

View File

@@ -28,7 +28,7 @@
#include "driver/opengl/OpenGLProgram.h"
#include "driver/opengl/OpenGLBlitter.h"
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
// change to true to display all GL extensions in the console on start-up
#define DEBUG_PRINT_EXTENSIONS false
@@ -59,10 +59,10 @@ namespace filament {
using namespace driver;
using namespace GLUtils;
std::unique_ptr<Driver> OpenGLDriver::create(
ContextManagerGL* const externalContext, void* const sharedGLContext) noexcept {
assert(externalContext);
ContextManagerGL* const ec = externalContext;
Driver* OpenGLDriver::create(
OpenGLPlatform* const platform, void* const sharedGLContext) noexcept {
assert(platform);
OpenGLPlatform* const ec = platform;
{ // here we check we're on a supported version of GL before initializing the driver
GLint major = 0, minor = 0;
@@ -93,14 +93,14 @@ std::unique_ptr<Driver> OpenGLDriver::create(
}
OpenGLDriver* const driver = new OpenGLDriver(ec);
return std::unique_ptr<Driver>(driver);
return driver;
}
OpenGLDriver::OpenGLDriver(ContextManagerGL* externalContext) noexcept
OpenGLDriver::OpenGLDriver(OpenGLPlatform* platform) noexcept
: DriverBase(new ConcreteDispatcher<OpenGLDriver>(this)),
mHandleArena("Handles", 2U * 1024U * 1024U), // TODO: set the amount in configuration
mSamplerMap(32),
mContextManager(*externalContext) {
mContextManager(*platform) {
state.enables.caps.set(getIndexForCap(GL_DITHER));
state.vao.p = &mDefaultVAO;
@@ -1376,7 +1376,7 @@ void OpenGLDriver::destroyStream(Driver::StreamHandle sh) {
Handle<HwStream> OpenGLDriver::createStream(void* nativeStream) {
Handle<HwStream> sh( allocateHandle(sizeof(GLStream)) );
ExternalContext::Stream* stream = mContextManager.createStream(nativeStream);
Platform::Stream* stream = mContextManager.createStream(nativeStream);
construct<GLStream>(sh, stream);
return sh;
}
@@ -2237,7 +2237,7 @@ void OpenGLDriver::updateStream(GLTexture* t, driver::DriverApi* driver) noexcep
info.width = s->width;
info.height = s->height;
ExternalContext::ExternalTexture* ets = s->user_thread.infos[s->user_thread.cur].ets;
Platform::ExternalTexture* ets = s->user_thread.infos[s->user_thread.cur].ets;
mContextManager.reallocateExternalStorage(ets, info.width, info.height,
TextureFormat::RGB8);
@@ -2521,7 +2521,7 @@ void OpenGLDriver::readPixels(Driver::RenderTargetHandle src,
void OpenGLDriver::beginFrame(uint64_t monotonic_clock_ns, uint32_t frameId) {
insertEventMarker("beginFrame");
if (UTILS_UNLIKELY(!mExternalStreams.empty())) {
driver::ContextManagerGL& contextManager = mContextManager;
driver::OpenGLPlatform& contextManager = mContextManager;
const size_t index = getIndexForTextureTarget(GL_TEXTURE_EXTERNAL_OES);
for (GLTexture const* t : mExternalStreams) {
assert(t && t->hwStream);

View File

@@ -43,12 +43,11 @@ class OpenGLProgram;
class OpenGLBlitter;
class OpenGLDriver final : public DriverBase {
inline explicit OpenGLDriver(driver::ContextManagerGL* external_context) noexcept;
inline explicit OpenGLDriver(driver::OpenGLPlatform* platform) noexcept;
~OpenGLDriver() noexcept final;
public:
static std::unique_ptr<Driver> create(
driver::ContextManagerGL* externalContext, void* sharedGLContext) noexcept;
static Driver* create(driver::OpenGLPlatform* platform, void* sharedGLContext) noexcept;
// OpenGLDriver specific fields
struct GLVertexBuffer : public HwVertexBuffer {
@@ -110,7 +109,7 @@ public:
bool isNativeStream() const { return gl.externalTextureId == 0; }
struct Info {
// storage for the read/write textures below
driver::ExternalContext::ExternalTexture* ets = nullptr;
driver::Platform::ExternalTexture* ets = nullptr;
GLuint width = 0;
GLuint height = 0;
};
@@ -532,7 +531,7 @@ private:
void detachStream(GLTexture* t) noexcept;
void replaceStream(GLTexture* t, GLStream* stream) noexcept;
driver::ContextManagerGL& mContextManager;
driver::OpenGLPlatform& mContextManager;
OpenGLBlitter* mOpenGLBlitter = nullptr;
void updateStream(GLTexture* t, driver::DriverApi* driver) noexcept;

View File

@@ -14,24 +14,24 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_COCOA_H
#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_COCOA_H
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_COCOA_GL_H
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_COCOA_GL_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
struct ContextManagerCocoaImpl;
struct PlatformCocoaGLImpl;
class ContextManagerCocoa final : public driver::ContextManagerGL {
class PlatformCocoaGL final : public driver::OpenGLPlatform {
public:
ContextManagerCocoa();
~ContextManagerCocoa() noexcept final;
PlatformCocoaGL();
~PlatformCocoaGL() noexcept final;
std::unique_ptr<Driver> createDriver(void* sharedGLContext) noexcept override;
Driver* createDriver(void* sharedContext) noexcept override;
void terminate() noexcept final;
SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final;
@@ -61,11 +61,9 @@ public:
int getOSVersion() const noexcept final { return 0; }
private:
ContextManagerCocoaImpl* pImpl = nullptr;
PlatformCocoaGLImpl* pImpl = nullptr;
};
using ContextManager = filament::ContextManagerCocoa;
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_COCOA_H
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_COCOA_GL_H

View File

@@ -14,14 +14,14 @@
* limitations under the License.
*/
#include "driver/opengl/ContextManagerCocoa.h"
#include "driver/opengl/PlatformCocoaGL.h"
#include <OpenGL/OpenGL.h>
#include <Cocoa/Cocoa.h>
#include "driver/DriverBase.h"
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
#include <utils/Panic.h>
@@ -31,20 +31,20 @@ namespace filament {
using namespace driver;
struct ContextManagerCocoaImpl {
struct PlatformCocoaGLImpl {
NSOpenGLContext* mGLContext = nullptr;
NSView* mCurrentView = nullptr;
};
ContextManagerCocoa::ContextManagerCocoa()
: pImpl(new ContextManagerCocoaImpl) {
PlatformCocoaGL::PlatformCocoaGL()
: pImpl(new PlatformCocoaGLImpl) {
}
ContextManagerCocoa::~ContextManagerCocoa() noexcept {
PlatformCocoaGL::~PlatformCocoaGL() noexcept {
delete pImpl;
}
std::unique_ptr<Driver> ContextManagerCocoa::createDriver(void* const sharedGLContext) noexcept {
Driver* PlatformCocoaGL::createDriver(void* sharedContext) noexcept {
// NSOpenGLPFAColorSize: when unspecified, a format that matches the screen is preferred
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = {
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
@@ -54,7 +54,7 @@ std::unique_ptr<Driver> ContextManagerCocoa::createDriver(void* const sharedGLCo
0, 0,
};
NSOpenGLContext* shareContext = (NSOpenGLContext*)sharedGLContext;
NSOpenGLContext* shareContext = (NSOpenGLContext*)sharedContext;
NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
NSOpenGLContext* nsOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:shareContext];
[pixelFormat release];
@@ -67,24 +67,24 @@ std::unique_ptr<Driver> ContextManagerCocoa::createDriver(void* const sharedGLCo
int result = bluegl::bind();
ASSERT_POSTCONDITION(!result, "Unable to load OpenGL entry points.");
return OpenGLDriver::create(this, sharedGLContext);
return OpenGLDriver::create(this, sharedContext);
}
void ContextManagerCocoa::terminate() noexcept {
void PlatformCocoaGL::terminate() noexcept {
[pImpl->mGLContext release];
bluegl::unbind();
}
ExternalContext::SwapChain* ContextManagerCocoa::createSwapChain(void* nativewindow, uint64_t& flags) noexcept {
Platform::SwapChain* PlatformCocoaGL::createSwapChain(void* nativewindow, uint64_t& flags) noexcept {
// Transparent swap chain is not supported
flags &= ~driver::SWAP_CHAIN_CONFIG_TRANSPARENT;
return (SwapChain*) nativewindow;
}
void ContextManagerCocoa::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformCocoaGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept {
}
void ContextManagerCocoa::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformCocoaGL::makeCurrent(Platform::SwapChain* swapChain) noexcept {
NSView *nsView = (NSView*) swapChain;
if (pImpl->mCurrentView != nsView) {
pImpl->mCurrentView = nsView;
@@ -105,7 +105,7 @@ void ContextManagerCocoa::makeCurrent(ExternalContext::SwapChain* swapChain) noe
[pImpl->mGLContext update];
}
void ContextManagerCocoa::commit(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformCocoaGL::commit(Platform::SwapChain* swapChain) noexcept {
[pImpl->mGLContext flushBuffer];
}

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
#include "driver/opengl/ContextManagerDummy.h"
#include "driver/opengl/PlatformDummyGL.h"
#include "driver/opengl/OpenGLDriver.h"
namespace filament {
std::unique_ptr<Driver> ContextManagerDummy::createDriver(void* const sharedGLContext) noexcept {
Driver* PlatformDummyGL::createDriver(void* const sharedGLContext) noexcept {
return nullptr;
}

View File

@@ -14,20 +14,20 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_DUMMY_H
#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_DUMMY_H
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_DUMMY_GL_H
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_DUMMY_GL_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
class ContextManagerDummy final : public driver::ContextManagerGL {
class PlatformDummyGL final : public driver::OpenGLPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedGLContext) noexcept override;
Driver* createDriver(void* const sharedGLContext) noexcept override;
void terminate() noexcept override { }
SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final override {
@@ -58,8 +58,6 @@ public:
int getOSVersion() const noexcept final override { return 0; }
};
using ContextManager = filament::ContextManagerDummy;
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_DUMMY_H
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_DUMMY_GL_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/opengl/ContextManagerEGL.h"
#include "driver/opengl/PlatformEGL.h"
#include <jni.h>
@@ -75,7 +75,7 @@ UTILS_PRIVATE PFNEGLPRESENTATIONTIMEANDROIDPROC eglPresentationTimeANDROID;
}
using namespace glext;
using EGLStream = ExternalContext::Stream;
using EGLStream = Platform::Stream;
// ---------------------------------------------------------------------------------------------
// Utilities
@@ -294,7 +294,7 @@ struct GraphicBufferWrapper { GraphicBuffer* graphicBuffer; };
} // namespace ndk
using namespace ndk;
struct EGLExternalTexture : public ExternalContext::ExternalTexture {
struct EGLExternalTexture : public Platform::ExternalTexture {
AHardwareBuffer* hardwareBuffer = nullptr;
GraphicBufferWrapper* graphicBufferWrapper = nullptr;
};
@@ -491,12 +491,12 @@ private:
// ---------------------------------------------------------------------------------------------
ContextManagerEGL::ContextManagerEGL() noexcept
PlatformEGL::PlatformEGL() noexcept
: mExternalStreamManager(ExternalStreamManagerAndroid::get()),
mExternalTextureManager(ExternalTextureManagerAndroid::get()) {
}
std::unique_ptr<Driver> ContextManagerEGL::createDriver(void* const sharedGLContext) noexcept {
Driver* PlatformEGL::createDriver(void* sharedContext) noexcept {
char scratch[PROP_VALUE_MAX + 1];
int length = __system_property_get("ro.build.version.release", scratch);
int androidVersion = length >= 0 ? atoi(scratch) : 1;
@@ -553,7 +553,7 @@ std::unique_ptr<Driver> ContextManagerEGL::createDriver(void* const sharedGLCont
#ifdef NDEBUG
// When we don't have a shared context and we're in release mode, we always activate the
// EGL_KHR_create_context_no_error extension.
if (!sharedGLContext && extensions.has("EGL_KHR_create_context_no_error")) {
if (!sharedContext && extensions.has("EGL_KHR_create_context_no_error")) {
contextAttribs[2] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR;
contextAttribs[3] = EGL_TRUE;
}
@@ -617,14 +617,14 @@ std::unique_ptr<Driver> ContextManagerEGL::createDriver(void* const sharedGLCont
goto error;
}
mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedGLContext, contextAttribs);
if (mEGLContext == EGL_NO_CONTEXT && sharedGLContext &&
mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedContext, contextAttribs);
if (mEGLContext == EGL_NO_CONTEXT && sharedContext &&
extensions.has("EGL_KHR_create_context_no_error")) {
// context creation could fail because of EGL_CONTEXT_OPENGL_NO_ERROR_KHR
// not matching the sharedContext. Try with it.
contextAttribs[2] = EGL_CONTEXT_OPENGL_NO_ERROR_KHR;
contextAttribs[3] = EGL_TRUE;
mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedGLContext, contextAttribs);
mEGLContext = eglCreateContext(mEGLDisplay, eglConfig, (EGLContext)sharedContext, contextAttribs);
}
if (UTILS_UNLIKELY(mEGLContext == EGL_NO_CONTEXT)) {
// eglCreateContext failed
@@ -639,7 +639,7 @@ std::unique_ptr<Driver> ContextManagerEGL::createDriver(void* const sharedGLCont
}
// success!!
return OpenGLDriver::create(this, sharedGLContext);
return OpenGLDriver::create(this, sharedContext);
error:
// if we're here, we've failed
@@ -659,7 +659,7 @@ error:
return nullptr;
}
EGLBoolean ContextManagerEGL::makeCurrent(EGLSurface surface) noexcept {
EGLBoolean PlatformEGL::makeCurrent(EGLSurface surface) noexcept {
if (UTILS_UNLIKELY((surface != mCurrentSurface))) {
mCurrentSurface = surface;
return eglMakeCurrent(mEGLDisplay, surface, surface, mEGLContext);
@@ -667,7 +667,7 @@ EGLBoolean ContextManagerEGL::makeCurrent(EGLSurface surface) noexcept {
return EGL_TRUE;
}
void ContextManagerEGL::terminate() noexcept {
void PlatformEGL::terminate() noexcept {
eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(mEGLDisplay, mEGLDummySurface);
eglDestroyContext(mEGLDisplay, mEGLContext);
@@ -675,7 +675,7 @@ void ContextManagerEGL::terminate() noexcept {
eglReleaseThread();
}
ExternalContext::SwapChain* ContextManagerEGL::createSwapChain(
Platform::SwapChain* PlatformEGL::createSwapChain(
void* nativeWindow, uint64_t& flags) noexcept {
EGLSurface sur = eglCreateWindowSurface(mEGLDisplay,
(flags & driver::SWAP_CHAIN_CONFIG_TRANSPARENT) ? mEGLTransparentConfig : mEGLConfig,
@@ -691,7 +691,7 @@ ExternalContext::SwapChain* ContextManagerEGL::createSwapChain(
return (SwapChain*)sur;
}
void ContextManagerEGL::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformEGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept {
EGLSurface sur = (EGLSurface) swapChain;
if (sur != EGL_NO_SURFACE) {
makeCurrent(mEGLDummySurface);
@@ -699,14 +699,14 @@ void ContextManagerEGL::destroySwapChain(ExternalContext::SwapChain* swapChain)
}
}
void ContextManagerEGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformEGL::makeCurrent(Platform::SwapChain* swapChain) noexcept {
EGLSurface sur = (EGLSurface) swapChain;
if (sur != EGL_NO_SURFACE) {
makeCurrent(sur);
}
}
void ContextManagerEGL::setPresentationTime(long time) noexcept {
void PlatformEGL::setPresentationTime(long time) noexcept {
if (mCurrentSurface != EGL_NO_SURFACE) {
eglPresentationTimeANDROID(
mEGLDisplay,
@@ -715,14 +715,14 @@ void ContextManagerEGL::setPresentationTime(long time) noexcept {
}
}
void ContextManagerEGL::commit(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformEGL::commit(Platform::SwapChain* swapChain) noexcept {
EGLSurface sur = (EGLSurface) swapChain;
if (sur != EGL_NO_SURFACE) {
eglSwapBuffers(mEGLDisplay, sur);
}
}
ExternalContext::Fence* ContextManagerEGL::createFence() noexcept {
Platform::Fence* PlatformEGL::createFence() noexcept {
Fence* f = nullptr;
#ifdef EGL_KHR_reusable_sync
f = (Fence*) eglCreateSyncKHR(mEGLDisplay, EGL_SYNC_FENCE_KHR, nullptr);
@@ -730,7 +730,7 @@ ExternalContext::Fence* ContextManagerEGL::createFence() noexcept {
return f;
}
void ContextManagerEGL::destroyFence(ExternalContext::Fence* fence) noexcept {
void PlatformEGL::destroyFence(Platform::Fence* fence) noexcept {
#ifdef EGL_KHR_reusable_sync
EGLSyncKHR sync = (EGLSyncKHR) fence;
if (sync != EGL_NO_SYNC_KHR) {
@@ -739,8 +739,8 @@ void ContextManagerEGL::destroyFence(ExternalContext::Fence* fence) noexcept {
#endif
}
driver::FenceStatus ContextManagerEGL::waitFence(
ExternalContext::Fence* fence, uint64_t timeout) noexcept {
driver::FenceStatus PlatformEGL::waitFence(
Platform::Fence* fence, uint64_t timeout) noexcept {
#ifdef EGL_KHR_reusable_sync
EGLSyncKHR sync = (EGLSyncKHR) fence;
if (sync != EGL_NO_SYNC_KHR) {
@@ -756,32 +756,32 @@ driver::FenceStatus ContextManagerEGL::waitFence(
return FenceStatus::ERROR;
}
ExternalContext::Stream* ContextManagerEGL::createStream(void* nativeStream) noexcept {
Platform::Stream* PlatformEGL::createStream(void* nativeStream) noexcept {
return mExternalStreamManager.acquire(static_cast<jobject>(nativeStream));
}
void ContextManagerEGL::destroyStream(ExternalContext::Stream* stream) noexcept {
void PlatformEGL::destroyStream(Platform::Stream* stream) noexcept {
mExternalStreamManager.release(static_cast<EGLStream*>(stream));
}
void ContextManagerEGL::attach(Stream* stream, intptr_t tname) noexcept {
void PlatformEGL::attach(Stream* stream, intptr_t tname) noexcept {
mExternalStreamManager.attach(static_cast<EGLStream*>(stream), tname);
}
void ContextManagerEGL::detach(Stream* stream) noexcept {
void PlatformEGL::detach(Stream* stream) noexcept {
mExternalStreamManager.detach(static_cast<EGLStream*>(stream));
}
void ContextManagerEGL::updateTexImage(Stream* stream) noexcept {
void PlatformEGL::updateTexImage(Stream* stream) noexcept {
mExternalStreamManager.updateTexImage(static_cast<EGLStream*>(stream));
}
ExternalContext::ExternalTexture* ContextManagerEGL::createExternalTextureStorage() noexcept {
Platform::ExternalTexture* PlatformEGL::createExternalTextureStorage() noexcept {
return mExternalTextureManager.create();
}
void ContextManagerEGL::reallocateExternalStorage(
ExternalContext::ExternalTexture* externalTexture,
void PlatformEGL::reallocateExternalStorage(
Platform::ExternalTexture* externalTexture,
uint32_t w, uint32_t h, driver::TextureFormat format) noexcept {
if (externalTexture) {
EGLExternalTexture* ets = static_cast<EGLExternalTexture*>(externalTexture);
@@ -790,15 +790,15 @@ void ContextManagerEGL::reallocateExternalStorage(
}
}
void ContextManagerEGL::destroyExternalTextureStorage(
ExternalContext::ExternalTexture* externalTexture) noexcept {
void PlatformEGL::destroyExternalTextureStorage(
Platform::ExternalTexture* externalTexture) noexcept {
if (externalTexture) {
EGLExternalTexture* ets = static_cast<EGLExternalTexture*>(externalTexture);
mExternalTextureManager.destroy(ets, mEGLDisplay);
}
}
int ContextManagerEGL::getOSVersion() const noexcept {
int PlatformEGL::getOSVersion() const noexcept {
return mOSVersion;
}

View File

@@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_EGL_H
#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_EGL_H
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_H
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_H
#include <stdint.h>
@@ -23,7 +23,7 @@
#include <EGL/eglext.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
struct AHardwareBuffer;
@@ -33,12 +33,12 @@ class VirtualMachineEnv;
class ExternalStreamManagerAndroid;
class ExternalTextureManagerAndroid;
class ContextManagerEGL final : public driver::ContextManagerGL {
class PlatformEGL final : public driver::OpenGLPlatform {
public:
ContextManagerEGL() noexcept;
PlatformEGL() noexcept;
std::unique_ptr<Driver> createDriver(void* sharedGLContext) noexcept override;
Driver* createDriver(void* sharedContext) noexcept override;
void terminate() noexcept override;
SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final;
@@ -81,8 +81,6 @@ private:
ExternalTextureManagerAndroid& mExternalTextureManager;
};
using ContextManager = filament::ContextManagerEGL;
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_EGL_H
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_EGL_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/opengl/ContextManagerGLX.h"
#include "driver/opengl/PlatformGLX.h"
#include <utils/Log.h>
#include <utils/Panic.h>
@@ -101,7 +101,7 @@ namespace filament {
using namespace driver;
std::unique_ptr<Driver> ContextManagerGLX::createDriver(void* const sharedGLContext) noexcept {
Driver* PlatformGLX::createDriver(void* const sharedGLContext) noexcept {
loadLibraries();
// Get the display device
mGLXDisplay = g_x11.openDisplay(NULL);
@@ -151,7 +151,7 @@ std::unique_ptr<Driver> ContextManagerGLX::createDriver(void* const sharedGLCont
return OpenGLDriver::create(this, sharedGLContext);
}
void ContextManagerGLX::terminate() noexcept {
void PlatformGLX::terminate() noexcept {
g_glx.setCurrentContext(mGLXDisplay, None, None, nullptr);
g_glx.destroyPbuffer(mGLXDisplay, mDummySurface);
g_glx.destroyContext(mGLXDisplay, mGLXContext);
@@ -159,7 +159,7 @@ void ContextManagerGLX::terminate() noexcept {
bluegl::unbind();
}
ExternalContext::SwapChain* ContextManagerGLX::createSwapChain(
Platform::SwapChain* PlatformGLX::createSwapChain(
void* nativeWindow, uint64_t& flags) noexcept {
// Transparent swap chain is not supported
@@ -167,29 +167,29 @@ ExternalContext::SwapChain* ContextManagerGLX::createSwapChain(
return (SwapChain*) nativeWindow;
}
void ContextManagerGLX::destroySwapChain(ExternalContext::SwapChain* /*swapChain*/) noexcept {
void PlatformGLX::destroySwapChain(Platform::SwapChain* /*swapChain*/) noexcept {
}
void ContextManagerGLX::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformGLX::makeCurrent(Platform::SwapChain* swapChain) noexcept {
g_glx.setCurrentContext(mGLXDisplay,
(GLXDrawable) swapChain, (GLXDrawable) swapChain, mGLXContext);
}
void ContextManagerGLX::commit(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformGLX::commit(Platform::SwapChain* swapChain) noexcept {
g_glx.swapBuffers(mGLXDisplay, (GLXDrawable)swapChain);
}
//TODO Implement GLX fences
ExternalContext::Fence* ContextManagerGLX::createFence() noexcept {
// TODO Implement GLX fences
Platform::Fence* PlatformGLX::createFence() noexcept {
Fence* f = new Fence();
return f;
}
void ContextManagerGLX::destroyFence(Fence* fence) noexcept {
void PlatformGLX::destroyFence(Fence* fence) noexcept {
delete fence;
}
driver::FenceStatus ContextManagerGLX::waitFence(Fence* fence, uint64_t timeout) noexcept {
driver::FenceStatus PlatformGLX::waitFence(Fence* fence, uint64_t timeout) noexcept {
return driver::FenceStatus::CONDITION_SATISFIED;
}

View File

@@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H
#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H
#include <stdint.h>
@@ -23,14 +23,14 @@
#include <GL/glx.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
class ContextManagerGLX final : public driver::ContextManagerGL {
class PlatformGLX final : public driver::OpenGLPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedGLContext) noexcept override;
Driver* createDriver(void* const sharedGLContext) noexcept override;
void terminate() noexcept override;
@@ -65,8 +65,6 @@ private:
GLXPbuffer mDummySurface;
};
using ContextManager = filament::ContextManagerGLX;
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/opengl/ContextManagerWGL.h"
#include "driver/opengl/PlatformWGL.h"
#include <Wingdi.h>
@@ -61,7 +61,7 @@ namespace filament {
using namespace driver;
std::unique_ptr<Driver> ContextManagerWGL::createDriver(void* const sharedGLContext) noexcept {
Driver* PlatformWGL::createDriver(void* const sharedGLContext) noexcept {
mPfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
@@ -135,7 +135,7 @@ error:
return NULL;
}
void ContextManagerWGL::terminate() noexcept {
void PlatformWGL::terminate() noexcept {
wglMakeCurrent(NULL, NULL);
if (mContext) {
wglDeleteContext(mContext);
@@ -153,7 +153,7 @@ void ContextManagerWGL::terminate() noexcept {
bluegl::unbind();
}
ExternalContext::SwapChain* ContextManagerWGL::createSwapChain(void* nativeWindow, uint64_t& flags) noexcept {
Platform::SwapChain* PlatformWGL::createSwapChain(void* nativeWindow, uint64_t& flags) noexcept {
// on Windows, the nativeWindow maps directly to a HDC
HDC hdc = (HDC) nativeWindow;
if (!ASSERT_POSTCONDITION_NON_FATAL(hdc,
@@ -169,12 +169,12 @@ ExternalContext::SwapChain* ContextManagerWGL::createSwapChain(void* nativeWindo
return swapChain;
}
void ContextManagerWGL::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformWGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept {
// make this swapChain not current (by making a dummy one current)
wglMakeCurrent(mWhdc, mContext);
}
void ContextManagerWGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformWGL::makeCurrent(Platform::SwapChain* swapChain) noexcept {
HDC hdc = (HDC)(swapChain);
if (hdc != NULL) {
BOOL success = wglMakeCurrent(hdc, mContext);
@@ -185,7 +185,7 @@ void ContextManagerWGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexc
}
}
void ContextManagerWGL::commit(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformWGL::commit(Platform::SwapChain* swapChain) noexcept {
HDC hdc = (HDC)(swapChain);
if (hdc != NULL) {
SwapBuffers(hdc);
@@ -193,14 +193,14 @@ void ContextManagerWGL::commit(ExternalContext::SwapChain* swapChain) noexcept {
}
//TODO Implement WGL fences
ExternalContext::Fence* ContextManagerWGL::createFence() noexcept {
Platform::Fence* PlatformWGL::createFence() noexcept {
return nullptr;
}
void ContextManagerWGL::destroyFence(Fence* fence) noexcept {
void PlatformWGL::destroyFence(Fence* fence) noexcept {
}
driver::FenceStatus ContextManagerWGL::waitFence(Fence* fence, uint64_t timeout) noexcept {
driver::FenceStatus PlatformWGL::waitFence(Fence* fence, uint64_t timeout) noexcept {
return driver::FenceStatus::ERROR;
}

View File

@@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WGL_H
#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WGL_H
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WGL_H
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WGL_H
#include <stdint.h>
@@ -23,13 +23,13 @@
#include <utils/unwindows.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
class ContextManagerWGL final : public driver::ContextManagerGL {
class PlatformWGL final : public driver::OpenGLPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedGLContext) noexcept override;
Driver* createDriver(void* const sharedGLContext) noexcept override;
void terminate() noexcept override;
SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept override;
@@ -63,8 +63,6 @@ private:
PIXELFORMATDESCRIPTOR mPfd = {};
};
using ContextManager = filament::ContextManagerWGL;
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_GLX_H
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_GLX_H

View File

@@ -14,44 +14,44 @@
* limitations under the License.
*/
#include "driver/opengl/ContextManagerWebGL.h"
#include "driver/opengl/PlatformWebGL.h"
#include "driver/opengl/OpenGLDriver.h"
namespace filament {
using namespace driver;
std::unique_ptr<Driver> ContextManagerWebGL::createDriver(void* const sharedGLContext) noexcept {
Driver* PlatformWebGL::createDriver(void* const sharedGLContext) noexcept {
return OpenGLDriver::create(this, sharedGLContext);
}
void ContextManagerWebGL::terminate() noexcept {
void PlatformWebGL::terminate() noexcept {
}
ExternalContext::SwapChain* ContextManagerWebGL::createSwapChain(
Platform::SwapChain* PlatformWebGL::createSwapChain(
void* nativeWindow, uint64_t& flags) noexcept {
return (SwapChain*) nativeWindow;
}
void ContextManagerWebGL::destroySwapChain(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformWebGL::destroySwapChain(Platform::SwapChain* swapChain) noexcept {
}
void ContextManagerWebGL::makeCurrent(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformWebGL::makeCurrent(Platform::SwapChain* swapChain) noexcept {
}
void ContextManagerWebGL::commit(ExternalContext::SwapChain* swapChain) noexcept {
void PlatformWebGL::commit(Platform::SwapChain* swapChain) noexcept {
}
ExternalContext::Fence* ContextManagerWebGL::createFence() noexcept {
Platform::Fence* PlatformWebGL::createFence() noexcept {
Fence* f = new Fence();
return f;
}
void ContextManagerWebGL::destroyFence(Fence* fence) noexcept {
void PlatformWebGL::destroyFence(Fence* fence) noexcept {
delete fence;
}
driver::FenceStatus ContextManagerWebGL::waitFence(Fence* fence, uint64_t timeout) noexcept {
driver::FenceStatus PlatformWebGL::waitFence(Fence* fence, uint64_t timeout) noexcept {
return driver::FenceStatus::CONDITION_SATISFIED;
}

View File

@@ -14,23 +14,23 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WEBGL_H
#define TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WEBGL_H
#ifndef TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WEBGL_H
#define TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WEBGL_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
namespace filament {
class ContextManagerWebGL final : public driver::ContextManagerGL {
class PlatformWebGL final : public driver::OpenGLPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedGLContext) noexcept override;
Driver* createDriver(void* const sharedGLContext) noexcept override;
void terminate() noexcept override;
SwapChain* createSwapChain(void* nativewindow, uint64_t& flags) noexcept final override;
@@ -58,8 +58,6 @@ public:
int getOSVersion() const noexcept final override { return 0; }
};
using ContextManager = filament::ContextManagerWebGL;
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_OPENGL_CONTEXT_MANAGER_WEBGL_H
#endif // TNT_FILAMENT_DRIVER_OPENGL_PLATFORM_WEBGL_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/vulkan/ContextManagerVkAndroid.h"
#include "driver/vulkan/PlatformVkAndroid.h"
#include "VulkanDriver.h"
@@ -29,7 +29,7 @@ namespace filament {
using namespace driver;
std::unique_ptr<Driver> ContextManagerVkAndroid::createDriver(void* const sharedContext) noexcept {
std::unique_ptr<Driver> PlatformVkAndroid::createDriver(void* const sharedContext) noexcept {
ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts.");
static const char* requestedExtensions[] = {
"VK_KHR_surface",
@@ -42,7 +42,7 @@ std::unique_ptr<Driver> ContextManagerVkAndroid::createDriver(void* const shared
sizeof(requestedExtensions) / sizeof(requestedExtensions[0]));
}
void* ContextManagerVkAndroid::createVkSurfaceKHR(void* nativeWindow, void* vkinstance,
void* PlatformVkAndroid::createVkSurfaceKHR(void* nativeWindow, void* vkinstance,
uint32_t* width, uint32_t* height) noexcept {
const VkInstance instance = (VkInstance) vkinstance;
ANativeWindow* aNativeWindow = (ANativeWindow*) nativeWindow;

View File

@@ -14,24 +14,27 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKCOCOA_H
#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKCOCOA_H
#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_ANDROID_H
#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_ANDROID_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
class ContextManagerVkCocoa final : public driver::ContextManagerVk {
class PlatformVkAndroid final : public driver::VulkanPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedContext) noexcept override;
void* createVkSurfaceKHR(void* nativeWindow, void* instance,
uint32_t* width, uint32_t* height) noexcept override;
int getOSVersion() const noexcept override { return 0; }
};
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKCOCOA_H
#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_ANDROID_H

View File

@@ -14,27 +14,24 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKANDROID_H
#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKANDROID_H
#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_COCOA_H
#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_COCOA_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
class ContextManagerVkAndroid final : public driver::ContextManagerVk {
class PlatformVkCocoa final : public driver::VulkanPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedContext) noexcept override;
Driver* createDriver(void* sharedContext) noexcept override;
void* createVkSurfaceKHR(void* nativeWindow, void* instance,
uint32_t* width, uint32_t* height) noexcept override;
int getOSVersion() const noexcept override { return 0; }
};
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKANDROID_H
#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_COCOA_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/vulkan/ContextManagerVkCocoa.h"
#include "driver/vulkan/PlatformVkCocoa.h"
#include "VulkanDriver.h"
@@ -36,14 +36,14 @@ namespace filament {
using namespace driver;
std::unique_ptr<Driver> ContextManagerVkCocoa::createDriver(void* const sharedContext) noexcept {
Driver* PlatformVkCocoa::createDriver(void* sharedContext) noexcept {
ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts.");
static const char* requestedExtensions[] = {"VK_KHR_surface", "VK_MVK_macos_surface"};
return VulkanDriver::create(this, requestedExtensions,
sizeof(requestedExtensions) / sizeof(requestedExtensions[0]));
}
void* ContextManagerVkCocoa::createVkSurfaceKHR(void* nativeWindow, void* instance,
void* PlatformVkCocoa::createVkSurfaceKHR(void* nativeWindow, void* instance,
uint32_t* width, uint32_t* height) noexcept {
// Obtain the CAMetalLayer-backed view.
NSView* nsview = (NSView*) nativeWindow;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/vulkan/ContextManagerVkLinux.h"
#include "driver/vulkan/PlatformVkLinux.h"
#include "VulkanDriver.h"
@@ -43,7 +43,7 @@ struct X11Functions {
void* library;
} g_x11;
std::unique_ptr<Driver> ContextManagerVkLinux::createDriver(void* const sharedContext) noexcept {
std::unique_ptr<Driver> PlatformVkLinux::createDriver(void* const sharedContext) noexcept {
ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts.");
static const char* requestedExtensions[] = {
"VK_KHR_surface",
@@ -63,7 +63,7 @@ std::unique_ptr<Driver> ContextManagerVkLinux::createDriver(void* const sharedCo
sizeof(requestedExtensions) / sizeof(requestedExtensions[0]));
}
void* ContextManagerVkLinux::createVkSurfaceKHR(void* nativeWindow, void* instance,
void* PlatformVkLinux::createVkSurfaceKHR(void* nativeWindow, void* instance,
uint32_t* width, uint32_t* height) noexcept {
ASSERT_POSTCONDITION(vkCreateXlibSurfaceKHR, "Unable to load vkCreateXlibSurfaceKHR function.");
VkSurfaceKHR surface = nullptr;

View File

@@ -14,19 +14,19 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKLINUX_H
#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKLINUX_H
#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_LINUX_H
#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_LINUX_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
#include <X11/Xlib.h>
namespace filament {
class ContextManagerVkLinux final : public driver::ContextManagerVk {
class PlatformVkLinux final : public driver::VulkanPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedContext) noexcept override;
@@ -42,4 +42,4 @@ private:
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKLINUX_H
#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_LINUX_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "driver/vulkan/ContextManagerVkWindows.h"
#include "driver/vulkan/PlatformVkWindows.h"
#include "VulkanDriver.h"
@@ -27,7 +27,7 @@ namespace filament {
using namespace driver;
std::unique_ptr<Driver> ContextManagerVkWindows::createDriver(void* const sharedContext) noexcept {
std::unique_ptr<Driver> PlatformVkWindows::createDriver(void* const sharedContext) noexcept {
ASSERT_PRECONDITION(sharedContext == nullptr, "Vulkan does not support shared contexts.");
static const char* requestedExtensions[] = {
"VK_KHR_surface",
@@ -40,7 +40,7 @@ std::unique_ptr<Driver> ContextManagerVkWindows::createDriver(void* const shared
sizeof(requestedExtensions) / sizeof(requestedExtensions[0]));
}
void* ContextManagerVkWindows::createVkSurfaceKHR(void* nativeWindow, void* instance,
void* PlatformVkWindows::createVkSurfaceKHR(void* nativeWindow, void* instance,
uint32_t* width, uint32_t* height) noexcept {
VkSurfaceKHR surface = nullptr;

View File

@@ -14,17 +14,17 @@
* limitations under the License.
*/
#ifndef TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKWINDOWS_H
#define TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKWINDOWS_H
#ifndef TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_WINDOWS_H
#define TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_WINDOWS_H
#include <stdint.h>
#include <filament/driver/DriverEnums.h>
#include <filament/driver/ExternalContext.h>
#include <filament/driver/Platform.h>
namespace filament {
class ContextManagerVkWindows final : public driver::ContextManagerVk {
class PlatformVkWindows final : public driver::VulkanPlatform {
public:
std::unique_ptr<Driver> createDriver(void* const sharedContext) noexcept override;
@@ -40,4 +40,4 @@ private:
} // namespace filament
#endif // TNT_FILAMENT_DRIVER_VULKAN_CONTEXTMANAGERVKWINDOWS_H
#endif // TNT_FILAMENT_DRIVER_VULKAN_PLATFORM_VK_WINDOWS_H

View File

@@ -39,10 +39,10 @@ static constexpr bool SWAPCHAIN_HAS_DEPTH = true;
namespace filament {
namespace driver {
VulkanDriver::VulkanDriver(ContextManagerVk* externalContext,
VulkanDriver::VulkanDriver(VulkanPlatform* platform,
const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept :
DriverBase(new ConcreteDispatcher<VulkanDriver>(this)),
mContextManager(*externalContext), mStagePool(mContext), mFramebufferCache(mContext),
mContextManager(*platform), mStagePool(mContext), mFramebufferCache(mContext),
mSamplerCache(mContext) {
mContext.rasterState = mBinder.getDefaultRasterState();
@@ -158,12 +158,12 @@ VulkanDriver::VulkanDriver(ContextManagerVk* externalContext,
VulkanDriver::~VulkanDriver() noexcept = default;
std::unique_ptr<Driver> VulkanDriver::create(ContextManagerVk* const externalContext,
Driver* VulkanDriver::create(VulkanPlatform* const platform,
const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept {
assert(externalContext);
auto* const driver = new VulkanDriver(externalContext, ppEnabledExtensions,
assert(platform);
auto* const driver = new VulkanDriver(platform, ppEnabledExtensions,
enabledExtensionCount);
return std::unique_ptr<Driver>(driver);
return driver;
}
ShaderModel VulkanDriver::getShaderModel() const noexcept {

View File

@@ -40,7 +40,7 @@ struct VulkanSamplerBuffer;
class VulkanDriver final : public DriverBase {
public:
static std::unique_ptr<Driver> create(driver::ContextManagerVk* externalContext,
static Driver* create(driver::VulkanPlatform* platform,
const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept;
private:
@@ -49,7 +49,7 @@ private:
void debugCommand(const char* methodName) override;
#endif
inline VulkanDriver(driver::ContextManagerVk* const externalContext,
inline VulkanDriver(driver::VulkanPlatform* const platform,
const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept;
virtual ~VulkanDriver() noexcept;
@@ -75,7 +75,7 @@ private:
VulkanDriver(VulkanDriver const&) = delete;
VulkanDriver& operator = (VulkanDriver const&) = delete;
driver::ContextManagerVk& mContextManager;
driver::VulkanPlatform& mContextManager;
// For now we're not bothering to store handles in pools, just simple on-demand allocation.
// We have a little map from integer handles to "blobs" which get replaced with the Hw objects.