#include "video/sdl/sdl_painter.hpp"
SDLLightmap::SDLLightmap() :
- renderer(static_cast<SDLRenderer*>(Renderer::instance())->get_sdl_renderer()),
- texture(),
- width(),
- height(),
- LIGHTMAP_DIV()
+ m_renderer(static_cast<SDLRenderer*>(Renderer::instance())->get_sdl_renderer()),
+ m_texture(),
+ m_width(),
+ m_height(),
+ m_LIGHTMAP_DIV()
{
- LIGHTMAP_DIV = 8;
-
- width = SCREEN_WIDTH;
- height = SCREEN_HEIGHT;
-
- SDL_Renderer* renderer = static_cast<SDLRenderer*>(Renderer::instance())->get_sdl_renderer();
- texture = SDL_CreateTexture(renderer,
- SDL_PIXELFORMAT_RGB888,
- SDL_TEXTUREACCESS_TARGET,
- width / LIGHTMAP_DIV,
- height / LIGHTMAP_DIV);
- if (!texture)
+ m_LIGHTMAP_DIV = 8;
+
+ m_width = SCREEN_WIDTH;
+ m_height = SCREEN_HEIGHT;
+
+ m_texture = SDL_CreateTexture(m_renderer,
+ SDL_PIXELFORMAT_RGB888,
+ SDL_TEXTUREACCESS_TARGET,
+ m_width / m_LIGHTMAP_DIV,
+ m_height / m_LIGHTMAP_DIV);
+ if (!m_texture)
{
std::stringstream msg;
msg << "Couldn't create lightmap texture: " << SDL_GetError();
SDLLightmap::~SDLLightmap()
{
- SDL_DestroyTexture(texture);
+ SDL_DestroyTexture(m_texture);
}
void
SDLLightmap::start_draw(const Color &ambient_color)
{
- SDL_SetRenderTarget(renderer, texture);
+ SDL_SetRenderTarget(m_renderer, m_texture);
Uint8 r = static_cast<Uint8>(ambient_color.red * 255);
Uint8 g = static_cast<Uint8>(ambient_color.green * 255);
Uint8 b = static_cast<Uint8>(ambient_color.blue * 255);
- SDL_SetRenderDrawColor(renderer, r, g, b, 255);
- SDL_RenderClear(renderer);
- SDL_RenderSetScale(renderer, 1.0f / LIGHTMAP_DIV, 1.0f / LIGHTMAP_DIV);
+ SDL_SetRenderDrawColor(m_renderer, r, g, b, 255);
+ SDL_RenderClear(m_renderer);
+ SDL_RenderSetScale(m_renderer, 1.0f / m_LIGHTMAP_DIV, 1.0f / m_LIGHTMAP_DIV);
}
void
SDLLightmap::end_draw()
{
- SDL_RenderSetScale(renderer, 1.0f, 1.0f);
- SDL_SetRenderTarget(renderer, NULL);
+ SDL_RenderSetScale(m_renderer, 1.0f, 1.0f);
+ SDL_SetRenderTarget(m_renderer, NULL);
}
void
SDLLightmap::do_draw()
{
- SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
+ SDL_SetTextureBlendMode(m_texture, SDL_BLENDMODE_MOD);
SDL_Rect dst_rect;
dst_rect.x = 0;
dst_rect.y = 0;
- dst_rect.w = width;
- dst_rect.h = height;
+ dst_rect.w = m_width;
+ dst_rect.h = m_height;
- SDL_RenderCopy(renderer, texture, NULL, &dst_rect);
+ SDL_RenderCopy(m_renderer, m_texture, NULL, &dst_rect);
}
void
SDLLightmap::draw_surface(const DrawingRequest& request)
{
- SDLPainter::draw_surface(renderer, request);
+ SDLPainter::draw_surface(m_renderer, request);
}
void
SDLLightmap::draw_surface_part(const DrawingRequest& request)
{
- SDLPainter::draw_surface_part(renderer, request);
+ SDLPainter::draw_surface_part(m_renderer, request);
}
void
SDLLightmap::draw_gradient(const DrawingRequest& request)
{
- SDLPainter::draw_gradient(renderer, request);
+ SDLPainter::draw_gradient(m_renderer, request);
}
void
SDLLightmap::draw_filled_rect(const DrawingRequest& request)
{
- SDLPainter::draw_filled_rect(renderer, request);
+ SDLPainter::draw_filled_rect(m_renderer, request);
}
void
SDLLightmap::get_light(const DrawingRequest& request) const
{
const GetLightRequest* getlightrequest
- = (GetLightRequest*) request.request_data;
+ = static_cast<GetLightRequest*>(request.request_data);
SDL_Rect rect;
- rect.x = static_cast<int>(request.pos.x * width / SCREEN_WIDTH);
- rect.y = static_cast<int>(request.pos.y * height / SCREEN_HEIGHT);
+ rect.x = static_cast<int>(request.pos.x * m_width / SCREEN_WIDTH);
+ rect.y = static_cast<int>(request.pos.y * m_height / SCREEN_HEIGHT);
rect.w = 1;
rect.h = 1;
- SDL_SetRenderTarget(renderer, texture);
+ SDL_SetRenderTarget(m_renderer, m_texture);
Uint8 pixel[4];
- int ret = SDL_RenderReadPixels(renderer, &rect,
+ int ret = SDL_RenderReadPixels(m_renderer, &rect,
SDL_PIXELFORMAT_RGB888,
pixel,
1);
{
log_warning << "failed to read pixels: " << SDL_GetError() << std::endl;
}
- SDL_SetRenderTarget(renderer, 0);
+ SDL_SetRenderTarget(m_renderer, 0);
*(getlightrequest->color_ptr) = Color(pixel[2] / 255.0f,
pixel[1] / 255.0f,
#include "video/util.hpp"
SDLRenderer::SDLRenderer() :
- window(),
- renderer(),
- viewport(),
- desktop_size(0, 0),
+ m_window(),
+ m_renderer(),
+ m_viewport(),
+ m_desktop_size(0, 0),
m_scale(1.0f, 1.0f)
{
Renderer::instance_ = this;
}
else
{
- desktop_size = Size(mode.w, mode.h);
+ m_desktop_size = Size(mode.w, mode.h);
}
log_info << "creating SDLRenderer" << std::endl;
SCREEN_WIDTH = width;
SCREEN_HEIGHT = height;
- viewport.x = 0;
- viewport.y = 0;
- viewport.w = width;
- viewport.h = height;
+ m_viewport.x = 0;
+ m_viewport.y = 0;
+ m_viewport.w = width;
+ m_viewport.h = height;
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
int ret = SDL_CreateWindowAndRenderer(width, height, flags,
- &window, &renderer);
+ &m_window, &m_renderer);
if(ret != 0) {
std::stringstream msg;
}
SDL_RendererInfo info;
- if (SDL_GetRendererInfo(renderer, &info) != 0)
+ if (SDL_GetRendererInfo(m_renderer, &info) != 0)
{
log_warning << "Couldn't get RendererInfo: " << SDL_GetError() << std::endl;
}
SDLRenderer::~SDLRenderer()
{
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
+ SDL_DestroyRenderer(m_renderer);
+ SDL_DestroyWindow(m_window);
}
void
SDLRenderer::start_draw()
{
- SDL_RenderSetScale(renderer, m_scale.x, m_scale.y);
+ SDL_RenderSetScale(m_renderer, m_scale.x, m_scale.y);
}
void
void
SDLRenderer::draw_surface(const DrawingRequest& request)
{
- SDLPainter::draw_surface(renderer, request);
+ SDLPainter::draw_surface(m_renderer, request);
}
void
SDLRenderer::draw_surface_part(const DrawingRequest& request)
{
- SDLPainter::draw_surface_part(renderer, request);
+ SDLPainter::draw_surface_part(m_renderer, request);
}
void
SDLRenderer::draw_gradient(const DrawingRequest& request)
{
- SDLPainter::draw_gradient(renderer, request);
+ SDLPainter::draw_gradient(m_renderer, request);
}
void
SDLRenderer::draw_filled_rect(const DrawingRequest& request)
{
- SDLPainter::draw_filled_rect(renderer, request);
+ SDLPainter::draw_filled_rect(m_renderer, request);
}
void
SDLRenderer::draw_inverse_ellipse(const DrawingRequest& request)
{
- SDLPainter::draw_inverse_ellipse(renderer, request);
+ SDLPainter::draw_inverse_ellipse(m_renderer, request);
}
void
// [Christoph] TODO: Yes, this method also takes care of the actual disk I/O. Split it?
int width;
int height;
- if (SDL_GetRendererOutputSize(renderer, &width, &height) != 0)
+ if (SDL_GetRendererOutputSize(m_renderer, &width, &height) != 0)
{
log_warning << "SDL_GetRenderOutputSize failed: " << SDL_GetError() << std::endl;
}
}
else
{
- int ret = SDL_RenderReadPixels(renderer, NULL,
+ int ret = SDL_RenderReadPixels(m_renderer, NULL,
SDL_PIXELFORMAT_ABGR8888,
surface->pixels,
surface->pitch);
void
SDLRenderer::flip()
{
- SDL_RenderPresent(renderer);
+ SDL_RenderPresent(m_renderer);
}
void
{
if (!g_config->use_fullscreen)
{
- SDL_SetWindowFullscreen(window, 0);
+ SDL_SetWindowFullscreen(m_window, 0);
}
else
{
if (g_config->fullscreen_size.width == 0 &&
g_config->fullscreen_size.height == 0)
{
- if (SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP) != 0)
+ if (SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP) != 0)
{
log_warning << "failed to switch to desktop fullscreen mode: "
<< SDL_GetError() << std::endl;
mode.refresh_rate = g_config->fullscreen_refresh_rate;
mode.driverdata = 0;
- if (SDL_SetWindowDisplayMode(window, &mode) != 0)
+ if (SDL_SetWindowDisplayMode(m_window, &mode) != 0)
{
log_warning << "failed to set display mode: "
<< mode.w << "x" << mode.h << "@" << mode.refresh_rate << ": "
}
else
{
- if (SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN) != 0)
+ if (SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN) != 0)
{
log_warning << "failed to switch to fullscreen mode: "
<< mode.w << "x" << mode.h << "@" << mode.refresh_rate << ": "
float pixel_aspect_ratio = 1.0f;
if (g_config->aspect_size != Size(0, 0))
{
- pixel_aspect_ratio = calculate_pixel_aspect_ratio(desktop_size,
+ pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size,
g_config->aspect_size);
}
else if (g_config->use_fullscreen)
{
- pixel_aspect_ratio = calculate_pixel_aspect_ratio(desktop_size,
+ pixel_aspect_ratio = calculate_pixel_aspect_ratio(m_desktop_size,
target_size);
}
target_size,
pixel_aspect_ratio,
g_config->magnification,
- m_scale, logical_size, viewport);
+ m_scale, logical_size, m_viewport);
SCREEN_WIDTH = logical_size.width;
SCREEN_HEIGHT = logical_size.height;
- if (viewport.x != 0 || viewport.y != 0)
+ if (m_viewport.x != 0 || m_viewport.y != 0)
{
// Clear the screen to avoid garbage in unreachable areas after we
// reset the coordinate system
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
- SDL_RenderClear(renderer);
- SDL_RenderPresent(renderer);
- SDL_RenderClear(renderer);
+ SDL_SetRenderDrawColor(m_renderer, 0, 0, 0, 255);
+ SDL_SetRenderDrawBlendMode(m_renderer, SDL_BLENDMODE_NONE);
+ SDL_RenderClear(m_renderer);
+ SDL_RenderPresent(m_renderer);
+ SDL_RenderClear(m_renderer);
}
// SetViewport() works in scaled screen coordinates, so we have to
// reset it to 1.0, 1.0 to get meaningful results
- SDL_RenderSetScale(renderer, 1.0f, 1.0f);
- SDL_RenderSetViewport(renderer, &viewport);
- SDL_RenderSetScale(renderer, m_scale.x, m_scale.y);
+ SDL_RenderSetScale(m_renderer, 1.0f, 1.0f);
+ SDL_RenderSetViewport(m_renderer, &m_viewport);
+ SDL_RenderSetScale(m_renderer, m_scale.x, m_scale.y);
}
void
Vector
SDLRenderer::to_logical(int physical_x, int physical_y)
{
- return Vector(static_cast<float>(physical_x - viewport.x) * SCREEN_WIDTH / viewport.w,
- static_cast<float>(physical_y - viewport.y) * SCREEN_HEIGHT / viewport.h);
+ return Vector(static_cast<float>(physical_x - m_viewport.x) * SCREEN_WIDTH / m_viewport.w,
+ static_cast<float>(physical_y - m_viewport.y) * SCREEN_HEIGHT / m_viewport.h);
}
void
{
Uint16 ramp[256];
SDL_CalculateGammaRamp(gamma, ramp);
- SDL_SetWindowGammaRamp(window, ramp, ramp, ramp);
+ SDL_SetWindowGammaRamp(m_window, ramp, ramp, ramp);
}
/* EOF */