[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] [pingus] 2 new revisions pushed by address@hidden on 2014-0
From: |
pingus |
Subject: |
[Pingus-CVS] [pingus] 2 new revisions pushed by address@hidden on 2014-07-27 16:32 GMT |
Date: |
Sun, 27 Jul 2014 16:32:41 +0000 |
feature/sdl2 moved from cb797fe72c39 to b3384180cca3
2 new revisions:
Revision: 82ab81356d6a
Author: Ingo Ruhnke <address@hidden>
Date: Sun Jul 27 15:23:11 2014 UTC
Log: Removed some unused code
http://code.google.com/p/pingus/source/detail?r=82ab81356d6a
Revision: b3384180cca3
Author: Ingo Ruhnke <address@hidden>
Date: Sun Jul 27 16:32:00 2014 UTC
Log: Fixed screenshoting for SDLFramebuffer, removed HAVE_OPENGL define
http://code.google.com/p/pingus/source/detail?r=b3384180cca3
==============================================================================
Revision: 82ab81356d6a
Author: Ingo Ruhnke <address@hidden>
Date: Sun Jul 27 15:23:11 2014 UTC
Log: Removed some unused code
http://code.google.com/p/pingus/source/detail?r=82ab81356d6a
Modified:
/src/engine/display/sdl_framebuffer.cpp
/src/engine/display/sdl_framebuffer.hpp
=======================================
--- /src/engine/display/sdl_framebuffer.cpp Sun Jul 27 04:14:52 2014 UTC
+++ /src/engine/display/sdl_framebuffer.cpp Sun Jul 27 15:23:11 2014 UTC
@@ -23,99 +23,6 @@
#include "util/log.hpp"
namespace {
-
-typedef void (*draw_pixel_func)(SDL_Surface* screen, int, int, const
Color&);
-
-inline void draw_pixel16(SDL_Surface* screen, int x, int y, const Color& c)
-{
- Uint32 color = SDL_MapRGBA(screen->format, c.r, c.g, c.b, c.a);
-
- if (c.a < 255) {
- Uint16 *p;
- unsigned long dp;
- uint8_t alpha;
-
- // Loses precision for speed
- alpha = static_cast<uint8_t>((255 - c.a) >> 3);
-
- p = &(static_cast<Uint16 *>(screen->pixels))[x + y * screen->w];
- color = (((color << 16) | color) & 0x07E0F81F);
- dp = *p;
- dp = ((dp << 16) | dp) & 0x07E0F81F;
- dp = ((((dp - color) * alpha) >> 5) + color) & 0x07E0F81F;
- *p = static_cast<Uint16>((dp >> 16) | dp);
- } else {
- static_cast<Uint16*>(screen->pixels)[x + y * screen->w] =
static_cast<Uint16>(color);
- }
-}
-
-inline void draw_pixel32(SDL_Surface* screen, int x, int y, const Color& c)
-{
- Uint32 color = SDL_MapRGBA(screen->format, c.r, c.g, c.b, c.a);
-
- if (c.a < 255) {
- Uint32 *p;
- unsigned long sp2;
- unsigned long dp1;
- unsigned long dp2;
- unsigned char alpha;
-
- alpha = static_cast<unsigned char>(255 - c.a);
-
- p = &(static_cast<Uint32*>(screen->pixels))[x + y * screen->w];
-
- sp2 = (color & 0xFF00FF00) >> 8;
- color &= 0x00FF00FF;
-
- dp1 = *p;
- dp2 = (dp1 & 0xFF00FF00) >> 8;
- dp1 &= 0x00FF00FF;
-
- dp1 = ((((dp1 - color) * alpha) >> 8) + color) & 0x00FF00FF;
- dp2 = ((((dp2 - sp2) * alpha) >> 8) + sp2) & 0x00FF00FF;
- *p = static_cast<Uint32>(dp1 | (dp2 << 8));
- } else {
- (static_cast<Uint32*>(screen->pixels))[x + y * screen->w] = color;
- }
-}
-
-draw_pixel_func get_draw_pixel(SDL_Surface* screen)
-{
- switch (screen->format->BitsPerPixel)
- {
- case 16:
- return draw_pixel16;
- case 32:
- return draw_pixel32;
- }
- return NULL;
-}
-
-void draw_vline(SDL_Surface* screen, int x, int y, int length, const
Color& color)
-{
- draw_pixel_func draw_pixel = get_draw_pixel(screen);
- if (!draw_pixel)
- return;
-
- SDL_LockSurface(screen);
- for (int i = 0; i < length; ++i) {
- draw_pixel(screen, x, y + i, color);
- }
- SDL_UnlockSurface(screen);
-}
-
-void draw_hline(SDL_Surface* screen, int x, int y, int length, const
Color& color)
-{
- draw_pixel_func draw_pixel = get_draw_pixel(screen);
- if (!draw_pixel)
- return;
-
- SDL_LockSurface(screen);
- for (int i = 0; i < length; ++i) {
- draw_pixel(screen, x + i, y, color);
- }
- SDL_UnlockSurface(screen);
-}
SDL_Rect Intersection(SDL_Rect* r1, SDL_Rect* r2)
{
@@ -128,14 +35,6 @@
rect.h = static_cast<Uint16>(Math::max(static_cast<int>(endy - rect.y),
0));
return rect;
}
-
-void clip(int& i, int min, int max)
-{
- if (i < min)
- i = min;
- else if (i > max)
- i = max;
-}
} // namespace
@@ -143,16 +42,12 @@
SDLFramebuffer::SDLFramebuffer() :
m_window(nullptr),
m_renderer(nullptr),
- m_screen(nullptr),
- m_texture(nullptr),
cliprect_stack()
{
}
SDLFramebuffer::~SDLFramebuffer()
{
- SDL_DestroyTexture(m_texture);
- SDL_FreeSurface(m_screen);
SDL_DestroyRenderer(m_renderer);
SDL_DestroyWindow(m_window);
}
@@ -314,15 +209,6 @@
SDL_SetWindowIcon(m_window,
IMG_Load(Pathname("images/icons/pingus.png",
Pathname::DATA_PATH).get_sys_path().c_str()));
m_renderer = SDL_CreateRenderer(m_window, -1,
SDL_RENDERER_ACCELERATED);
- m_screen = SDL_CreateRGBSurface(0, size.width, size.height, 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000);
- m_texture = SDL_CreateTexture(m_renderer,
- SDL_PIXELFORMAT_ARGB8888,
- SDL_TEXTUREACCESS_STREAMING,
- size.width, size.height);
}
}
=======================================
--- /src/engine/display/sdl_framebuffer.hpp Sat Jul 26 19:58:06 2014 UTC
+++ /src/engine/display/sdl_framebuffer.hpp Sun Jul 27 15:23:11 2014 UTC
@@ -24,8 +24,6 @@
private:
SDL_Window* m_window;
SDL_Renderer* m_renderer;
- SDL_Surface* m_screen;
- SDL_Texture* m_texture;
std::vector<SDL_Rect> cliprect_stack;
public:
==============================================================================
Revision: b3384180cca3
Author: Ingo Ruhnke <address@hidden>
Date: Sun Jul 27 16:32:00 2014 UTC
Log: Fixed screenshoting for SDLFramebuffer, removed HAVE_OPENGL define
http://code.google.com/p/pingus/source/detail?r=b3384180cca3
Modified:
/SConscript
/src/engine/display/delta/delta_framebuffer.cpp
/src/engine/display/delta/delta_framebuffer.hpp
/src/engine/display/display.cpp
/src/engine/display/framebuffer.hpp
/src/engine/display/null_framebuffer.hpp
/src/engine/display/opengl/opengl_framebuffer.cpp
/src/engine/display/opengl/opengl_framebuffer.hpp
/src/engine/display/screenshot.cpp
/src/engine/display/screenshot.hpp
/src/engine/display/sdl_framebuffer.cpp
/src/engine/display/sdl_framebuffer.hpp
/src/pingus/screens/option_menu.cpp
=======================================
--- /SConscript Sat Jul 26 18:07:52 2014 UTC
+++ /SConscript Sun Jul 27 16:32:00 2014 UTC
@@ -127,8 +127,7 @@
else:
self.reports += " * OpenGL support: enabled\n"
self.conf.env.Append(optional_sources =
['src/engine/display/opengl/opengl_framebuffer_surface_impl.cpp',
- 'src/engine/display/opengl/opengl_framebuffer.cpp'
],
- CPPDEFINES = [('HAVE_OPENGL', 1)])
+ 'src/engine/display/opengl/opengl_framebuffer.cpp'
])
if sys.platform == "darwin":
self.conf.env.Append(LINKFLAGS =
[ '-framework', 'OpenGL', '-framework', 'Cocoa' ])
else:
=======================================
--- /src/engine/display/delta/delta_framebuffer.cpp Fri Oct 14 02:03:23
2011 UTC
+++ /src/engine/display/delta/delta_framebuffer.cpp Sun Jul 27 16:32:00
2014 UTC
@@ -40,6 +40,12 @@
{
return framebuffer->create_surface(surface);
}
+
+Surface
+DeltaFramebuffer::make_screenshot() const
+{
+ return framebuffer->make_screenshot();
+}
void
DeltaFramebuffer::set_video_mode(const Size& size, bool fullscreen, bool
resizable)
=======================================
--- /src/engine/display/delta/delta_framebuffer.hpp Fri Oct 14 02:03:23
2011 UTC
+++ /src/engine/display/delta/delta_framebuffer.hpp Sun Jul 27 16:32:00
2014 UTC
@@ -34,6 +34,8 @@
FramebufferSurface create_surface(const Surface& surface);
+ Surface make_screenshot() const override;
+
void set_video_mode(const Size& size, bool fullscreen, bool resizable);
bool is_fullscreen() const;
bool is_resizable() const;
=======================================
--- /src/engine/display/display.cpp Sat Jul 26 19:58:06 2014 UTC
+++ /src/engine/display/display.cpp Sun Jul 27 16:32:00 2014 UTC
@@ -22,9 +22,7 @@
#include "engine/display/sdl_framebuffer.hpp"
#include "engine/screen/screen_manager.hpp"
#include "pingus/globals.hpp"
-#ifdef HAVE_OPENGL
-# include "engine/display/opengl/opengl_framebuffer.hpp"
-#endif
+#include "engine/display/opengl/opengl_framebuffer.hpp"
#include "engine/display/delta/delta_framebuffer.hpp"
#include "engine/display/null_framebuffer.hpp"
#include "util/log.hpp"
@@ -95,12 +93,8 @@
switch (framebuffer_type)
{
case OPENGL_FRAMEBUFFER:
-#ifdef HAVE_OPENGL
s_framebuffer = std::unique_ptr<Framebuffer>(new
OpenGLFramebuffer());
s_framebuffer->set_video_mode(size, fullscreen, resizable);
-#else
- raise_exception(std::runtime_error, "OpenGL support was not compiled
in");
-#endif
break;
case NULL_FRAMEBUFFER:
=======================================
--- /src/engine/display/framebuffer.hpp Fri Oct 14 02:03:23 2011 UTC
+++ /src/engine/display/framebuffer.hpp Sun Jul 27 16:32:00 2014 UTC
@@ -36,6 +36,8 @@
virtual FramebufferSurface create_surface(const Surface& surface) =0;
+ virtual Surface make_screenshot() const =0;
+
virtual void set_video_mode(const Size& size, bool fullscreen, bool
resizable) =0;
virtual bool is_fullscreen() const =0;
virtual bool is_resizable() const =0;
=======================================
--- /src/engine/display/null_framebuffer.hpp Fri Oct 14 02:03:23 2011 UTC
+++ /src/engine/display/null_framebuffer.hpp Sun Jul 27 16:32:00 2014 UTC
@@ -32,6 +32,8 @@
~NullFramebuffer();
FramebufferSurface create_surface(const Surface& surface);
+
+ Surface make_screenshot() const override { return Surface(); }
void set_video_mode(const Size& size, bool fullscreen, bool resizable);
bool is_fullscreen() const;
=======================================
--- /src/engine/display/opengl/opengl_framebuffer.cpp Sun Jul 27 00:18:02
2014 UTC
+++ /src/engine/display/opengl/opengl_framebuffer.cpp Sun Jul 27 16:32:00
2014 UTC
@@ -39,6 +39,22 @@
{
return FramebufferSurface(new
OpenGLFramebufferSurfaceImpl(surface.get_surface()));
}
+
+Surface
+OpenGLFramebuffer::make_screenshot() const
+{
+ Size size = get_size();
+
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ std::unique_ptr<uint8_t[]> buffer(new uint8_t[size.width * size.height *
4]);
+ glReadPixels(0, 0, size.width, size.height, GL_RGBA, GL_UNSIGNED_BYTE,
buffer.get());
+
+ Surface screenshot(size.width, size.height);
+#ifdef OLD_SDL1
+ // insert code
+#endif
+ return screenshot;
+}
void
OpenGLFramebuffer::set_video_mode(const Size& size, bool fullscreen, bool
resizable)
=======================================
--- /src/engine/display/opengl/opengl_framebuffer.hpp Sat Jul 26 19:58:06
2014 UTC
+++ /src/engine/display/opengl/opengl_framebuffer.hpp Sun Jul 27 16:32:00
2014 UTC
@@ -5,12 +5,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
-//
+//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -31,11 +31,13 @@
FramebufferSurface create_surface(const Surface& surface);
+ Surface make_screenshot() const override;
+
void set_video_mode(const Size& size, bool fullscreen, bool resizable);
bool is_fullscreen() const;
bool is_resizable() const;
void flip();
-
+
void push_cliprect(const Rect&);
void pop_cliprect();
=======================================
--- /src/engine/display/screenshot.cpp Sat Jul 26 19:58:06 2014 UTC
+++ /src/engine/display/screenshot.cpp Sun Jul 27 16:32:00 2014 UTC
@@ -20,10 +20,11 @@
#include <assert.h>
#include <png.h>
-#ifdef HAVE_OPENGL
#include <SDL_opengl.h>
-#endif
+#include "engine/display/display.hpp"
+#include "engine/display/framebuffer.hpp"
+#include "engine/display/surface.hpp"
#include "pingus/gettext.h"
#include "util/log.hpp"
#include "util/system.hpp"
@@ -33,116 +34,23 @@
std::string
Screenshot::make_screenshot()
{
- std::string filename = get_filename();
-
- log_info("Screenshot: Saving screenshot to: %1%", filename);
-#ifdef OLD_SDL1
- save(SDL_GetVideoSurface(), filename);
-#endif
- log_info("Screenshot: Screenshot is done.");
-
- return filename;
-}
-
-void
-Screenshot::save(SDL_Surface* surface, const std::string& filename)
-{
- std::unique_ptr<uint8_t[]> buffer(new uint8_t[surface->w * surface->h *
3]);
-
-#ifdef HAVE_OPENGL
- if(surface->flags & SDL_WINDOW_OPENGL)
+ Surface screen = Display::get_framebuffer()->make_screenshot();
+ if (screen)
{
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE,
buffer.get());
- save_png(filename, buffer.get(), surface->w, surface->h, true);
+ std::string filename = get_filename();
+ log_info("Screenshot: Saving screenshot to: %1%", filename);
+ save_png(filename, screen.get_data(), screen.get_width(),
screen.get_height(), screen.get_pitch());
+ log_info("Screenshot: Screenshot is done.");
+ return filename;
}
else
-#endif
{
- SDL_LockSurface(surface);
-
- switch(surface->format->BitsPerPixel)
- {
- case 16: // 16bit
- {
- uint8_t* pixels = static_cast<uint8_t*>(surface->pixels);
- for (int y = 0; y < surface->h; ++y)
- for (int x = 0; x < surface->w; ++x)
- {
- int i = (y * surface->w + x);
- SDL_GetRGB(*(reinterpret_cast<uint16_t*>(pixels + y *
surface->pitch + x*2)),
- surface->format,
- buffer.get() + i*3 + 0, buffer.get() + i*3 + 1,
buffer.get() + i*3 + 2);
- }
- break;
- }
-
- case 24: // 24bit
- {
- uint8_t* pixels = static_cast<uint8_t*>(surface->pixels);
- for (int y = 0; y < surface->h; ++y)
- for (int x = 0; x < surface->w; ++x)
- {
- int i = (y * surface->w + x);
- SDL_GetRGB(*(reinterpret_cast<uint32_t*>(pixels + y *
surface->pitch + x*3)),
- surface->format,
- buffer.get() + i*3 + 0, buffer.get() + i*3 + 1,
buffer.get() + i*3 + 2);
- }
- break;
- }
-
- case 32: // 32bit
- {
- uint8_t* pixels = static_cast<uint8_t*>(surface->pixels);
- for (int y = 0; y < surface->h; ++y)
- for (int x = 0; x < surface->w; ++x)
- {
- int i = (y * surface->w + x);
- SDL_GetRGB(*(reinterpret_cast<uint32_t*>(pixels + y *
surface->pitch + x*4)),
- surface->format,
- buffer.get() + i*3 + 0, buffer.get() + i*3 + 1,
buffer.get() + i*3 + 2);
- }
- break;
- }
- default:
- log_info("BitsPerPixel: %1%", int(surface->format->BitsPerPixel));
- assert(!"Unknown color format");
- break;
- }
-
- save_png(filename, buffer.get(), surface->w, surface->h);
-
- SDL_UnlockSurface(surface);
+ return std::string();
}
}
void
-Screenshot::save_ppm(const std::string& filename, uint8_t* buffer, int
width, int height)
-{
- FILE* out = fopen(filename.c_str(), "wb");
-
- if (!out)
- {
- perror(filename.c_str());
- log_info("Screenshot: Couldn't write file: %1%", filename);
- return;
- }
-
- fprintf(out,
- "P6\n"
- "# CREATOR: Pingus %s\n"
- "%d %d\n"
- "255\n",
- VERSION,
- width,
- height);
-
- fwrite(buffer, sizeof(unsigned char), width * height * 3, out);
- fclose(out);
-}
-
-void
-Screenshot::save_png(const std::string& filename, uint8_t* buffer, int
width, int height, bool flipvertically)
+Screenshot::save_png(const std::string& filename, uint8_t* buffer, int
width, int height, int pitch)
{
FILE* fp;
png_structp png_ptr;
@@ -187,19 +95,19 @@
PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
-
- if (flipvertically){
- for (int i = height-1; i >= 0; --i)
+ {
+ std::unique_ptr<uint8_t[]> row{ new uint8_t[width * 3] };
+ for (int y = 0; y < height; ++y)
{
- png_write_row(png_ptr, buffer + i * width * 3);
- }
- } else {
- for (int i = 0; i < height; ++i)
- {
- png_write_row(png_ptr, buffer + i * width * 3);
+ for(int x = 0; x < width; ++x)
+ {
+ row[3*x + 0] = (buffer + y * pitch)[4*x + 3];
+ row[3*x + 1] = (buffer + y * pitch)[4*x + 2];
+ row[3*x + 2] = (buffer + y * pitch)[4*x + 1];
+ }
+ png_write_row(png_ptr, row.get());
}
}
-
png_write_end(png_ptr, info_ptr);
// clean up after the write, and free any memory allocated
=======================================
--- /src/engine/display/screenshot.hpp Sat Sep 3 19:54:44 2011 UTC
+++ /src/engine/display/screenshot.hpp Sun Jul 27 16:32:00 2014 UTC
@@ -30,11 +30,9 @@
public:
static std::string make_screenshot();
- static void save(SDL_Surface* surface, const std::string& filename);
- /** buffer must be RGB and width*height*3 large */
- static void save_ppm(const std::string& filename, uint8_t* buffer, int
width, int height);
- static void save_png(const std::string& filename, uint8_t* buffer, int
width, int height, bool flipvertically = false);
+ /** buffer must be RGBX and width*height*4 large */
+ static void save_png(const std::string& filename, uint8_t* buffer, int
width, int height, int pitch);
private:
Screenshot();
=======================================
--- /src/engine/display/sdl_framebuffer.cpp Sun Jul 27 15:23:11 2014 UTC
+++ /src/engine/display/sdl_framebuffer.cpp Sun Jul 27 16:32:00 2014 UTC
@@ -5,12 +5,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
-//
+//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -57,6 +57,23 @@
{
return FramebufferSurface(new SDLFramebufferSurfaceImpl(m_renderer,
surface.get_surface()));
}
+
+Surface
+SDLFramebuffer::make_screenshot() const
+{
+ Size size = get_size();
+ Surface screenshot(size.width, size.height);
+ int ret = SDL_RenderReadPixels(m_renderer, nullptr,
+ SDL_PIXELFORMAT_RGBX8888,
+ screenshot.get_data(),
+ screenshot.get_pitch());
+ if (ret != 0)
+ {
+ log_error("%1%", SDL_GetError());
+ }
+
+ return screenshot;
+}
void
SDLFramebuffer::draw_surface(const FramebufferSurface& surface, const
Vector2i& pos)
@@ -86,7 +103,7 @@
dstrect.x = static_cast<Sint16>(pos.x);
dstrect.y = static_cast<Sint16>(pos.y);
dstrect.w = srcrect.get_width();
- dstrect.h = srcrect.get_height();
+ dstrect.h = srcrect.get_height();
SDL_Rect sdlsrcrect;
sdlsrcrect.x = static_cast<Sint16>(srcrect.left);
@@ -237,7 +254,7 @@
{
sdl_rect = Intersection(&cliprect_stack.back(), &sdl_rect);
}
-
+
cliprect_stack.push_back(sdl_rect);
SDL_RenderSetClipRect(m_renderer, &cliprect_stack.back());
}
=======================================
--- /src/engine/display/sdl_framebuffer.hpp Sun Jul 27 15:23:11 2014 UTC
+++ /src/engine/display/sdl_framebuffer.hpp Sun Jul 27 16:32:00 2014 UTC
@@ -32,6 +32,8 @@
FramebufferSurface create_surface(const Surface& surface);
+ Surface make_screenshot() const override;
+
void set_video_mode(const Size& size, bool fullscreen, bool resizable);
bool is_fullscreen() const;
bool is_resizable() const;
=======================================
--- /src/pingus/screens/option_menu.cpp Sun Jul 27 03:58:39 2014 UTC
+++ /src/pingus/screens/option_menu.cpp Sun Jul 27 16:32:00 2014 UTC
@@ -130,17 +130,13 @@
ChoiceBox* renderer_box = new ChoiceBox(Rect());
renderer_box->add_choice("sdl");
renderer_box->add_choice("delta");
-#ifdef HAVE_OPENGL
renderer_box->add_choice("opengl");
-#endif
switch(config_manager.get_renderer())
{
case SDL_FRAMEBUFFER: renderer_box->set_current_choice(0); break;
case DELTA_FRAMEBUFFER: renderer_box->set_current_choice(1); break;
-#ifdef HAVE_OPENGL
case OPENGL_FRAMEBUFFER: renderer_box->set_current_choice(2); break;
-#endif
default: assert(!"unknown renderer type");
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] [pingus] 2 new revisions pushed by address@hidden on 2014-07-27 16:32 GMT,
pingus <=