Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GL Context Resource Busy #16

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
project(skui)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
Expand All @@ -33,6 +34,14 @@ set(CMAKE_CXX_EXTENSIONS OFF)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# MSVC static
if (MSVC)
option(SKUI_USE_STATIC_LIBRARY "Use MSVC static build" OFF)
if(SKUI_USE_STATIC_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()

# 3rdparty dependencies
option(SKUI_USE_PREBUILT_3RDPARTY "Use a prebuilt 3rdparty package" OFF)
set(SKUI_PREBUILT_3RDPARTY_PATH CACHE STRING "NOTSET")
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Update

Fork from [skui-org/skui](https://github.com/skui-org/skui).
Solve the OpenGL rendering problem and make it run properly on Windows.

# Introduction

UI framework that uses [Skia](https://skia.org/) as a low-level drawing toolkit.
Expand Down
5 changes: 3 additions & 2 deletions core/library_windows.c++
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ namespace skui::core
path directory = fs::absolute(filename).remove_filename();
path filename_only = filename.filename();

std::array<path, 3> filenames{{directory / filename_only,
std::array<path, 4> filenames{{directory / filename_only,
directory / (filename_only + dll_suffix),
directory / (dll_prefix + filename_only + dll_suffix)}};
directory / (dll_prefix + filename_only + dll_suffix),
filename_only}};

for(const auto& filepath : filenames)
{
Expand Down
1 change: 1 addition & 0 deletions gui/native_visual.h++
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace skui::gui::native_visual

virtual void create_surface(std::uintptr_t window) = 0;
virtual void make_current() const = 0;
virtual void make_no_current() const = 0;
virtual void swap_buffers(const graphics::pixel_size& size) const = 0;

using gl_function_type = void(*)();
Expand Down
3 changes: 3 additions & 0 deletions gui/native_visual/cgl.c++
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ namespace skui::gui::native_visual
void cgl::make_current() const
{}

void cgl::make_no_current() const
{}

void cgl::swap_buffers(const graphics::pixel_size&) const
{}

Expand Down
1 change: 1 addition & 0 deletions gui/native_visual/cgl.h++
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace skui::gui::native_visual

void create_surface(std::uintptr_t window) override;
void make_current() const override;
void make_no_current() const override;
void swap_buffers(const graphics::pixel_size&) const override;

gl_get_function_type get_gl_function() const override;
Expand Down
3 changes: 3 additions & 0 deletions gui/native_visual/coregraphics.c++
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace skui::gui::native_visual
void coregraphics::make_current() const
{}

void coregraphics::make_no_current() const
{}

void coregraphics::swap_buffers(const graphics::pixel_size&) const
{}
}
1 change: 1 addition & 0 deletions gui/native_visual/coregraphics.h++
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace skui::gui::native_visual

void create_surface(std::uintptr_t window) override;
void make_current() const override;
void make_no_current() const override;
void swap_buffers(const graphics::pixel_size&) const override;
};
}
Expand Down
5 changes: 5 additions & 0 deletions gui/native_visual/egl.c++
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ namespace skui::gui::native_visual
eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
}

void egl::make_current() const
{
eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}

void egl::swap_buffers(const graphics::pixel_size&) const
{
eglSwapBuffers(egl_display, egl_surface);
Expand Down
1 change: 1 addition & 0 deletions gui/native_visual/egl.h++
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace skui::gui::native_visual

void create_surface(std::uintptr_t window) override;
void make_current() const override;
void make_no_current() const override;
void swap_buffers(const graphics::pixel_size&) const override;

EGLint get_egl_visual();
Expand Down
5 changes: 5 additions & 0 deletions gui/native_visual/glx.c++
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ namespace skui::gui::native_visual
core::debug_print("Call to glXMakeCurrent failed.\n");
}

void glx::make_no_current() const
{
glXMakeCurrent(display, None, NULL)
}

void glx::swap_buffers(const graphics::pixel_size&) const
{
glXSwapBuffers(display, drawable);
Expand Down
1 change: 1 addition & 0 deletions gui/native_visual/glx.h++
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace skui::gui::native_visual

void create_surface(std::uintptr_t window) override;
void make_current() const override;
void make_no_current() const override;
void swap_buffers(const graphics::pixel_size&) const override;

gl_get_function_type get_gl_function() const override;
Expand Down
11 changes: 8 additions & 3 deletions gui/native_visual/wgl.c++
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace skui::gui::native_visual
{
base::gl_function_type get_gl(void*, const char name[])
{
auto p = (base::gl_function_type)wglGetProcAddress(name);
auto p = (base::gl_function_type)wglGetProcAddress(name);
if(p == 0 ||
p == reinterpret_cast<base::gl_function_type>(0x1) ||
p == reinterpret_cast<base::gl_function_type>(0x2) ||
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace skui::gui::native_visual
0,
0,
0, 0, 0, 0,
24, //Number of bits for the depthbuffer
24, //Number of bits for the depthbuffer
8, //Number of bits for the stencilbuffer
0, //Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
Expand Down Expand Up @@ -105,7 +105,12 @@ namespace skui::gui::native_visual
{
BOOL success = wglMakeCurrent(device_context, gl_context);
if(success == FALSE)
core::debug_print("Failed making WGL Context current.\n");
core::debug_print("Failed making WGL Context current. (", GetLastError(), ")\n");
}

void wgl::make_no_current() const
{
wglMakeCurrent(NULL, NULL);
}

base::gl_get_function_type wgl::get_gl_function() const
Expand Down
1 change: 1 addition & 0 deletions gui/native_visual/wgl.h++
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace skui::gui::native_visual
void create_surface(std::uintptr_t window) override;
void swap_buffers(const graphics::pixel_size&) const override;
void make_current() const override;
void make_no_current() const override;

gl_get_function_type get_gl_function() const override;

Expand Down
5 changes: 5 additions & 0 deletions gui/native_visual/win32.c++
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ namespace skui::gui::native_visual

}

void win32::make_no_current() const
{

}

void win32::swap_buffers(const graphics::pixel_size& size) const
{
BITMAPINFO bitmap_info = create_bitmapinfo(size);
Expand Down
1 change: 1 addition & 0 deletions gui/native_visual/win32.h++
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace skui::gui::native_visual

void create_surface(std::uintptr_t window) override;
void make_current() const override;
void make_no_current() const override;
void swap_buffers(const graphics::pixel_size& size) const override;

private:
Expand Down
4 changes: 4 additions & 0 deletions gui/native_visual/xcb.c++
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ namespace skui::gui::native_visual
{
}

void xcb::make_no_current() const
{
}

void xcb::swap_buffers(const graphics::pixel_size& size) const
{
const std::uint16_t width = static_cast<std::uint16_t>(size.width);
Expand Down
1 change: 1 addition & 0 deletions gui/native_visual/xcb.h++
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace skui::gui::native_visual

void create_surface(std::uintptr_t window) override;
void make_current() const override;
void make_no_current() const override;
void swap_buffers(const graphics::pixel_size& size) const override;

xcb_visualid_t visualid() const;
Expand Down
7 changes: 7 additions & 0 deletions gui/window.c++
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ namespace skui::gui
// Ensure initialize_and_execute_platform_loop is waiting on handle_condition_variable
std::unique_lock handle_lock{mutex};
}

// Release context so that main thread to have right to access GL
{
const auto& native_visual = native_window->get_native_visual();
native_visual.make_no_current();
}

initialized = true;
handle_condition_variable.notify_all();

Expand Down