+Surface::Surfaces Surface::surfaces;
+
+SurfaceData::SurfaceData(SDL_Surface* temp, int use_alpha_)
+ : type(SURFACE), surface(0), use_alpha(use_alpha_)
+{
+ // Copy the given surface and make sure that it is not stored in
+ // video memory
+ surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE),
+ temp->w, temp->h,
+ temp->format->BitsPerPixel,
+ temp->format->Rmask,
+ temp->format->Gmask,
+ temp->format->Bmask,
+ temp->format->Amask);
+ if(!surface)
+ st_abort("No memory left.", "");
+ SDL_SetAlpha(temp,0,0);
+ SDL_BlitSurface(temp, NULL, surface, NULL);
+}
+
+SurfaceData::SurfaceData(const std::string& file_, int use_alpha_)
+ : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_)
+{}
+
+SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_)
+ : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
+ x(x_), y(y_), w(w_), h(h_)
+{}
+
+SurfaceData::~SurfaceData()
+{
+ SDL_FreeSurface(surface);
+}
+
+SurfaceImpl*
+SurfaceData::create()
+{
+#ifndef NOOPENGL
+ if (use_gl)
+ return create_SurfaceOpenGL();
+ else
+ return create_SurfaceSDL();
+#else
+ return create_SurfaceSDL();
+#endif
+}
+
+SurfaceSDL*
+SurfaceData::create_SurfaceSDL()
+{
+ switch(type)
+ {
+ case LOAD:
+ return new SurfaceSDL(file, use_alpha);
+ case LOAD_PART:
+ return new SurfaceSDL(file, x, y, w, h, use_alpha);
+ case SURFACE:
+ return new SurfaceSDL(surface, use_alpha);
+ }
+ assert(0);
+}
+
+SurfaceOpenGL*
+SurfaceData::create_SurfaceOpenGL()
+{
+#ifndef NOOPENGL
+ switch(type)
+ {
+ case LOAD:
+ return new SurfaceOpenGL(file, use_alpha);
+ case LOAD_PART:
+ return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
+ case SURFACE:
+ return new SurfaceOpenGL(surface, use_alpha);
+ }
+#endif
+ assert(0);
+}
+
+#ifndef NOOPENGL