X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fsdl2%2Fg_system.pas;h=6f48d28bef982189e1b68bd9243f897eb723ce5f;hb=fa89488f45ed157516a0126f4c291a11a22765d7;hp=e4bd07046a8576bbecdc7763b13cbe282295e062;hpb=14771a7395dda16d199b88c71d975d840c7e5b14;p=d2df-sdl.git diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index e4bd070..6f48d28 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -74,6 +74,38 @@ implementation (* --------- Graphics --------- *) + function LoadGL: Boolean; + var ltmp: Integer; + begin + result := true; + {$IFDEF NOGL_INIT} + nogl_Init; + if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then + begin + e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering'); + glRenderToFBO := false; + end; + {$ELSE} + if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then + begin + e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering'); + glRenderToFBO := false; + end; + {$ENDIF} + if SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, @ltmp) = 0 then + begin + e_LogWritefln('stencil buffer size: %s', [ltmp]); + gwin_has_stencil := (ltmp > 0); + end; + end; + + procedure FreeGL; + begin + {$IFDEF NOGL_INIT} + nogl_Quit(); + {$ENDIF} + end; + procedure UpdateSize (w, h: Integer); begin gWinSizeX := w; @@ -85,7 +117,13 @@ implementation // store real window size in gWinSize, downscale resolution now w := round(w / r_pixel_scale); h := round(h / r_pixel_scale); - e_ResizeFramebuffer(w, h); + if not e_ResizeFramebuffer(w, h) then + begin + e_LogWriteln('GL: could not create framebuffer, falling back to --no-fbo'); + glRenderToFBO := False; + w := gWinSizeX; + h := gWinSizeY; + end; end; gScreenWidth := w; gScreenHeight := h; @@ -96,7 +134,7 @@ implementation e_ResizeWindow(w, h); e_InitGL; g_Game_SetupScreenSize; - {$IFNDEF ANDOIRD} + {$IFNDEF ANDROID} (* This will fix menu reset on keyboard showing *) g_Menu_Reset; {$ENDIF} @@ -106,17 +144,17 @@ implementation {$ENDIF} end; - function GetTitle (): PChar; + function GetTitle (): AnsiString; var info: AnsiString; begin info := g_GetBuildHash(false); if info = 'custom build' then info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME; - result := PChar(Format(GameTitle, [info])) + result := Format(GameTitle, [info]); end; function InitWindow (w, h, bpp: Integer; fullScreen, maximized: Boolean): Boolean; - var flags: UInt32; x, y: cint; + var flags: UInt32; x, y: cint; title: AnsiString; begin // note: on window close make: if assigned(oglDeinitCB) then oglDeinitCB; e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]); @@ -150,21 +188,18 @@ implementation x := wx; y := wy end; - window := SDL_CreateWindow(GetTitle(), x, y, w, h, flags); + title := GetTitle(); + window := SDL_CreateWindow(PChar(title), x, y, w, h, flags); if window <> nil then begin context := SDL_GL_CreateContext(window); if context <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Init; - if (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) and glRenderToFBO then - {$ELSE} - if (not Load_GL_ARB_framebuffer_object()) and glRenderToFBO then - {$ENDIF} + if not LoadGL then begin - e_LogWriteln('SDL: no framebuffer object support detected'); - glRenderToFBO := False + e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal); + SDL_GL_DeleteContext(context); context := nil; + exit; end; if (fullscreen = false) and (maximized = false) and (wc = false) then begin @@ -223,8 +258,6 @@ implementation procedure sys_Repaint; begin - if glRenderToFBO then - e_BlitFramebuffer(gWinSizeX, gWinSizeY); SDL_GL_SwapWindow(window) end; @@ -485,9 +518,11 @@ implementation e_KeyUpDown(key, down); g_Console_ProcessBind(key, down); end - else if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then + else begin - KeyPress(key) // key repeat in menus and shit + if g_dbg_input then + e_LogWritefln('Input Debug: keyrep, scancode=%s', [key]); + g_Console_ProcessBindRepeat(key); end end; @@ -564,9 +599,7 @@ implementation e_WriteLog('Releasing SDL2', TMsgType.Notify); if context <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Quit; - {$ENDIF} + FreeGL; SDL_GL_DeleteContext(context); context := nil; end;