diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a27a5ebd2..430fd6cb6 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -84,6 +84,8 @@ #include "hwsym_sdl.h" #include "ogl_sdl.h" #endif +#include "i_video_hwr2.h" +#include "../hwr2/renderer.h" // maximum number of windowed modes (see windowedModes[][]) #define MAXWINMODES (18) @@ -147,6 +149,7 @@ SDL_Window *window; SDL_Renderer *renderer; static SDL_Texture *texture; static SDL_bool havefocus = SDL_TRUE; +static hwr2renderer_h sdl_current_hwr2renderer; static const char *fallback_resolution_name = "Fallback"; // windowed video modes from which to choose from. @@ -233,6 +236,14 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen, SDL_bool OglSdlSurface(vid.width, vid.height); } #endif + if (rendermode == render_hwr2) + { + if (sdl_current_hwr2renderer == NULL) + { + I_SDL_DestroyGlesHwr2Renderer(sdl_current_hwr2renderer); + } + sdl_current_hwr2renderer = I_SDL_CreateGlesHwr2Renderer(window); + } if (rendermode == render_soft) { @@ -1168,6 +1179,10 @@ void I_UpdateNoBlit(void) SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } + else if (rendermode == render_hwr2) + { + I_SDL_Hwr2Present(sdl_current_hwr2renderer); + } } exposevideo = SDL_FALSE; } @@ -1257,6 +1272,10 @@ void I_FinishUpdate(void) OglSdlFinishUpdate(cv_vidwait.value); } #endif + else if (rendermode == render_hwr2) + { + I_SDL_Hwr2Present(sdl_current_hwr2renderer); + } exposevideo = SDL_FALSE; } @@ -1956,3 +1975,8 @@ void I_GetCursorPosition(INT32 *x, INT32 *y) { SDL_GetMouseState(x, y); } + +hwr2renderer_h I_GetHwr2Renderer() +{ + return sdl_current_hwr2renderer; +} diff --git a/src/sdl/i_video_hwr2.cpp b/src/sdl/i_video_hwr2.cpp index c98fac1d0..2f59bcac7 100644 --- a/src/sdl/i_video_hwr2.cpp +++ b/src/sdl/i_video_hwr2.cpp @@ -1,3 +1,7 @@ +#include "i_video_hwr2.h" + +#include "SDL.h" + extern "C" { #include "../i_video.h" } @@ -6,12 +10,29 @@ extern "C" { class Sdl2Gles2Renderer : public Gles2Renderer { +private: + SDL_Window* window_ = NULL; public: + Sdl2Gles2Renderer(SDL_Window* window) : window_(window) {} + virtual void Present() - {} + { + SDL_GL_SwapWindow(window_); + } }; -hwr2renderer_h I_GetHwr2Renderer() +hwr2renderer_h I_SDL_CreateGlesHwr2Renderer(SDL_Window* window) { - return reinterpret_cast(new Sdl2Gles2Renderer()); + return reinterpret_cast(new Sdl2Gles2Renderer(window)); +} + +void I_SDL_DestroyGlesHwr2Renderer(hwr2renderer_h renderer) +{ + delete reinterpret_cast(renderer); +} + +void I_SDL_Hwr2Present(hwr2renderer_h renderer) +{ + Sdl2Gles2Renderer* hwr2 = reinterpret_cast(renderer); + hwr2->Present(); } diff --git a/src/sdl/i_video_hwr2.h b/src/sdl/i_video_hwr2.h new file mode 100644 index 000000000..18e28f6a0 --- /dev/null +++ b/src/sdl/i_video_hwr2.h @@ -0,0 +1,27 @@ +#ifndef __SDL_I_VIDEO_HWR2_H__ +#define __SDL_I_VIDEO_HWR2_H__ + +#include "SDL.h" + +#ifdef __cplusplus +extern "C" { +#endif +#include "../i_video.h" +#ifdef __cplusplus +} +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +hwr2renderer_h I_SDL_CreateGlesHwr2Renderer(SDL_Window* window); +void I_SDL_DestroyGlesHwr2Renderer(hwr2renderer_h renderer); +void I_SDL_Hwr2Present(hwr2renderer_h renderer); + +#ifdef __cplusplus +} +#endif + +#endif // __SDL_I_VIDEO_HWR2_H__