X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=blobdiff_plain;f=src%2Fgame%2Fsdl%2Fg_system.pas;h=0df28dc724dc5b391f37dc85b7a8373a12070727;hp=e5f62750ea6b0ca2c993025d4f7ab23125eb1d35;hb=a280ce1ab3f2d28a227e7cf492a12c749e4d5290;hpb=e452d337f0620b50d8d978b534437b2732134d8f diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index e5f6275..0df28dc 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -70,6 +70,28 @@ implementation (* --------- Graphics --------- *) + function LoadGL: Boolean; + begin + result := true; + {$IFDEF NOGL_INIT} + nogl_Init; + if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then + {$ELSE} + if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then + {$ENDIF} + begin + e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering'); + glRenderToFBO := false; + end; + end; + + procedure FreeGL; + begin + {$IFDEF NOGL_INIT} + nogl_Quit(); + {$ENDIF} + end; + procedure UpdateSize (w, h: Integer); begin gWinSizeX := w; @@ -81,7 +103,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,17 +124,17 @@ implementation g_Game_ClearLoading; 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: Boolean): Boolean; - var flags: Uint32; + var flags: Uint32; title: AnsiString; begin e_LogWritefln('InitWindow %s %s %s %s', [w, h, bpp, fullScreen]); result := false; @@ -125,19 +153,13 @@ implementation screen := SDL_SetVideoMode(w, h, bpp, flags); if screen <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Init; - glRenderToFBO := False; // TODO: check for GL_OES_framebuffer_object - {$ELSE} - if glRenderToFBO then - if not Load_GL_ARB_framebuffer_object() then - if not Load_GL_EXT_framebuffer_object() then - begin - e_LogWriteln('SDL: no framebuffer support detected'); - glRenderToFBO := False - end; - {$ENDIF} - SDL_WM_SetCaption(GetTitle(), nil); + if not LoadGL then + begin + e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal); + exit; + end; + title := GetTitle(); + SDL_WM_SetCaption(PChar(title), nil); gFullScreen := fullscreen; gRC_FullScreen := fullscreen; UpdateSize(w, h); @@ -152,8 +174,6 @@ implementation procedure sys_Repaint; begin - if glRenderToFBO then - e_BlitFramebuffer(gWinSizeX, gWinSizeY); SDL_GL_SwapBuffers end; @@ -165,7 +185,7 @@ implementation function sys_GetDisplayModes (bpp: Integer): SSArray; var m: PPSDL_Rect; f: TSDL_PixelFormat; i, count: Integer; begin - SetLength(result, 0); + result := nil; FillChar(f, sizeof(f), 0); f.palette := nil; f.BitsPerPixel := bpp; @@ -430,9 +450,9 @@ 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 + g_Console_ProcessBindRepeat(key) end; if down and IsValid1251(ev.keysym.unicode) and IsPrintable1251(ch) then CharPress(ch) @@ -499,9 +519,7 @@ implementation RemoveJoystick(i); if screen <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Quit; - {$ENDIF} + FreeGL; SDL_FreeSurface(screen) end; SDL_Quit