no need to create WGL context explicitly - defer to Engine
This commit is contained in:
@@ -11,89 +11,6 @@ namespace flutter_filament {
|
|||||||
WGLContext::WGLContext(flutter::PluginRegistrarWindows *pluginRegistrar,
|
WGLContext::WGLContext(flutter::PluginRegistrarWindows *pluginRegistrar,
|
||||||
flutter::TextureRegistrar *textureRegistrar)
|
flutter::TextureRegistrar *textureRegistrar)
|
||||||
: FlutterRenderContext(pluginRegistrar, 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_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, // Flags
|
|
||||||
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
|
|
||||||
24, // Colordepth of the framebuffer.
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
16, // 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) {
|
||||||
@@ -118,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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user