Skip to content

Commit

Permalink
Fix screen flickering when glClear is not called
Browse files Browse the repository at this point in the history
  • Loading branch information
hbatagelo committed Oct 27, 2021
1 parent 1d77c08 commit 302394a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions VERSION.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
Version history
======

### v2.0.0
### v2.0.1

#### Breaking changes
* `abcg::Application::run` now takes by value a unique pointer to `abcg::OpenGLWindow`. Since `std::unique_ptr` cannot be copied, the caller must either use `std::move` or pass the pointer as an rvalue. This makes clear the intent of transferring ownership of the pointer, which was not explicit in the previous version that takes an lvalue reference.
* Support for running multiple windows has been dropped. Multiple windows weren't working properly on Emscripten builds and aren't used in the course.
* `abcg::opengl::loadCubemap` now transforms the cube map textures to a right-handed coordinate system by default. A small loading overhead is incurred because some of the bitmaps are flipped vertically and horizontally. This behavior can be disabled by setting the (new) parameter `rightHandedSystem` to `false`.

#### Bug Fixes
* Fixed flickering effect when `glClear` is not called for each frame. For this fix to work, `abcg::OpenGLSettings::preserveWebGLDrawingBuffer` must be `true` even when building for desktop.

#### Other changes
* `abcg::Exception::OpenGL` now generates a string describing all OpenGL error messages returned by `glGetError` when there are multiple errors.
* All OpenGL functions from OpenGL ES 2.0 and ES 3.0 can now be qualified with the `abcg` namespace (e.g. `abcg::glActiveTexture(0)`) for automatic error handling in debug builds. This is an alternative to the `GL_CHECK` macro used in many engines to check for errors before and after each GL call.
* Now, by default, `abcg::opengl::loadCubemap` transforms the cube map textures to a right-handed coordinate system. This will add a small loading overhead because some of the bitmaps are flipped vertically and horizontally. This behavior can be disabled by setting the (new) parameter `rightHandedSystem` to `false`.
* Updated external libraries (Dear ImGui v1.84; cppitertools v2.1; {fmt} 8.0.1).

### v1.0.0
Expand Down
14 changes: 12 additions & 2 deletions abcg/abcg_openglwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,12 @@ void abcg::OpenGLWindow::initialize(std::string_view basePath) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (m_openGLSettings.preserveWebGLDrawingBuffer) {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
} else {
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
}

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_openGLSettings.depthBufferSize);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_openGLSettings.stencilSize);
if (m_openGLSettings.samples > 0) {
Expand Down Expand Up @@ -696,7 +701,12 @@ void abcg::OpenGLWindow::paint() {
ImGui::Render();
paintGL();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(m_window);

if (m_openGLSettings.preserveWebGLDrawingBuffer) {
glFinish();
} else {
SDL_GL_SwapWindow(m_window);
}

// Cap to 480 Hz
if (m_deltaTime.elapsed() >= 1.0 / 480.0) {
Expand Down

0 comments on commit 302394a

Please sign in to comment.