add Cmake/preprocessor define to switch between ANGLE/OpenGL on Windows
This commit is contained in:
5
.gitattributes
vendored
5
.gitattributes
vendored
@@ -589,3 +589,8 @@ example/assets/BusterDrone/textures/body_metallicRoughness.jpg filter=lfs diff=l
|
||||
example/assets/FlightHelmet/FlightHelmet.bin filter=lfs diff=lfs merge=lfs -text
|
||||
example/assets/FlightHelmet/FlightHelmet_baseColor3.png filter=lfs diff=lfs merge=lfs -text
|
||||
assets/default.uberz filter=lfs diff=lfs merge=lfs -text
|
||||
windows/lib/**/*.* filter=lfs diff=lfs merge=lfs -text
|
||||
windows/lib/Debug/angle/* filter=lfs diff=lfs merge=lfs -text
|
||||
windows/lib/Debug/opengl/* filter=lfs diff=lfs merge=lfs -text
|
||||
windows/lib/Release/opengl/* filter=lfs diff=lfs merge=lfs -text
|
||||
windows/lib/Release/angle/* filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
1
example/.gitattributes
vendored
1
example/.gitattributes
vendored
@@ -2,3 +2,4 @@ assets/lit_opaque_43.uberz filter=lfs diff=lfs merge=lfs -text
|
||||
assets/BusterDrone filter=lfs diff=lfs merge=lfs -text
|
||||
assets/FlightHelmet filter=lfs diff=lfs merge=lfs -text
|
||||
assets/lit_opaque_32.uberz filter=lfs diff=lfs merge=lfs -text
|
||||
windows/lib/**/*.* filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
@@ -12,7 +12,6 @@ set(PLUGIN_NAME "polyvox_filament_plugin")
|
||||
list(APPEND PLUGIN_SOURCES
|
||||
"polyvox_filament_plugin.cpp"
|
||||
"polyvox_filament_plugin.h"
|
||||
"PlatformAngle.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/AssetManager.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/FilamentViewer.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/PolyvoxFilamentApi.cpp"
|
||||
@@ -21,6 +20,14 @@ list(APPEND PLUGIN_SOURCES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../ios/src/TimeIt.cpp"
|
||||
)
|
||||
|
||||
set(USE_ANGLE TRUE)
|
||||
|
||||
add_compile_definitions(USE_ANGLE=${USE_ANGLE})
|
||||
|
||||
if(USE_ANGLE)
|
||||
list(APPEND PLUGIN_SOURCES "PlatformAngle.cpp")
|
||||
endif()
|
||||
|
||||
# Define the plugin library target. Its name must not be changed (see comment
|
||||
# on PLUGIN_NAME above).
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
@@ -43,15 +50,37 @@ target_include_directories(${PLUGIN_NAME} INTERFACE
|
||||
)
|
||||
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/filament")
|
||||
|
||||
add_library(EGL SHARED IMPORTED)
|
||||
set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/libEGL.dll.lib")
|
||||
set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/libEGL.dll.lib")
|
||||
set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/libEGL.dll.lib")
|
||||
add_library(GLESv2 SHARED IMPORTED)
|
||||
set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/libGLESv2.dll.lib")
|
||||
set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/libGLESv2.dll.lib")
|
||||
set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/libGLESv2.dll.lib")
|
||||
|
||||
if(USE_ANGLE)
|
||||
list(APPEND GL_LIBS
|
||||
EGL
|
||||
GLESv2
|
||||
)
|
||||
set(ANGLE_OR_OPENGL_DIR angle)
|
||||
add_library(EGL SHARED IMPORTED)
|
||||
set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/angle/libEGL.dll.lib")
|
||||
set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/angle/libEGL.dll.lib")
|
||||
set_property(TARGET EGL PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/angle/libEGL.dll.lib")
|
||||
add_library(GLESv2 SHARED IMPORTED)
|
||||
set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/angle/libGLESv2.dll.lib")
|
||||
set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/angle/libGLESv2.dll.lib")
|
||||
set_property(TARGET GLESv2 PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/angle/libGLESv2.dll.lib")
|
||||
else()
|
||||
list(APPEND GL_LIBS
|
||||
bluegl
|
||||
opengl32
|
||||
)
|
||||
set(ANGLE_OR_OPENGL_DIR opengl)
|
||||
add_library(bluegl SHARED IMPORTED)
|
||||
set_property(TARGET bluegl PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/opengl/bluegl.lib")
|
||||
set_property(TARGET bluegl PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/opengl/bluegl.lib")
|
||||
set_property(TARGET bluegl PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/opengl/bluegl.lib")
|
||||
endif()
|
||||
|
||||
add_library(backend SHARED IMPORTED)
|
||||
set_property(TARGET backend PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/${ANGLE_OR_OPENGL_DIR}/backend.lib")
|
||||
set_property(TARGET backend PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/${ANGLE_OR_OPENGL_DIR}/backend.lib")
|
||||
set_property(TARGET backend PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/${ANGLE_OR_OPENGL_DIR}/backend.lib")
|
||||
|
||||
add_library(geometry SHARED IMPORTED)
|
||||
set_property(TARGET geometry PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/geometry.lib")
|
||||
@@ -63,11 +92,6 @@ set_property(TARGET filament PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOU
|
||||
set_property(TARGET filament PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/filament.lib")
|
||||
set_property(TARGET filament PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/filament.lib")
|
||||
|
||||
add_library(backend SHARED IMPORTED)
|
||||
set_property(TARGET backend PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/backend.lib")
|
||||
set_property(TARGET backend PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/backend.lib")
|
||||
set_property(TARGET backend PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/backend.lib")
|
||||
|
||||
add_library(filameshio SHARED IMPORTED)
|
||||
set_property(TARGET filameshio PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/filameshio.lib")
|
||||
set_property(TARGET filameshio PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/filameshio.lib")
|
||||
@@ -164,9 +188,9 @@ set_property(TARGET smol-v PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SO
|
||||
set_property(TARGET smol-v PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/smol-v.lib")
|
||||
|
||||
add_library(uberarchive SHARED IMPORTED)
|
||||
set_property(TARGET uberarchive PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/uberarchive.lib")
|
||||
set_property(TARGET uberarchive PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/uberarchive.lib")
|
||||
set_property(TARGET uberarchive PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/uberarchive.lib")
|
||||
set_property(TARGET uberarchive PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/${ANGLE_OR_OPENGL_DIR}/uberarchive.lib")
|
||||
set_property(TARGET uberarchive PROPERTY IMPORTED_IMPLIB_PROFILE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/${ANGLE_OR_OPENGL_DIR}/uberarchive.lib")
|
||||
set_property(TARGET uberarchive PROPERTY IMPORTED_IMPLIB_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/lib/Release/${ANGLE_OR_OPENGL_DIR}/uberarchive.lib")
|
||||
|
||||
add_library(meshoptimizer SHARED IMPORTED)
|
||||
set_property(TARGET meshoptimizer PROPERTY IMPORTED_IMPLIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/meshoptimizer.lib")
|
||||
@@ -199,9 +223,9 @@ include_directories(
|
||||
)
|
||||
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE
|
||||
flutter
|
||||
flutter_wrapper_plugin
|
||||
gltfio
|
||||
flutter
|
||||
flutter_wrapper_plugin
|
||||
gltfio
|
||||
gltfio_core
|
||||
filament
|
||||
backend
|
||||
@@ -228,22 +252,18 @@ flutter_wrapper_plugin
|
||||
png
|
||||
tinyexr
|
||||
Shlwapi
|
||||
EGL
|
||||
GLESv2
|
||||
${GL_LIBS}
|
||||
)
|
||||
|
||||
# List of absolute paths to libraries that should be bundled with the plugin
|
||||
if(USE_ANGLE)
|
||||
set(polyvox_filament_bundled_libraries
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/libEGL.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/libGLESv2.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/angle/libEGL.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/angle/libGLESv2.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/libc++.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/third_party_abseil-cpp_absl.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/third_party_zlib.dll
|
||||
PARENT_SCOPE
|
||||
)
|
||||
endif()
|
||||
|
||||
# get_cmake_property(_variableNames VARIABLES)
|
||||
# list (SORT _variableNames)
|
||||
# foreach (_variableName ${_variableNames})
|
||||
# message(STATUS "${_variableName}FOO=BAR${${_variableName}}")
|
||||
# endforeach()
|
||||
@@ -29,7 +29,10 @@
|
||||
#include <future>
|
||||
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
#ifdef USE_ANGLE
|
||||
#include "PlatformANGLE.h"
|
||||
#endif
|
||||
|
||||
#include "GL/GL.h"
|
||||
#include "GL/GLu.h"
|
||||
#include "GL/wglext.h"
|
||||
@@ -137,21 +140,16 @@ void render_callback(void* owner) {
|
||||
|
||||
// this is the method on PolyvoxFilamentPlugin that will copy between D3D textures
|
||||
void PolyvoxFilamentPlugin::RenderCallback() {
|
||||
#ifdef USE_ANGLE
|
||||
_D3D11DeviceContext->CopyResource(_externalD3DTexture2D.Get(),
|
||||
_internalD3DTexture2D.Get());
|
||||
_D3D11DeviceContext->Flush();
|
||||
#endif
|
||||
_textureRegistrar->MarkTextureFrameAvailable(_flutterTextureId);
|
||||
}
|
||||
|
||||
void PolyvoxFilamentPlugin::CreateTexture(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
|
||||
const auto *args =
|
||||
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
||||
|
||||
const auto width = (uint32_t)round(*(std::get_if<double>(&(args->at(0)))));
|
||||
const auto height = (uint32_t)round(*(std::get_if<double>(&(args->at(1)))));
|
||||
#ifdef USE_ANGLE
|
||||
bool PolyvoxFilamentPlugin::MakeD3DTexture(uint32_t width, uint32_t height,std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
|
||||
// D3D starts here
|
||||
IDXGIAdapter* adapter_ = nullptr;
|
||||
@@ -180,7 +178,7 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
||||
dxgi->Release();
|
||||
if (!adapter_) {
|
||||
result->Error("ERROR", "Failed to locate default D3D adapter", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
DXGI_ADAPTER_DESC adapter_desc_;
|
||||
@@ -194,7 +192,7 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
||||
|
||||
if (FAILED(hr)) {
|
||||
result->Error("ERROR", "Failed to create D3D device", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device = nullptr;
|
||||
@@ -227,19 +225,19 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
||||
if FAILED(hr)
|
||||
{
|
||||
result->Error("ERROR", "Failed to create D3D texture", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
auto resource = Microsoft::WRL::ComPtr<IDXGIResource>{};
|
||||
hr = _internalD3DTexture2D.As(&resource);
|
||||
|
||||
if FAILED(hr) {
|
||||
result->Error("ERROR", "Failed to create D3D texture", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
hr = resource->GetSharedHandle(&_internalD3DTextureHandle);
|
||||
if FAILED(hr) {
|
||||
result->Error("ERROR", "Failed to get shared handle to D3D texture", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
_internalD3DTexture2D->AddRef();
|
||||
|
||||
@@ -250,25 +248,25 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
||||
if FAILED(hr)
|
||||
{
|
||||
result->Error("ERROR", "Failed to create D3D texture", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
hr = _externalD3DTexture2D.As(&resource);
|
||||
|
||||
if FAILED(hr) {
|
||||
result->Error("ERROR", "Failed to create D3D texture", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
hr = resource->GetSharedHandle(&_externalD3DTextureHandle);
|
||||
if FAILED(hr) {
|
||||
result->Error("ERROR", "Failed to get shared handle to external D3D texture", nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
_externalD3DTexture2D->AddRef();
|
||||
|
||||
std::cout << "Created external D3D texture" << std::endl;
|
||||
|
||||
_platform = new filament::backend::PlatformANGLE(_internalD3DTextureHandle, width, height);
|
||||
|
||||
|
||||
_textureDescriptor = std::make_unique<FlutterDesktopGpuSurfaceDescriptor>();
|
||||
_textureDescriptor->struct_size = sizeof(FlutterDesktopGpuSurfaceDescriptor);
|
||||
_textureDescriptor->handle = _externalD3DTextureHandle;
|
||||
@@ -286,17 +284,174 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
||||
_flutterTextureId = _textureRegistrar->RegisterTexture(_texture.get());
|
||||
std::cout << "Registered Flutter texture ID " << _flutterTextureId << std::endl;
|
||||
|
||||
_D3D11DeviceContext->CopyResource(_externalD3DTexture2D.Get(),
|
||||
_internalD3DTexture2D.Get());
|
||||
_D3D11DeviceContext->Flush();
|
||||
|
||||
_textureRegistrar->MarkTextureFrameAvailable(_flutterTextureId);
|
||||
|
||||
std::vector<flutter::EncodableValue> resultList;
|
||||
resultList.push_back(flutter::EncodableValue(_flutterTextureId));
|
||||
resultList.push_back(flutter::EncodableValue((int64_t)nullptr));
|
||||
resultList.push_back(flutter::EncodableValue(_platform->glTextureId));
|
||||
result->Success(resultList);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool PolyvoxFilamentPlugin::MakeOpenGLTexture(uint32_t width, uint32_t height,std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
HWND hwnd = _pluginRegistrar->GetView()
|
||||
->GetNativeWindow();;
|
||||
|
||||
HDC whdc = GetDC(hwnd);
|
||||
if (whdc == NULL) {
|
||||
result->Error("ERROR", "No device context for temporary window", nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
1,
|
||||
PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
|
||||
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
|
||||
32, // Colordepth of the framebuffer.
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, 0, 0, 0,
|
||||
32, // Number of bits for the depthbuffer
|
||||
0, // Number of bits for the stencilbuffer
|
||||
0, // Number of Aux buffers in the framebuffer.
|
||||
PFD_MAIN_PLANE,
|
||||
0,
|
||||
0, 0, 0
|
||||
};
|
||||
|
||||
int pixelFormat = ChoosePixelFormat(whdc, &pfd);
|
||||
SetPixelFormat(whdc, pixelFormat, &pfd);
|
||||
|
||||
// We need a tmp context to retrieve and call wglCreateContextAttribsARB.
|
||||
HGLRC tempContext = wglCreateContext(whdc);
|
||||
if (!wglMakeCurrent(whdc, tempContext)) {
|
||||
result->Error("ERROR", "Failed to acquire temporary context", nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
GLenum err = glGetError();
|
||||
|
||||
if(err != GL_NO_ERROR) {
|
||||
result->Error("ERROR", "GL Error @ 455 %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr;
|
||||
|
||||
wglCreateContextAttribs =
|
||||
(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress(
|
||||
"wglCreateContextAttribsARB");
|
||||
|
||||
if (!wglCreateContextAttribs) {
|
||||
result->Error("ERROR", "Failed to resolve wglCreateContextAttribsARB",
|
||||
nullptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int minor = 5; minor >= 1; minor--) {
|
||||
std::vector<int> mAttribs = {WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
|
||||
WGL_CONTEXT_MINOR_VERSION_ARB, minor, 0};
|
||||
_context = wglCreateContextAttribs(whdc, nullptr, mAttribs.data());
|
||||
if (_context) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(tempContext);
|
||||
|
||||
|
||||
if (!_context || !wglMakeCurrent(whdc, _context)) {
|
||||
result->Error("ERROR", "Failed to create OpenGL context.");
|
||||
return false;
|
||||
}
|
||||
|
||||
glGenTextures(1, &_glTextureId);
|
||||
|
||||
if(_glTextureId == 0) {
|
||||
result->Error("ERROR", "Failed to generate texture, OpenGL err was %d", glGetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
err = glGetError();
|
||||
|
||||
if (err != GL_NO_ERROR) {
|
||||
result->Error("ERROR", "Failed to generate texture, GL error was %d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
_pixelData.reset(new uint8_t[width * height * 4]);
|
||||
_pixelBuffer = std::make_unique<FlutterDesktopPixelBuffer>();
|
||||
_pixelBuffer->buffer = _pixelData.get();
|
||||
|
||||
_pixelBuffer->width = size_t(width);
|
||||
_pixelBuffer->height = size_t(height);
|
||||
|
||||
_texture = std::make_unique<flutter::TextureVariant>(flutter::PixelBufferTexture(
|
||||
[=](size_t width,
|
||||
size_t height) -> const FlutterDesktopPixelBuffer * {
|
||||
std::lock_guard<std::mutex> guard(_renderMutex);
|
||||
|
||||
if(!_context || !wglMakeCurrent(whdc, _context)) {
|
||||
std::cout << "Failed to switch OpenGL context." << std::endl;
|
||||
} else {
|
||||
uint8_t* data = new uint8_t[width*height*4];
|
||||
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
||||
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
|
||||
|
||||
GLenum err = glGetError();
|
||||
|
||||
if(err != GL_NO_ERROR) {
|
||||
if(err == GL_INVALID_OPERATION) {
|
||||
std::cout << "Invalid op" << std::endl;
|
||||
} else if(err == GL_INVALID_VALUE) {
|
||||
std::cout << "Invalid value" << std::endl;
|
||||
} else if(err == GL_OUT_OF_MEMORY) {
|
||||
std::cout << "Out of mem" << std::endl;
|
||||
} else if(err == GL_INVALID_ENUM ) {
|
||||
std::cout << "Invalid enum" << std::endl;
|
||||
} else {
|
||||
std::cout << "Unknown error" << std::endl;
|
||||
}
|
||||
}
|
||||
glFinish();
|
||||
_pixelData.reset(data);
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
}
|
||||
_pixelBuffer->buffer = _pixelData.get();
|
||||
|
||||
return _pixelBuffer.get();
|
||||
}));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void PolyvoxFilamentPlugin::CreateTexture(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||
|
||||
const auto *args =
|
||||
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
||||
|
||||
const auto width = (uint32_t)round(*(std::get_if<double>(&(args->at(0)))));
|
||||
const auto height = (uint32_t)round(*(std::get_if<double>(&(args->at(1)))));
|
||||
|
||||
#ifdef USE_ANGLE
|
||||
bool success = MakeD3DTexture(width, height, std::move(result));
|
||||
#else
|
||||
bool success = MakeOpenGLTexture(width, height, std::move(result));
|
||||
#endif
|
||||
if(!success) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -321,6 +476,9 @@ void PolyvoxFilamentPlugin::HandleMethodCall(
|
||||
} else if(methodCall.method_name() == "getDriverPlatform") {
|
||||
result->Success(flutter::EncodableValue((int64_t)_platform));
|
||||
}
|
||||
else {
|
||||
result->Error("NOT_IMPLEMENTED", "Method is not implemented %s", methodCall.method_name());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace polyvox_filament
|
||||
|
||||
@@ -11,17 +11,21 @@
|
||||
#include <Windows.h>
|
||||
#include <wrl.h>
|
||||
|
||||
#ifdef USE_ANGLE
|
||||
#include <d3d.h>
|
||||
#include <d3d11.h>
|
||||
#endif
|
||||
|
||||
#include "GL/GL.h"
|
||||
#include "GL/GLu.h"
|
||||
|
||||
#ifdef USE_ANGLE
|
||||
#include "EGL/egl.h"
|
||||
#include "EGL/eglext.h"
|
||||
#include "EGL/eglplatform.h"
|
||||
#include "GLES2/gl2.h"
|
||||
#include "GLES2/gl2ext.h"
|
||||
#endif
|
||||
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
#include "PlatformAngle.h"
|
||||
@@ -59,9 +63,7 @@ public:
|
||||
|
||||
int64_t _flutterTextureId;
|
||||
|
||||
GLuint _glTextureId = 0;
|
||||
|
||||
// D3D
|
||||
#ifdef USE_ANGLE
|
||||
// Device
|
||||
ID3D11Device* _D3D11Device = nullptr;
|
||||
ID3D11DeviceContext* _D3D11DeviceContext = nullptr;
|
||||
@@ -71,6 +73,12 @@ public:
|
||||
HANDLE _externalD3DTextureHandle = nullptr;
|
||||
HANDLE _internalD3DTextureHandle = nullptr;
|
||||
filament::backend::PlatformANGLE* _platform = nullptr;
|
||||
#else
|
||||
// OpenGL
|
||||
HGLRC _context = NULL;
|
||||
GLuint _glTextureId = 0;
|
||||
std::mutex _renderMutex;
|
||||
#endif
|
||||
|
||||
void CreateTexture(
|
||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||
@@ -80,6 +88,11 @@ public:
|
||||
|
||||
ResourceBuffer loadResource(const char *path);
|
||||
void freeResource(ResourceBuffer rbuf);
|
||||
#ifdef USE_ANGLE
|
||||
bool MakeD3DTexture(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
#else
|
||||
bool MakeOpenGLTexture(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace polyvox_filament
|
||||
|
||||
Reference in New Issue
Block a user