Merge branch 'feature/instancing' of github.com:nmfisher/polyvox_filament into feature/instancing
This commit is contained in:
@@ -150,39 +150,26 @@ namespace flutter_filament
|
|||||||
|
|
||||||
_scene = _engine->createScene();
|
_scene = _engine->createScene();
|
||||||
|
|
||||||
Log("Scene created");
|
|
||||||
|
|
||||||
utils::Entity camera = EntityManager::get().create();
|
utils::Entity camera = EntityManager::get().create();
|
||||||
|
|
||||||
_mainCamera = _engine->createCamera(camera);
|
_mainCamera = _engine->createCamera(camera);
|
||||||
|
|
||||||
Log("Main camera created");
|
|
||||||
_view = _engine->createView();
|
_view = _engine->createView();
|
||||||
|
|
||||||
Log("View created");
|
|
||||||
|
|
||||||
setToneMapping(ToneMapping::ACES);
|
setToneMapping(ToneMapping::ACES);
|
||||||
Log("Set tone mapping");
|
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
// there's a glitch on certain iGPUs where nothing will render when postprocessing is enabled and bloom is disabled
|
||||||
Log("Bloom is disabled on WebGL builds as it causes instability with certain drivers");
|
// set bloom to a small value here
|
||||||
decltype(_view->getBloomOptions()) opts;
|
setBloom(0.01);
|
||||||
opts.enabled = false;
|
|
||||||
_view->setBloomOptions(opts);
|
|
||||||
|
|
||||||
_view->setAmbientOcclusionOptions({.enabled = false});
|
_view->setAmbientOcclusionOptions({.enabled = false});
|
||||||
|
|
||||||
_view->setDynamicResolutionOptions({.enabled = false});
|
_view->setDynamicResolutionOptions({.enabled = false});
|
||||||
|
|
||||||
_view->setDithering(filament::Dithering::NONE);
|
_view->setDithering(filament::Dithering::NONE);
|
||||||
_view->setAntiAliasing(filament::AntiAliasing::NONE);
|
setAntiAliasing(false, false, false);
|
||||||
_view->setShadowingEnabled(false);
|
_view->setShadowingEnabled(false);
|
||||||
_view->setScreenSpaceRefractionEnabled(false);
|
_view->setScreenSpaceRefractionEnabled(false);
|
||||||
|
setPostProcessing(false);
|
||||||
#else
|
|
||||||
setBloom(0.6f);
|
|
||||||
Log("Set bloom");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_view->setScene(_scene);
|
_view->setScene(_scene);
|
||||||
_view->setCamera(_mainCamera);
|
_view->setCamera(_mainCamera);
|
||||||
@@ -197,17 +184,6 @@ namespace flutter_filament
|
|||||||
const float sens = _mainCamera->getSensitivity();
|
const float sens = _mainCamera->getSensitivity();
|
||||||
|
|
||||||
Log("Camera aperture %f shutter %f sensitivity %f", aperture, shutterSpeed, sens);
|
Log("Camera aperture %f shutter %f sensitivity %f", aperture, shutterSpeed, sens);
|
||||||
|
|
||||||
View::DynamicResolutionOptions options;
|
|
||||||
options.enabled = false;
|
|
||||||
// options.homogeneousScaling = homogeneousScaling;
|
|
||||||
// options.minScale = filament::math::float2{ minScale };
|
|
||||||
// options.maxScale = filament::math::float2{ maxScale };
|
|
||||||
// options.sharpness = sharpness;
|
|
||||||
// options.quality = View::QualityLevel::ULTRA;
|
|
||||||
_view->setDynamicResolutionOptions(options);
|
|
||||||
|
|
||||||
setAntiAliasing(false, true, false);
|
|
||||||
|
|
||||||
EntityManager &em = EntityManager::get();
|
EntityManager &em = EntityManager::get();
|
||||||
|
|
||||||
@@ -292,14 +268,15 @@ namespace flutter_filament
|
|||||||
|
|
||||||
void FilamentViewer::setBloom(float strength)
|
void FilamentViewer::setBloom(float strength)
|
||||||
{
|
{
|
||||||
|
decltype(_view->getBloomOptions()) opts;
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
|
opts.enabled = false;
|
||||||
Log("Bloom is disabled on WebGL builds as it causes instability with certain drivers. setBloom will be ignored");
|
Log("Bloom is disabled on WebGL builds as it causes instability with certain drivers. setBloom will be ignored");
|
||||||
#else
|
#else
|
||||||
decltype(_view->getBloomOptions()) opts;
|
|
||||||
opts.enabled = true;
|
opts.enabled = true;
|
||||||
opts.strength = strength;
|
opts.strength = strength;
|
||||||
_view->setBloomOptions(opts);
|
|
||||||
#endif
|
#endif
|
||||||
|
_view->setBloomOptions(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::setToneMapping(ToneMapping toneMapping)
|
void FilamentViewer::setToneMapping(ToneMapping toneMapping)
|
||||||
@@ -335,7 +312,7 @@ namespace flutter_filament
|
|||||||
{
|
{
|
||||||
_frameInterval = frameInterval;
|
_frameInterval = frameInterval;
|
||||||
Renderer::FrameRateOptions fro;
|
Renderer::FrameRateOptions fro;
|
||||||
fro.interval = frameInterval;
|
fro.interval = 1; //frameInterval;
|
||||||
_renderer->setFrameRateOptions(fro);
|
_renderer->setFrameRateOptions(fro);
|
||||||
Log("Set framerate interval to %f", frameInterval);
|
Log("Set framerate interval to %f", frameInterval);
|
||||||
}
|
}
|
||||||
@@ -1045,7 +1022,7 @@ namespace flutter_filament
|
|||||||
if (secsSinceLastFpsCheck >= 1)
|
if (secsSinceLastFpsCheck >= 1)
|
||||||
{
|
{
|
||||||
auto fps = _frameCount / secsSinceLastFpsCheck;
|
auto fps = _frameCount / secsSinceLastFpsCheck;
|
||||||
Log("%ffps", fps);
|
Log("%ffps (%d skipped)", fps, _skippedFrames);
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
_skippedFrames = 0;
|
_skippedFrames = 0;
|
||||||
_fpsCounterStartTime = now;
|
_fpsCounterStartTime = now;
|
||||||
|
|||||||
@@ -206,8 +206,8 @@ namespace flutter_filament
|
|||||||
|
|
||||||
FilamentAsset *asset = nullptr;
|
FilamentAsset *asset = nullptr;
|
||||||
if(numInstances > 1) {
|
if(numInstances > 1) {
|
||||||
FilamentInstance* instances[numInstances];
|
std::vector<FilamentInstance*> instances(numInstances);
|
||||||
asset = _assetLoader->createInstancedAsset((const uint8_t *)data, length, instances, numInstances);
|
asset = _assetLoader->createInstancedAsset((const uint8_t *)data, length, instances.data(), numInstances);
|
||||||
} else {
|
} else {
|
||||||
asset = _assetLoader->createAsset(
|
asset = _assetLoader->createAsset(
|
||||||
(const uint8_t *)data, length);
|
(const uint8_t *)data, length);
|
||||||
|
|||||||
@@ -298,6 +298,8 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
throw Exception("Failed to get resource loader");
|
throw Exception("Failed to get resource loader");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var renderingSurface = await _createRenderingSurface();
|
||||||
|
|
||||||
if (Platform.isWindows && requiresTextureWidget) {
|
if (Platform.isWindows && requiresTextureWidget) {
|
||||||
_driver = Pointer<Void>.fromAddress(
|
_driver = Pointer<Void>.fromAddress(
|
||||||
await _channel.invokeMethod("getDriverPlatform"));
|
await _channel.invokeMethod("getDriverPlatform"));
|
||||||
@@ -310,7 +312,6 @@ class FilamentControllerFFI extends FilamentController {
|
|||||||
var renderCallbackOwner =
|
var renderCallbackOwner =
|
||||||
Pointer<Void>.fromAddress(renderCallbackResult[1]);
|
Pointer<Void>.fromAddress(renderCallbackResult[1]);
|
||||||
|
|
||||||
var renderingSurface = await _createRenderingSurface();
|
|
||||||
|
|
||||||
print("Got rendering surface");
|
print("Got rendering surface");
|
||||||
|
|
||||||
|
|||||||
@@ -305,5 +305,5 @@ class TransparencyPainter extends CustomPainter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
|
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ if(USE_ANGLE)
|
|||||||
add_compile_definitions(USE_ANGLE)
|
add_compile_definitions(USE_ANGLE)
|
||||||
list(APPEND PLUGIN_SOURCES "flutter_angle_texture.cpp" "egl_context.cpp" )
|
list(APPEND PLUGIN_SOURCES "flutter_angle_texture.cpp" "egl_context.cpp" )
|
||||||
else()
|
else()
|
||||||
add_compile_definitions(WGL_USE_BACKING_WINDOW)
|
if(WGL_USE_BACKING_WINDOW)
|
||||||
|
add_compile_definitions(WGL_USE_BACKING_WINDOW)
|
||||||
|
endif()
|
||||||
list(APPEND PLUGIN_SOURCES "wgl_context.cpp" "opengl_texture_buffer.cpp" "backing_window.cpp")
|
list(APPEND PLUGIN_SOURCES "wgl_context.cpp" "opengl_texture_buffer.cpp" "backing_window.cpp")
|
||||||
# if(WGL_USE_BACKING_WINDOW)
|
# if(WGL_USE_BACKING_WINDOW)
|
||||||
# list(APPEND PLUGIN_SOURCES )
|
# list(APPEND PLUGIN_SOURCES )
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <Commctrl.h>
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dwmapi.h>
|
#include <dwmapi.h>
|
||||||
#include <ShObjIdl.h>
|
#include <ShObjIdl.h>
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
|
|
||||||
#include "egl_context.h"
|
#include "egl_context.h"
|
||||||
|
|
||||||
|
#define FILAMENT_USE_EXTERNAL_GLES3
|
||||||
|
#include <gl_headers.h>
|
||||||
|
|
||||||
|
#pragma comment(lib, "dwmapi.lib")
|
||||||
|
#pragma comment(lib, "comctl32.lib")
|
||||||
|
|
||||||
namespace flutter_filament {
|
namespace flutter_filament {
|
||||||
|
|
||||||
EGLContext::EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter::TextureRegistrar* textureRegistrar); {
|
FlutterEGLContext::FlutterEGLContext(
|
||||||
|
flutter::PluginRegistrarWindows* pluginRegistrar,
|
||||||
|
flutter::TextureRegistrar* textureRegistrar) : FlutterRenderContext(pluginRegistrar, textureRegistrar) {
|
||||||
|
|
||||||
_platform = new filament::backend::PlatformEGL();
|
_platform = new filament::backend::PlatformEGL();
|
||||||
|
|
||||||
@@ -34,7 +43,7 @@ EGLContext::EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter
|
|||||||
dxgi->Release();
|
dxgi->Release();
|
||||||
if (!adapter_) {
|
if (!adapter_) {
|
||||||
std::cout << "Failed to locate default D3D adapter" << std::endl;
|
std::cout << "Failed to locate default D3D adapter" << std::endl;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC adapter_desc_;
|
DXGI_ADAPTER_DESC adapter_desc_;
|
||||||
@@ -49,7 +58,7 @@ EGLContext::EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter
|
|||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
std::cout << "Failed to create D3D device" << std::endl;
|
std::cout << "Failed to create D3D device" << std::endl;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device = nullptr;
|
Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device = nullptr;
|
||||||
@@ -74,7 +83,7 @@ EGLContext::EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter
|
|||||||
EGLBoolean bindAPI = eglBindAPI(EGL_OPENGL_ES_API);
|
EGLBoolean bindAPI = eglBindAPI(EGL_OPENGL_ES_API);
|
||||||
if (UTILS_UNLIKELY(!bindAPI)) {
|
if (UTILS_UNLIKELY(!bindAPI)) {
|
||||||
std::cout << "eglBindAPI EGL_OPENGL_ES_API failed" << std::endl;
|
std::cout << "eglBindAPI EGL_OPENGL_ES_API failed" << std::endl;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
@@ -106,10 +115,10 @@ EGLContext::EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter
|
|||||||
|
|
||||||
if (UTILS_UNLIKELY(!initialized)) {
|
if (UTILS_UNLIKELY(!initialized)) {
|
||||||
std::cout << "eglInitialize failed" << std::endl;
|
std::cout << "eglInitialize failed" << std::endl;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
importGLESExtensionsEntryPoints();
|
glext::importGLESExtensionsEntryPoints();
|
||||||
|
|
||||||
EGLint configsCount;
|
EGLint configsCount;
|
||||||
|
|
||||||
@@ -126,53 +135,66 @@ EGLContext::EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter
|
|||||||
// find an opaque config
|
// find an opaque config
|
||||||
if (!eglChooseConfig(_eglDisplay, configAttribs, &_eglConfig, 1,
|
if (!eglChooseConfig(_eglDisplay, configAttribs, &_eglConfig, 1,
|
||||||
&configsCount)) {
|
&configsCount)) {
|
||||||
return false;
|
std::cout << "Failed to find EGL config" << std::endl;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_context = (void *)eglCreateContext(_eglDisplay, _eglConfig, EGL_NO_CONTEXT,
|
auto ctx = eglCreateContext(_eglDisplay, _eglConfig, EGL_NO_CONTEXT,contextAttribs);
|
||||||
contextAttribs);
|
_context = (void*)ctx;
|
||||||
|
|
||||||
if (UTILS_UNLIKELY(_context == EGL_NO_CONTEXT)) {
|
if (UTILS_UNLIKELY(_context == EGL_NO_CONTEXT)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLContext::CreateRenderingSurface(
|
void FlutterEGLContext::CreateRenderingSurface(
|
||||||
uint32_t width, uint32_t height,
|
uint32_t width, uint32_t height,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result,
|
||||||
uint32_t left, uint32_t top
|
uint32_t left, uint32_t top
|
||||||
) {
|
) {
|
||||||
importGLESExtensionsEntryPoints();
|
|
||||||
|
glext::importGLESExtensionsEntryPoints();
|
||||||
|
|
||||||
if(left != 0 || top != 0) {
|
if(left != 0 || top != 0) {
|
||||||
result->Error("ERROR",
|
result->Error("ERROR",
|
||||||
"Rendering with EGL uses a Texture render target/Flutter widget and does not need a window offset.");
|
"Rendering with EGL uses a Texture render target/Flutter widget and does not need a window offset.");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_active.get()) {
|
if (_active.get()) {
|
||||||
result->Error("ERROR",
|
result->Error("ERROR",
|
||||||
"Texture already exists. You must call destroyTexture before "
|
"Texture already exists. You must call destroyTexture before "
|
||||||
"attempting to create a new one.");
|
"attempting to create a new one.");
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_active = std::make_unique<FlutterAngleTexture>(
|
std::unique_ptr<FlutterTextureBuffer> active = std::make_unique<FlutterAngleTexture>(
|
||||||
_pluginRegistrar, _textureRegistrar, std::move(result), width, height,
|
_pluginRegistrar, _textureRegistrar, std::move(result), width, height,
|
||||||
_D3D11Device, _D3D11DeviceContext, _eglConfig, _eglDisplay, _context,
|
_D3D11Device, _D3D11DeviceContext, _eglConfig, _eglDisplay, _context,
|
||||||
[=](size_t width, size_t height) {
|
[=](size_t width, size_t height) {
|
||||||
|
std::cout << "RESIZE" << std::endl;
|
||||||
std::vector<int64_t> list;
|
std::vector<int64_t> list;
|
||||||
list.push_back((int64_t)width);
|
list.push_back((int64_t)width);
|
||||||
list.push_back((int64_t)height);
|
list.push_back((int64_t)height);
|
||||||
auto val = std::make_unique<flutter::EncodableValue>(list);
|
// auto val = std::make_unique<flutter::EncodableValue>(list);
|
||||||
this->_channel->InvokeMethod("resize", std::move(val), nullptr);
|
// this->_channel->InvokeMethod("resize", std::move(val), nullptr);
|
||||||
});
|
});
|
||||||
|
_active = std::move(active);
|
||||||
|
|
||||||
return _active->flutterTextureId != -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLContext::GetSharedContext() {
|
void FlutterEGLContext::RenderCallback() {
|
||||||
return (void*)_eglContext;
|
if(_active.get()) {
|
||||||
|
((FlutterAngleTexture*)_active.get())->RenderCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FlutterEGLContext::GetSharedContext() {
|
||||||
|
return (void*)_context;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* FlutterEGLContext::GetPlatform() {
|
||||||
|
return (void*)_platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,35 @@
|
|||||||
#ifndef _EGL_CONTEXT_H
|
#ifndef _EGL_CONTEXT_H
|
||||||
#define _EGL_CONTEXT_H
|
#define _EGL_CONTEXT_H
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
#include <flutter/method_channel.h>
|
||||||
|
#include <flutter/plugin_registrar_windows.h>
|
||||||
|
#include <flutter/standard_method_codec.h>
|
||||||
|
#include <flutter/texture_registrar.h>
|
||||||
|
|
||||||
#include "flutter_angle_texture.h"
|
#include "flutter_angle_texture.h"
|
||||||
#include "backend/platforms/PlatformEGL.h"
|
#include "backend/platforms/PlatformEGL.h"
|
||||||
|
#include "flutter_render_context.h"
|
||||||
|
|
||||||
namespace flutter_filament {
|
namespace flutter_filament {
|
||||||
|
|
||||||
class EGLContext : public FlutterRenderingContext {
|
class FlutterEGLContext : public FlutterRenderContext {
|
||||||
public:
|
public:
|
||||||
EGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter::TextureRegistrar* textureRegistrar);
|
FlutterEGLContext(flutter::PluginRegistrarWindows* pluginRegistrar, flutter::TextureRegistrar* textureRegistrar);
|
||||||
|
void* GetSharedContext();
|
||||||
|
void RenderCallback();
|
||||||
|
void* GetPlatform();
|
||||||
|
void CreateRenderingSurface(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result, uint32_t left, uint32_t top );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EGLContext _context = NULL;
|
void* _context = nullptr;
|
||||||
EGLConfig _eglConfig = NULL;
|
EGLConfig _eglConfig = NULL;
|
||||||
EGLDisplay _eglDisplay = NULL;
|
EGLDisplay _eglDisplay = NULL;
|
||||||
std::unique_ptr<FlutterAngleTexture> _active = nullptr;
|
|
||||||
std::unique_ptr<FlutterAngleTexture> _inactive = nullptr;
|
|
||||||
ID3D11Device* _D3D11Device = nullptr;
|
ID3D11Device* _D3D11Device = nullptr;
|
||||||
ID3D11DeviceContext* _D3D11DeviceContext = nullptr;
|
ID3D11DeviceContext* _D3D11DeviceContext = nullptr;
|
||||||
filament::backend::Platform* _platform = nullptr;
|
filament::backend::Platform* _platform = nullptr;
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ FlutterAngleTexture::FlutterAngleTexture(
|
|||||||
resultList.push_back(flutter::EncodableValue(flutterTextureId));
|
resultList.push_back(flutter::EncodableValue(flutterTextureId));
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
||||||
resultList.push_back(flutter::EncodableValue(glTextureId));
|
resultList.push_back(flutter::EncodableValue(glTextureId));
|
||||||
|
resultList.push_back(flutter::EncodableValue((int64_t) eglContext));
|
||||||
result->Success(resultList);
|
result->Success(resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ typedef uint32_t GLuint;
|
|||||||
|
|
||||||
namespace flutter_filament {
|
namespace flutter_filament {
|
||||||
|
|
||||||
class FlutterAngleTexture : FlutterTextureBuffer {
|
class FlutterAngleTexture : public FlutterTextureBuffer {
|
||||||
public:
|
public:
|
||||||
FlutterAngleTexture(
|
FlutterAngleTexture(
|
||||||
flutter::PluginRegistrarWindows* pluginRegistrar,
|
flutter::PluginRegistrarWindows* pluginRegistrar,
|
||||||
|
|||||||
@@ -3,11 +3,7 @@
|
|||||||
|
|
||||||
#include "flutter_filament_plugin.h"
|
#include "flutter_filament_plugin.h"
|
||||||
|
|
||||||
// This must be included before many other Windows headers.
|
#include <Windows.h>
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
// For getPlatformVersion; remove unless needed for your plugin implementation.
|
|
||||||
#include <VersionHelpers.h>
|
|
||||||
|
|
||||||
#include <flutter/method_channel.h>
|
#include <flutter/method_channel.h>
|
||||||
#include <flutter/plugin_registrar_windows.h>
|
#include <flutter/plugin_registrar_windows.h>
|
||||||
@@ -18,7 +14,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <future>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -31,11 +27,6 @@
|
|||||||
|
|
||||||
#include "FlutterFilamentApi.h"
|
#include "FlutterFilamentApi.h"
|
||||||
|
|
||||||
#include <Commctrl.h>
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <dwmapi.h>
|
|
||||||
#include <wrl.h>
|
|
||||||
|
|
||||||
#include "flutter_render_context.h"
|
#include "flutter_render_context.h"
|
||||||
|
|
||||||
#if USE_ANGLE
|
#if USE_ANGLE
|
||||||
@@ -154,10 +145,16 @@ void render_callback(void *owner) {
|
|||||||
void FlutterFilamentPlugin::RenderCallback() {
|
void FlutterFilamentPlugin::RenderCallback() {
|
||||||
if (_context) {
|
if (_context) {
|
||||||
auto flutterTextureId = _context->GetFlutterTextureId();
|
auto flutterTextureId = _context->GetFlutterTextureId();
|
||||||
|
if(flutterTextureId == -1) {
|
||||||
|
std::cout << "Bad texture" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
#ifdef USE_ANGLE
|
#ifdef USE_ANGLE
|
||||||
_active->RenderCallback();
|
_context->RenderCallback();
|
||||||
#endif
|
#endif
|
||||||
|
#if !WGL_USE_BACKING_WINDOW
|
||||||
_textureRegistrar->MarkTextureFrameAvailable(flutterTextureId);
|
_textureRegistrar->MarkTextureFrameAvailable(flutterTextureId);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +180,7 @@ void FlutterFilamentPlugin::CreateTexture(
|
|||||||
// this will be used to create a backing texture and passed to Filament
|
// this will be used to create a backing texture and passed to Filament
|
||||||
if (!_context) {
|
if (!_context) {
|
||||||
#ifdef USE_ANGLE
|
#ifdef USE_ANGLE
|
||||||
_context = std::make_unique<EGLContext>(_pluginRegistrar);
|
_context = std::make_unique<FlutterEGLContext>(_pluginRegistrar, _textureRegistrar);
|
||||||
#else
|
#else
|
||||||
_context = std::make_unique<WGLContext>(_pluginRegistrar, _textureRegistrar);
|
_context = std::make_unique<WGLContext>(_pluginRegistrar, _textureRegistrar);
|
||||||
#endif
|
#endif
|
||||||
@@ -195,7 +192,6 @@ void FlutterFilamentPlugin::DestroyTexture(
|
|||||||
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
const flutter::MethodCall<flutter::EncodableValue> &methodCall,
|
||||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||||
|
|
||||||
|
|
||||||
const auto *flutterTextureId = std::get_if<int64_t>(methodCall.arguments());
|
const auto *flutterTextureId = std::get_if<int64_t>(methodCall.arguments());
|
||||||
|
|
||||||
if (!flutterTextureId) {
|
if (!flutterTextureId) {
|
||||||
@@ -261,7 +257,7 @@ void FlutterFilamentPlugin::HandleMethodCall(
|
|||||||
result->Success(resultList);
|
result->Success(resultList);
|
||||||
} else if (methodCall.method_name() == "getDriverPlatform") {
|
} else if (methodCall.method_name() == "getDriverPlatform") {
|
||||||
#ifdef USE_ANGLE
|
#ifdef USE_ANGLE
|
||||||
result->Success(flutter::EncodableValue((int64_t)_platform));
|
result->Success(flutter::EncodableValue((int64_t)_context->GetPlatform()));
|
||||||
#else
|
#else
|
||||||
result->Success(flutter::EncodableValue((int64_t) nullptr));
|
result->Success(flutter::EncodableValue((int64_t) nullptr));
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "FlutterFilamentApi.h"
|
#include "FlutterFilamentApi.h"
|
||||||
|
|
||||||
#if ANGLE
|
#if USE_ANGLE
|
||||||
#include "egl_context.h"
|
#include "egl_context.h"
|
||||||
#else
|
#else
|
||||||
#include "wgl_context.h"
|
#include "wgl_context.h"
|
||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef USE_ANGLE
|
#ifdef USE_ANGLE
|
||||||
std::unique_ptr<EGLContext> _context = nullptr;
|
std::unique_ptr<FlutterEGLContext> _context = nullptr;
|
||||||
#else
|
#else
|
||||||
std::unique_ptr<WGLContext> _context = nullptr;
|
std::unique_ptr<WGLContext> _context = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace flutter_filament {
|
|||||||
|
|
||||||
class FlutterRenderContext {
|
class FlutterRenderContext {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void CreateRenderingSurface(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result, uint32_t left, uint32_t top );
|
void CreateRenderingSurface(uint32_t width, uint32_t height, std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result, uint32_t left, uint32_t top );
|
||||||
|
|
||||||
void DestroyTexture(std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
void DestroyTexture(std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
||||||
@@ -33,11 +34,15 @@ namespace flutter_filament {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
int64_t GetFlutterTextureId() {
|
int64_t GetFlutterTextureId() {
|
||||||
|
if(!_active) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return _active->flutterTextureId;
|
return _active->flutterTextureId;
|
||||||
}
|
}
|
||||||
void* sharedContext = nullptr;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
FlutterRenderContext( flutter::PluginRegistrarWindows* pluginRegistrar, flutter::TextureRegistrar* textureRegistrar) : _pluginRegistrar(pluginRegistrar), _textureRegistrar(textureRegistrar) {};
|
||||||
|
|
||||||
flutter::PluginRegistrarWindows* _pluginRegistrar;
|
flutter::PluginRegistrarWindows* _pluginRegistrar;
|
||||||
flutter::TextureRegistrar* _textureRegistrar;
|
flutter::TextureRegistrar* _textureRegistrar;
|
||||||
std::unique_ptr<FlutterTextureBuffer> _active = nullptr;
|
std::unique_ptr<FlutterTextureBuffer> _active = nullptr;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace flutter_filament {
|
|||||||
|
|
||||||
class FlutterTextureBuffer {
|
class FlutterTextureBuffer {
|
||||||
public:
|
public:
|
||||||
int64_t flutterTextureId = 0;
|
int64_t flutterTextureId = -1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,11 +117,15 @@ OpenGLTextureBuffer::OpenGLTextureBuffer(
|
|||||||
flutterTextureId = textureRegistrar->RegisterTexture(texture.get());
|
flutterTextureId = textureRegistrar->RegisterTexture(texture.get());
|
||||||
std::cout << "Registered Flutter texture ID " << flutterTextureId
|
std::cout << "Registered Flutter texture ID " << flutterTextureId
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::vector<flutter::EncodableValue> resultList;
|
|
||||||
resultList.push_back(flutter::EncodableValue(flutterTextureId));
|
if (flutterTextureId != -1) {
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
std::vector<flutter::EncodableValue> resultList;
|
||||||
resultList.push_back(flutter::EncodableValue(glTextureId));
|
resultList.push_back(flutter::EncodableValue(flutterTextureId));
|
||||||
result->Success(resultList);
|
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
||||||
|
resultList.push_back(flutter::EncodableValue(glTextureId));
|
||||||
|
resultList.push_back(flutter::EncodableValue((int64_t)_context));
|
||||||
|
result->Success(resultList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGLTextureBuffer::~OpenGLTextureBuffer() {
|
OpenGLTextureBuffer::~OpenGLTextureBuffer() {
|
||||||
|
|||||||
@@ -10,94 +10,13 @@ namespace flutter_filament {
|
|||||||
|
|
||||||
WGLContext::WGLContext(flutter::PluginRegistrarWindows *pluginRegistrar,
|
WGLContext::WGLContext(flutter::PluginRegistrarWindows *pluginRegistrar,
|
||||||
flutter::TextureRegistrar *textureRegistrar)
|
flutter::TextureRegistrar *textureRegistrar)
|
||||||
: _pluginRegistrar(pluginRegistrar), _textureRegistrar(textureRegistrar) {
|
: FlutterRenderContext(pluginRegistrar, textureRegistrar) {
|
||||||
|
|
||||||
auto hwnd = pluginRegistrar->GetView()->GetNativeWindow();
|
|
||||||
|
|
||||||
HDC whdc = GetDC(hwnd);
|
|
||||||
if (whdc == NULL) {
|
|
||||||
std::cout << "No device context for temporary window" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "No GL context exists, creating" << std::endl;
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
std::cout << "Failed to acquire temporary context" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLenum err = glGetError();
|
|
||||||
|
|
||||||
if (err != GL_NO_ERROR) {
|
|
||||||
std::cout << "GL Error @ 455 %d" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs = nullptr;
|
|
||||||
|
|
||||||
wglCreateContextAttribs =
|
|
||||||
(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress(
|
|
||||||
"wglCreateContextAttribsARB");
|
|
||||||
|
|
||||||
if (!wglCreateContextAttribs) {
|
|
||||||
std::cout << "Failed to resolve wglCreateContextAttribsARB" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
std::cout << "Failed to create OpenGL context." << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WGLContext::ResizeRenderingSurface(uint32_t width, uint32_t height, uint32_t left, uint32_t top) {
|
void WGLContext::ResizeRenderingSurface(uint32_t width, uint32_t height, uint32_t left, uint32_t top) {
|
||||||
|
#if WGL_USE_BACKING_WINDOW
|
||||||
_backingWindow->Resize(width, height, left, top);
|
_backingWindow->Resize(width, height, left, top);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WGLContext::CreateRenderingSurface(
|
void WGLContext::CreateRenderingSurface(
|
||||||
@@ -116,7 +35,7 @@ void WGLContext::CreateRenderingSurface(
|
|||||||
resultList.push_back(
|
resultList.push_back(
|
||||||
flutter::EncodableValue((int64_t)_backingWindow->GetHandle()));
|
flutter::EncodableValue((int64_t)_backingWindow->GetHandle()));
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t)sharedContext));
|
resultList.push_back(flutter::EncodableValue((int64_t)_context));
|
||||||
result->Success(resultList);
|
result->Success(resultList);
|
||||||
#else
|
#else
|
||||||
if(left != 0 || top != 0) {
|
if(left != 0 || top != 0) {
|
||||||
@@ -128,20 +47,10 @@ void WGLContext::CreateRenderingSurface(
|
|||||||
"attempting to create a new one.");
|
"attempting to create a new one.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_active = std::make_unique<OpenGLTextureBuffer>(
|
auto active = std::make_unique<OpenGLTextureBuffer>(
|
||||||
_pluginRegistrar, _textureRegistrar, std::move(result), width, height,
|
_pluginRegistrar, _textureRegistrar, std::move(result), width, height,
|
||||||
_context);
|
_context);
|
||||||
|
_active = std::move(active);
|
||||||
if (_active->flutterTextureId != -1) {
|
|
||||||
std::vector<flutter::EncodableValue> resultList;
|
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
|
||||||
resultList.push_back(flutter::EncodableValue((int64_t)sharedContext));
|
|
||||||
result->Success(resultList);
|
|
||||||
} else {
|
|
||||||
result->Error("NO_FLUTTER_TEXTURE", "Unknown error registering texture with Flutter.", nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ namespace flutter_filament {
|
|||||||
uint32_t width, uint32_t height, uint32_t left, uint32_t top
|
uint32_t width, uint32_t height, uint32_t left, uint32_t top
|
||||||
);
|
);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
flutter::PluginRegistrarWindows* _pluginRegistrar = nullptr;
|
|
||||||
flutter::TextureRegistrar* _textureRegistrar = nullptr;
|
|
||||||
HGLRC _context = NULL;
|
HGLRC _context = NULL;
|
||||||
#if WGL_USE_BACKING_WINDOW
|
#if WGL_USE_BACKING_WINDOW
|
||||||
std::unique_ptr<BackingWindow> _backingWindow = nullptr;
|
std::unique_ptr<BackingWindow> _backingWindow = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user