event channel handlers
This commit is contained in:
@@ -104,6 +104,13 @@ static void _freeResource(ResourceBuffer rbf, void *const plugin) {
|
|||||||
void PolyvoxFilamentPlugin::CreateFilamentViewer(
|
void PolyvoxFilamentPlugin::CreateFilamentViewer(
|
||||||
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 *args =
|
||||||
|
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
||||||
|
|
||||||
|
const auto width = uint32_t(*(std::get_if<double>(&(args->at(0)))));
|
||||||
|
const auto height = uint32_t(*(std::get_if<double>(&(args->at(1)))));
|
||||||
|
|
||||||
const ResourceLoaderWrapper *const resourceLoader =
|
const ResourceLoaderWrapper *const resourceLoader =
|
||||||
new ResourceLoaderWrapper(_loadResource, _freeResource, this);
|
new ResourceLoaderWrapper(_loadResource, _freeResource, this);
|
||||||
|
|
||||||
@@ -111,30 +118,11 @@ void PolyvoxFilamentPlugin::CreateFilamentViewer(
|
|||||||
|
|
||||||
_viewer = (void *)create_filament_viewer(_context, resourceLoader);
|
_viewer = (void *)create_filament_viewer(_context, resourceLoader);
|
||||||
|
|
||||||
std::cout << "Created filament viewer " << std::endl;
|
|
||||||
|
|
||||||
// auto hwnd = _pluginRegistrar->GetView()->GetNativeWindow();
|
// auto hwnd = _pluginRegistrar->GetView()->GetNativeWindow();
|
||||||
|
|
||||||
create_swap_chain(_viewer, nullptr, 1024, 768);
|
create_swap_chain(_viewer, nullptr, width, height);
|
||||||
|
|
||||||
// create_render_target(_viewer, _glTextureId, 1024, 768);
|
create_render_target(_viewer, _glTextureId, width, height);
|
||||||
|
|
||||||
// Update the texture @ 10 Hz
|
|
||||||
// Setting this to 60 Hz might cause epileptic shocks :D
|
|
||||||
_frameInterval = std::chrono::milliseconds(1000 / 60);
|
|
||||||
// std::thread([&]() {
|
|
||||||
// while (true) {
|
|
||||||
// if (_rendering) {
|
|
||||||
// auto callback = [](void *buf, size_t size, void *data) {
|
|
||||||
// auto plugin = (PolyvoxFilamentPlugin*)data;
|
|
||||||
// plugin->_textureRegistrar->MarkTextureFrameAvailable(
|
|
||||||
// plugin->_flutterTextureId);
|
|
||||||
// };
|
|
||||||
// render(_viewer, 0, _pixelData.get(), callback, this);
|
|
||||||
// }
|
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(_frameInterval));
|
|
||||||
// }
|
|
||||||
// }).detach();
|
|
||||||
|
|
||||||
result->Success(flutter::EncodableValue((int64_t)_viewer));
|
result->Success(flutter::EncodableValue((int64_t)_viewer));
|
||||||
}
|
}
|
||||||
@@ -147,7 +135,10 @@ void PolyvoxFilamentPlugin::Render(
|
|||||||
plugin->_textureRegistrar->MarkTextureFrameAvailable(
|
plugin->_textureRegistrar->MarkTextureFrameAvailable(
|
||||||
plugin->_flutterTextureId);
|
plugin->_flutterTextureId);
|
||||||
};
|
};
|
||||||
render(_viewer, 0, _pixelData.get(), callback, this);
|
// render(_viewer, 0, _pixelData.get(), callback, this);
|
||||||
|
render(_viewer, 0, nullptr, nullptr, nullptr);
|
||||||
|
_textureRegistrar->MarkTextureFrameAvailable(_flutterTextureId);
|
||||||
|
|
||||||
result->Success(flutter::EncodableValue(true));
|
result->Success(flutter::EncodableValue(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +152,12 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
|||||||
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 *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)))));
|
||||||
|
|
||||||
HWND hwnd = _pluginRegistrar->GetView()
|
HWND hwnd = _pluginRegistrar->GetView()
|
||||||
->GetNativeWindow(); // CreateWindowA("STATIC", "dummy", 0, 0,
|
->GetNativeWindow(); // CreateWindowA("STATIC", "dummy", 0, 0,
|
||||||
// 0, 1, 1, NULL, NULL, NULL, NULL);
|
// 0, 1, 1, NULL, NULL, NULL, NULL);
|
||||||
@@ -245,7 +242,7 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_pixelData.reset(new uint8_t[1024 * 768 * 4]);
|
_pixelData.reset(new uint8_t[width * height * 4]);
|
||||||
|
|
||||||
glGenTextures(1, &_glTextureId);
|
glGenTextures(1, &_glTextureId);
|
||||||
|
|
||||||
@@ -258,45 +255,57 @@ void PolyvoxFilamentPlugin::CreateTexture(
|
|||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1024, 768, 0, GL_RGBA,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,
|
||||||
GL_UNSIGNED_BYTE, 0);
|
GL_UNSIGNED_BYTE, 0);
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
|
||||||
|
if (err != GL_NO_ERROR) {
|
||||||
|
result->Error("ERROR", "Failed to generate texture, GL error was %d", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_pixelBuffer = std::make_unique<FlutterDesktopPixelBuffer>();
|
_pixelBuffer = std::make_unique<FlutterDesktopPixelBuffer>();
|
||||||
_pixelBuffer->buffer = _pixelData.get();
|
_pixelBuffer->buffer = _pixelData.get();
|
||||||
|
|
||||||
_pixelBuffer->width = 1024;
|
_pixelBuffer->width = size_t(width);
|
||||||
_pixelBuffer->height = 768;
|
_pixelBuffer->height = size_t(height);
|
||||||
|
|
||||||
_texture =
|
_texture =
|
||||||
std::make_unique<flutter::TextureVariant>(flutter::PixelBufferTexture(
|
std::make_unique<flutter::TextureVariant>(flutter::PixelBufferTexture(
|
||||||
[=](size_t width,
|
[=](size_t width,
|
||||||
size_t height) -> const FlutterDesktopPixelBuffer * {
|
size_t height) -> const FlutterDesktopPixelBuffer * {
|
||||||
// if(!_context || !wglMakeCurrent(whdc, _context)) {
|
if(!_context || !wglMakeCurrent(whdc, _context)) {
|
||||||
// std::cout << "Failed to switch OpenGL context." << std::endl;
|
std::cout << "Failed to switch OpenGL context." << std::endl;
|
||||||
// } else {
|
} else {
|
||||||
// uint8_t* data = new uint8_t[1024*768*4];
|
uint8_t* data = new uint8_t[width*height*4];
|
||||||
// auto buf = _pixelData.get();
|
glBindTexture(GL_TEXTURE_2D, _glTextureId);
|
||||||
// for(int y = 0; y < 768; y++) {
|
glGetTexImage(GL_TEXTURE_2D,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
|
||||||
// for(int x=0; x < 1024; x++) {
|
|
||||||
// data[y*768 + (x*4)] = uint8_t(buf[y*768 + (x*4)] * 255);
|
GLenum err = glGetError();
|
||||||
// data[y*768 + (x*4+1)] = uint8_t(buf[y*768 + (x*4)] * 255);
|
|
||||||
// data[y*768 + (x*4+2)] = uint8_t(buf[y*768 + (x*4)] * 255);
|
if(err != GL_NO_ERROR) {
|
||||||
// data[y*768 + (x*4+3)] = 255;
|
if(err == GL_INVALID_OPERATION) {
|
||||||
// }
|
std::cout << "Invalid op" << std::endl;
|
||||||
// }
|
} else if(err == GL_INVALID_VALUE) {
|
||||||
// glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
|
std::cout << "Invalid value" << std::endl;
|
||||||
// glClear(GL_COLOR_BUFFER_BIT);
|
} else if(err == GL_OUT_OF_MEMORY) {
|
||||||
// glReadPixels(0,0, (GLsizei)1024, (GLsizei)768, GL_RGBA,
|
std::cout << "Out of mem" << std::endl;
|
||||||
// GL_UNSIGNED_BYTE, data);
|
} else if(err == GL_INVALID_ENUM ) {
|
||||||
// _pixelData.reset(data);
|
std::cout << "Invalid enum" << std::endl;
|
||||||
_pixelBuffer->buffer = _pixelData.get();
|
} else {
|
||||||
// wglMakeCurrent(NULL, NULL);
|
std::cout << "Unknown error" << std::endl;
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_pixelData.reset(data);
|
||||||
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
}
|
||||||
_pixelBuffer->buffer = _pixelData.get();
|
_pixelBuffer->buffer = _pixelData.get();
|
||||||
|
|
||||||
return _pixelBuffer.get();
|
return _pixelBuffer.get();
|
||||||
|
|||||||
Reference in New Issue
Block a user