From d4290a951593f4405de665a4c1559aa45d9a1d8c Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 9 Jul 2014 19:26:21 -0700 Subject: [PATCH] Handle resize better --- project/src/backend/sdl/SDLApplication.cpp | 18 +++++++- project/src/backend/sdl/SDLRenderer.cpp | 48 ++++++++-------------- project/src/backend/sdl/SDLRenderer.h | 1 + samples/SimpleImage/Source/Main.hx | 8 ++-- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 4f4281538..d02d8c437 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -18,6 +18,17 @@ namespace lime { SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER); + currentUpdate = 0; + lastUpdate = 0; + nextUpdate = 0; + + KeyEvent keyEvent; + MouseEvent mouseEvent; + RenderEvent renderEvent; + TouchEvent touchEvent; + UpdateEvent updateEvent; + WindowEvent windowEvent; + } @@ -162,7 +173,6 @@ namespace lime { case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_HIDDEN: - case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_MOVED: @@ -175,6 +185,12 @@ namespace lime { RenderEvent::Dispatch (&renderEvent); break; + case SDL_WINDOWEVENT_SIZE_CHANGED: + + ProcessWindowEvent (event); + RenderEvent::Dispatch (&renderEvent); + break; + case SDL_WINDOWEVENT_CLOSE: ProcessWindowEvent (event); diff --git a/project/src/backend/sdl/SDLRenderer.cpp b/project/src/backend/sdl/SDLRenderer.cpp index f8a3c9409..2f4088431 100644 --- a/project/src/backend/sdl/SDLRenderer.cpp +++ b/project/src/backend/sdl/SDLRenderer.cpp @@ -11,40 +11,26 @@ namespace lime { currentWindow = window; sdlWindow = ((SDLWindow*)window)->sdlWindow; - if (OpenGLBindings::Init ()) { + int sdlFlags = SDL_RENDERER_ACCELERATED; + + if (window->flags & WINDOW_FLAG_VSYNC) sdlFlags |= SDL_RENDERER_PRESENTVSYNC; + + if (window->flags & WINDOW_FLAG_DEPTH_BUFFER) { - SDL_GLContext context = SDL_GL_CreateContext (sdlWindow); - - if (context) { - - if (window->flags & WINDOW_FLAG_VSYNC) { - - SDL_GL_SetSwapInterval (1); - - } else { - - SDL_GL_SetSwapInterval (0); - - } - - if (window->flags & WINDOW_FLAG_DEPTH_BUFFER) { - - SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (window->flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0); - - } - - if (window->flags & WINDOW_FLAG_STENCIL_BUFFER) { - - SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8); - - } - - SDL_GL_MakeCurrent (sdlWindow, context); - - } + SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 32 - (window->flags & WINDOW_FLAG_STENCIL_BUFFER) ? 8 : 0); } + if (window->flags & WINDOW_FLAG_STENCIL_BUFFER) { + + SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8); + + } + + sdlRenderer = SDL_CreateRenderer (sdlWindow, -1, sdlFlags); + + OpenGLBindings::Init (); + } @@ -57,7 +43,7 @@ namespace lime { void SDLRenderer::Flip () { - SDL_GL_SwapWindow (sdlWindow); + SDL_RenderPresent (sdlRenderer); } diff --git a/project/src/backend/sdl/SDLRenderer.h b/project/src/backend/sdl/SDLRenderer.h index 094be6100..602b20673 100644 --- a/project/src/backend/sdl/SDLRenderer.h +++ b/project/src/backend/sdl/SDLRenderer.h @@ -18,6 +18,7 @@ namespace lime { virtual void Flip (); + SDL_Renderer* sdlRenderer; SDL_Window* sdlWindow; }; diff --git a/samples/SimpleImage/Source/Main.hx b/samples/SimpleImage/Source/Main.hx index c1ff0d674..243ff725f 100644 --- a/samples/SimpleImage/Source/Main.hx +++ b/samples/SimpleImage/Source/Main.hx @@ -13,6 +13,7 @@ class Main extends Application { private var buffer:GLBuffer; + private var matrixUniform:GLUniformLocation; private var program:GLProgram; private var texture:GLTexture; private var textureAttribute:Int; @@ -89,14 +90,12 @@ class Main extends Application { vertexAttribute = gl.getAttribLocation (program, "aPosition"); textureAttribute = gl.getAttribLocation (program, "aTexCoord"); - var matrixUniform = gl.getUniformLocation (program, "uMatrix"); + matrixUniform = gl.getUniformLocation (program, "uMatrix"); var imageUniform = gl.getUniformLocation (program, "uImage0"); gl.enableVertexAttribArray (vertexAttribute); gl.enableVertexAttribArray (textureAttribute); - gl.uniform1i (imageUniform, 0); - gl.uniformMatrix4fv (matrixUniform, false, Matrix4.createOrtho (0, window.width, window.height, 0, -1000, 1000)); var image = Assets.getImage ("assets/lime.png"); @@ -148,6 +147,9 @@ class Main extends Application { gl.clearColor (r, g, b, a); gl.clear (gl.COLOR_BUFFER_BIT); + var matrix = Matrix4.createOrtho (0, window.width, window.height, 0, -1000, 1000); + gl.uniformMatrix4fv (matrixUniform, false, matrix); + gl.activeTexture (gl.TEXTURE0); gl.bindTexture (gl.TEXTURE_2D, texture);