#include "SDL.h"
#include <math.h>
-namespace {
-
-inline void intern_draw(float left, float top, float right, float bottom,
- float uv_left, float uv_top,
- float uv_right, float uv_bottom,
- float angle, float alpha,
- const Color& color,
- const Blend& blend,
- DrawingEffect effect)
-{
- if(effect & HORIZONTAL_FLIP)
- std::swap(uv_left, uv_right);
-
- if(effect & VERTICAL_FLIP)
- std::swap(uv_top, uv_bottom);
-
- glBlendFunc(blend.sfactor, blend.dfactor);
- glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
-
- // unrotated blit
- if (angle == 0.0f) {
- float vertices[] = {
- left, top,
- right, top,
- right, bottom,
- left, bottom,
- };
- glVertexPointer(2, GL_FLOAT, 0, vertices);
-
- float uvs[] = {
- uv_left, uv_top,
- uv_right, uv_top,
- uv_right, uv_bottom,
- uv_left, uv_bottom,
- };
- glTexCoordPointer(2, GL_FLOAT, 0, uvs);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- } else {
- // rotated blit
- float center_x = (left + right) / 2;
- float center_y = (top + bottom) / 2;
-
- float sa = sinf(angle/180.0f*M_PI);
- float ca = cosf(angle/180.0f*M_PI);
-
- left -= center_x;
- right -= center_x;
-
- top -= center_y;
- bottom -= center_y;
-
- float vertices[] = {
- left*ca - top*sa + center_x, left*sa + top*ca + center_y,
- right*ca - top*sa + center_x, right*sa + top*ca + center_y,
- right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
- left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
- };
- glVertexPointer(2, GL_FLOAT, 0, vertices);
-
- float uvs[] = {
- uv_left, uv_top,
- uv_right, uv_top,
- uv_right, uv_bottom,
- uv_left, uv_bottom,
- };
- glTexCoordPointer(2, GL_FLOAT, 0, uvs);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
- }
-
- // FIXME: find a better way to restore the blend mode
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-} // namespace
-
-
-
class GLRenderer : public Renderer
{
private:
- SDL_Window* window;
- SDL_GLContext glcontext;
- Size desktop_size;
- Size screen_size;
- bool fullscreen_active;
-
- GLuint last_texture;
+ SDL_Window* m_window;
+ SDL_GLContext m_glcontext;
+ SDL_Rect m_viewport;
+ Size m_desktop_size;
+ bool m_fullscreen_active;
public:
GLRenderer();
~GLRenderer();
- void draw_surface(const DrawingRequest& request);
- void draw_surface_part(const DrawingRequest& request);
- void draw_gradient(const DrawingRequest& request);
- void draw_filled_rect(const DrawingRequest& request);
- void draw_inverse_ellipse(const DrawingRequest& request);
- void do_take_screenshot();
- void flip();
- void resize(int w, int h);
- void apply_config();
- void apply_video_mode(const Size& size, bool fullscreen);
- Vector to_logical(int physical_x, int physical_y);
- void set_gamma(float gamma);
- SDL_Window* get_window() const { return window; }
+ void start_draw() override;
+ void end_draw() override;
+ void draw_surface(const DrawingRequest& request) override;
+ void draw_surface_part(const DrawingRequest& request) override;
+ void draw_gradient(const DrawingRequest& request) override;
+ void draw_filled_rect(const DrawingRequest& request) override;
+ void draw_inverse_ellipse(const DrawingRequest& request) override;
+ void do_take_screenshot() override;
+ void flip() override;
+ void resize(int w, int h) override;
+ void apply_config() override;
+ Vector to_logical(int physical_x, int physical_y) override;
+ void set_gamma(float gamma) override;
+
+ SDL_Window* get_window() const { return m_window; }
+
+private:
+ void apply_video_mode();
+
+private:
+ GLRenderer(const GLRenderer&) = delete;
+ GLRenderer& operator=(const GLRenderer&) = delete;
};
#endif