Update with current status
[gnash.git] / gui / sdl / sdl_ogl_glue.cpp
blobab93b429477a6139e7b6bcd0518ff54c779cbf29
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "opengl/Renderer_ogl.h"
20 #include "tu_opengl_includes.h"
21 #include "SDL.h"
22 #include "sdl_ogl_glue.h"
24 #include "log.h"
26 #define OVERSIZE 1.0f
28 using namespace std;
30 namespace gnash
33 SdlOglGlue::SdlOglGlue()
35 // GNASH_REPORT_FUNCTION;
38 SdlOglGlue::~SdlOglGlue()
40 // GNASH_REPORT_FUNCTION;
44 bool SdlOglGlue::init(int /*argc*/, char ** /*argv*/ [])
46 // GNASH_REPORT_FUNCTION;
47 return true;
51 Renderer*
52 SdlOglGlue::createRenderHandler(int depth)
54 // GNASH_REPORT_FUNCTION;
56 _bpp = depth;
58 Renderer* renderer = renderer::opengl::create_handler();
60 return renderer;
63 /// Not implemented, Fixme
64 void
65 SdlOglGlue::setInvalidatedRegions(const InvalidatedRanges& /*ranges*/)
69 bool
70 SdlOglGlue::prepDrawingArea(int width, int height, std::uint32_t sdl_flags)
72 if (_bpp == 16) {
73 // 16-bit color, surface creation is likely to succeed.
74 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
75 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
76 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
77 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 15);
78 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
79 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
80 } else {
81 assert(_bpp == 32);
83 // 32-bit color etc, for getting dest alpha,
84 // for MULTIPASS_ANTIALIASING (see
85 // Renderer_ogl.cpp).
86 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
87 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
88 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
89 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
90 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
91 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
92 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
95 SDL_SetVideoMode(width, height, _bpp, sdl_flags | SDL_OPENGL);
97 // Turn on alpha blending.
98 glEnable(GL_BLEND);
99 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
101 // Turn on line smoothing. Antialiased lines can be used to
102 // smooth the outsides of shapes.
103 glEnable(GL_LINE_SMOOTH);
104 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // GL_NICEST, GL_FASTEST, GL_DONT_CARE
105 glMatrixMode(GL_PROJECTION);
108 glOrtho(-OVERSIZE, OVERSIZE, OVERSIZE, -OVERSIZE, -1, 1);
109 glMatrixMode(GL_MODELVIEW);
110 glLoadIdentity();
112 // We don't need lighting effects
113 glDisable(GL_LIGHTING);
114 glPushAttrib (GL_ALL_ATTRIB_BITS);
116 return true;
119 void
120 SdlOglGlue::render()
122 // GNASH_REPORT_FUNCTION;
123 SDL_GL_SwapBuffers();
128 } // namespace gnash