summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-06-12 20:24:12 +0000
committertruelight <truelight@openttd.org>2007-06-12 20:24:12 +0000
commitf3f744d36a60431a6845d2b7e3ce17e64ee2e4f5 (patch)
treebed173ca279e1556489d31b0b8aa873a6d1cf110 /src/video
parent381b11c9796d6b40653f8b4c319c33f9920f047a (diff)
downloadopenttd-f3f744d36a60431a6845d2b7e3ce17e64ee2e4f5.tar.xz
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
-Add: added NULL blitter and renderer, which are always used for -vnull -Add: dedicated driver doesn't blit nor render by default. Can be overruled by user. (-D -b 8bpp-optimized) -Remove: removed CTRL+D from win32, which is incompatible with above -Add: extended screenshot support for PNG and BMP -Codechange: remove all hardcoded 8bpp references and replace them with more dynamic ones -Codechange: minor stuff in blitters
Diffstat (limited to 'src/video')
-rw-r--r--src/video/cocoa_v.mm5
-rw-r--r--src/video/dedicated_v.cpp10
-rw-r--r--src/video/null_v.cpp14
-rw-r--r--src/video/sdl_v.cpp22
-rw-r--r--src/video/win32_v.cpp101
5 files changed, 55 insertions, 97 deletions
diff --git a/src/video/cocoa_v.mm b/src/video/cocoa_v.mm
index b8193e902..7c563d281 100644
--- a/src/video/cocoa_v.mm
+++ b/src/video/cocoa_v.mm
@@ -69,6 +69,7 @@ extern "C" void HideMenuBar();
#include "../macros.h"
#include "../os/macosx/splash.h"
#include "../variables.h"
+#include "../blitter/blitter.hpp"
#include "cocoa_v.h"
#include "cocoa_keys.h"
@@ -950,6 +951,10 @@ static void QZ_SetPortAlphaOpaque()
static void QZ_UpdateWindowPalette(uint start, uint count)
{
+ /* We can only update the palette in 8bpp for now */
+ /* TODO -- We need support for other bpps too! */
+ if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 8) return;
+
uint i;
switch (_cocoa_video_data.device_bpp) {
diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp
index 046dc2ac8..4aa6b9f20 100644
--- a/src/video/dedicated_v.cpp
+++ b/src/video/dedicated_v.cpp
@@ -13,6 +13,7 @@
#include "../console.h"
#include "../variables.h"
#include "../genworld.h"
+#include "../blitter/blitter.hpp"
#include "dedicated_v.h"
#ifdef BEOS_NET_SERVER
@@ -112,7 +113,7 @@ static void CloseWindowsConsoleThread()
#endif
-static Pixel *_dedicated_video_mem;
+static void *_dedicated_video_mem;
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
extern void SwitchMode(int new_mode);
@@ -120,9 +121,14 @@ extern void SwitchMode(int new_mode);
static const char *DedicatedVideoStart(const char * const *parm)
{
+ int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
+ if (bpp == 0) _dedicated_video_mem = NULL;
+ else _dedicated_video_mem = malloc(_cur_resolution[0] * _cur_resolution[1] * (bpp / 8));
+
_screen.width = _screen.pitch = _cur_resolution[0];
_screen.height = _cur_resolution[1];
- _dedicated_video_mem = (Pixel *)malloc(_cur_resolution[0] * _cur_resolution[1] * sizeof(Pixel));
+ _screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
+ if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
SetDebugString("net=6");
diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp
index fd15954d9..0c1f4715e 100644
--- a/src/video/null_v.cpp
+++ b/src/video/null_v.cpp
@@ -5,19 +5,23 @@
#include "../gfx.h"
#include "../variables.h"
#include "../window.h"
+#include "../debug.h"
+#include "../blitter/blitter.hpp"
#include "null_v.h"
-static Pixel *_null_video_mem = NULL;
-
static const char* NullVideoStart(const char* const* parm)
{
_screen.width = _screen.pitch = _cur_resolution[0];
_screen.height = _cur_resolution[1];
- _null_video_mem = (Pixel *)malloc(_cur_resolution[0] * _cur_resolution[1] * sizeof(Pixel));
+ /* Do not render, nor blit */
+ DEBUG(misc, 1, "Forcing blitter 'null'...");
+ BlitterFactoryBase::SelectBlitter("null");
+ _screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
+ if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
return NULL;
}
-static void NullVideoStop() { free(_null_video_mem); }
+static void NullVideoStop() { }
static void NullVideoMakeDirty(int left, int top, int width, int height) {}
@@ -27,7 +31,7 @@ static void NullVideoMainLoop()
for (i = 0; i < 1000; i++) {
GameLoop();
- _screen.dst_ptr = _null_video_mem;
+ _screen.dst_ptr = NULL;
UpdateWindows();
}
}
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 9a70b55a6..8b851e2d6 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -13,6 +13,8 @@
#include "../window.h"
#include "../network/network.h"
#include "../variables.h"
+#include "../blitter/blitter.hpp"
+#include "../renderer/renderer.hpp"
#include "sdl_v.h"
#include <SDL.h>
@@ -36,6 +38,10 @@ static void SdlVideoMakeDirty(int left, int top, int width, int height)
static void UpdatePalette(uint start, uint count)
{
+ /* We can only update the palette in 8bpp for now */
+ /* TODO -- We need support for other bpps too! */
+ if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 8) return;
+
SDL_Color pal[256];
uint i;
@@ -172,10 +178,13 @@ static bool CreateMainSurface(int w, int h)
extern const char _openttd_revision[];
SDL_Surface *newscreen, *icon;
char caption[50];
+ int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
GetAvailableVideoMode(&w, &h);
- DEBUG(driver, 1, "SDL: using mode %dx%d", w, h);
+ DEBUG(driver, 1, "SDL: using mode %dx%dx%d", w, h, bpp);
+
+ if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
/* Give the application an icon */
icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp");
@@ -189,14 +198,15 @@ static bool CreateMainSurface(int w, int h)
}
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
- newscreen = SDL_CALL SDL_SetVideoMode(w, h, 8, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
+ newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
if (newscreen == NULL)
return false;
_screen.width = newscreen->w;
_screen.height = newscreen->h;
- _screen.pitch = newscreen->pitch / sizeof(Pixel);
-
+ _screen.pitch = newscreen->pitch / (bpp / 8);
+ _screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
+ if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
_sdl_screen = newscreen;
InitPalette();
@@ -469,7 +479,7 @@ static void SdlVideoMainLoop()
(keys[SDLK_DOWN] ? 8 : 0);
GameLoop();
- _screen.dst_ptr = (Pixel*)_sdl_screen->pixels;
+ _screen.dst_ptr = _sdl_screen->pixels;
UpdateWindows();
if (++pal_tick > 4) {
CheckPaletteAnim();
@@ -478,7 +488,7 @@ static void SdlVideoMainLoop()
DrawSurfaceToScreen();
} else {
SDL_CALL SDL_Delay(1);
- _screen.dst_ptr = (Pixel*)_sdl_screen->pixels;
+ _screen.dst_ptr = _sdl_screen->pixels;
DrawTextMessage();
DrawMouseCursor();
DrawSurfaceToScreen();
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index cee533c7c..9e14290d3 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -9,6 +9,7 @@
#include "../variables.h"
#include "../win32.h"
#include "../window.h"
+#include "../blitter/blitter.hpp"
#include "win32_v.h"
#include <windows.h>
#include <tchar.h>
@@ -16,22 +17,18 @@
static struct {
HWND main_wnd;
HBITMAP dib_sect;
- Pixel *bitmap_bits;
- Pixel *buffer_bits;
- Pixel *alloced_bits;
+ void *buffer_bits;
HPALETTE gdi_palette;
int width;
int height;
int width_org;
int height_org;
bool fullscreen;
- bool double_size;
bool has_focus;
bool running;
} _wnd;
bool _force_full_redraw;
-bool _double_size;
bool _window_maximize;
uint _display_hz;
uint _fullscreen_bpp;
@@ -63,6 +60,10 @@ static void MakePalette()
static void UpdatePalette(HDC dc, uint start, uint count)
{
+ /* We can only update the palette in 8bpp for now */
+ /* TODO -- We need support for other bpps too! */
+ if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 8) return;
+
RGBQUAD rgb[256];
uint i;
@@ -136,11 +137,6 @@ static bool AllocateDibSection(int w, int h);
static void ClientSizeChanged(int w, int h)
{
- if (_wnd.double_size) {
- w /= 2;
- h /= 2;
- }
-
// allocate new dib section of the new size
if (AllocateDibSection(w, h)) {
// mark all palette colors dirty
@@ -319,11 +315,6 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
DrawMouseCursor();
}
- if (_wnd.double_size) {
- x /= 2;
- y /= 2;
- }
-
if (_cursor.fix_at) {
int dx = x - _cursor.pos.x;
int dy = y - _cursor.pos.y;
@@ -334,10 +325,6 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
pt.x = _cursor.pos.x;
pt.y = _cursor.pos.y;
- if (_wnd.double_size) {
- pt.x *= 2;
- pt.y *= 2;
- }
ClientToScreen(hwnd, &pt);
SetCursorPos(pt.x, pt.y);
}
@@ -400,13 +387,6 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
* WM_KEYDOWN only handles CTRL+ commands and special keys like VK_LEFT, etc. */
if (keycode == 0 || (keycode > WKC_PAUSE && GB(keycode, 13, 4) == 0)) return 0;
- if (keycode == ('D' | WKC_CTRL) && !_wnd.fullscreen) {
- _double_size ^= 1;
- _wnd.double_size = _double_size;
- ClientSizeChanged(_wnd.width, _wnd.height);
- MarkWholeScreenDirty();
- }
-
HandleKeypress(0 | (keycode << 16));
return 0;
}
@@ -455,16 +435,8 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
w = r->right - r->left - (r2.right - r2.left);
h = r->bottom - r->top - (r2.bottom - r2.top);
- if (_wnd.double_size) {
- w /= 2;
- h /= 2;
- }
w = clamp(w, 64, MAX_SCREEN_WIDTH);
h = clamp(h, 64, MAX_SCREEN_HEIGHT);
- if (_wnd.double_size) {
- w *= 2;
- h *= 2;
- }
SetRect(&r2, 0, 0, w, h);
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
@@ -567,8 +539,6 @@ static void MakeWindow(bool full_screen)
{
_fullscreen = full_screen;
- _wnd.double_size = _double_size && !full_screen;
-
// recreate window?
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
DestroyWindow(_wnd.main_wnd);
@@ -581,6 +551,9 @@ static void MakeWindow(bool full_screen)
if (full_screen) {
DEVMODE settings;
+ /* Make sure we are always at least the screen-depth of the blitter */
+ if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
+
memset(&settings, 0, sizeof(settings));
settings.dmSize = sizeof(settings);
settings.dmFields =
@@ -649,49 +622,39 @@ static bool AllocateDibSection(int w, int h)
{
BITMAPINFO *bi;
HDC dc;
+ int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
w = clamp(w, 64, MAX_SCREEN_WIDTH);
h = clamp(h, 64, MAX_SCREEN_HEIGHT);
+ if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
+
if (w == _screen.width && h == _screen.height)
return false;
_screen.width = w;
_screen.pitch = ALIGN(w, 4);
_screen.height = h;
-
- if (_wnd.alloced_bits) {
- free(_wnd.alloced_bits);
- _wnd.alloced_bits = NULL;
- }
-
+ _screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
+ if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- if (_wnd.double_size) {
- w = ALIGN(w, 4);
- _wnd.alloced_bits = _wnd.buffer_bits = (Pixel *)malloc(w * h * sizeof(Pixel));
- w *= 2;
- h *= 2;
- }
-
bi->bmiHeader.biWidth = _wnd.width = w;
bi->bmiHeader.biHeight = -(_wnd.height = h);
bi->bmiHeader.biPlanes = 1;
- bi->bmiHeader.biBitCount = 8;
+ bi->bmiHeader.biBitCount = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
bi->bmiHeader.biCompression = BI_RGB;
if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
dc = GetDC(0);
- _wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.bitmap_bits, NULL, 0);
+ _wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0);
if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
ReleaseDC(0, dc);
- if (!_wnd.double_size) _wnd.buffer_bits = _wnd.bitmap_bits;
-
return true;
}
@@ -723,7 +686,7 @@ static void FindResolutions()
* Doesn't really matter since we don't pass a string anyways, but still
* a letdown */
for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
- if (dm.dmBitsPerPel == 8 && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
+ if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
IS_INT_INSIDE(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) {
uint j;
@@ -786,43 +749,13 @@ static void Win32GdiStop()
#if !defined(WINCE)
if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0);
#endif
- if (_wnd.double_size) {
- _cur_resolution[0] *= 2;
- _cur_resolution[1] *= 2;
- }
-
MyShowCursor(true);
}
-// simple upscaler by 2
-static void filter(int left, int top, int width, int height)
-{
- uint p = _screen.pitch;
- const Pixel *s = _wnd.buffer_bits + top * p + left;
- Pixel *d = _wnd.bitmap_bits + top * p * 4 + left * 2;
-
- for (; height > 0; height--) {
- int i;
-
- for (i = 0; i != width; i++) {
- d[i * 2] = d[i * 2 + 1] = d[i * 2 + p * 2] = d[i * 2 + 1 + p * 2] = s[i];
- }
- s += p;
- d += p * 4;
- }
-}
-
static void Win32GdiMakeDirty(int left, int top, int width, int height)
{
RECT r = { left, top, left + width, top + height };
- if (_wnd.double_size) {
- filter(left, top, width, height);
- r.left *= 2;
- r.top *= 2;
- r.right *= 2;
- r.bottom *= 2;
- }
InvalidateRect(_wnd.main_wnd, &r, FALSE);
}