ScummVM API documentation
renderer.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Based on the original sources
21 * https://github.com/Croquetx/thecolony
22 * Copyright (C) 1988, David A. Smith
23 *
24 * Distributed under Apache Version 2.0 License
25 *
26 */
27
28#ifndef COLONY_RENDERER_H
29#define COLONY_RENDERER_H
30
31#include "common/scummsys.h"
32#include "common/rect.h"
33#include "graphics/managed_surface.h"
34#include "graphics/font.h"
35
36namespace Colony {
37
38// CALCROBO.C projects both axes with (coordinate << 8) / depth.
39const float kProjectionFocalLength = 256.0f;
40const float kProjectionNearClip = 1.0f;
41
42class Renderer {
43public:
44 virtual ~Renderer() {}
45
46 // 2D drawing primitives (used for UI overlay, dashboard, etc.)
47 virtual void clear(uint32 color) = 0;
48 virtual void drawLine(int x1, int y1, int x2, int y2, uint32 color) = 0;
49 virtual void drawRect(const Common::Rect &rect, uint32 color) = 0;
50 virtual void fillRect(const Common::Rect &rect, uint32 color) = 0;
51 virtual void drawString(const Graphics::Font *font, const Common::String &str, int x, int y, uint32 color, Graphics::TextAlign align = Graphics::kTextAlignLeft) = 0;
52 virtual void drawEllipse(int x, int y, int rx, int ry, uint32 color) = 0;
53 virtual void fillEllipse(int x, int y, int rx, int ry, uint32 color) = 0;
54 virtual void fillDitherRect(const Common::Rect &rect, uint32 color1, uint32 color2) = 0;
55 virtual void setPixel(int x, int y, uint32 color) = 0;
56 virtual void drawQuad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, uint32 color) = 0;
57 virtual void drawPolygon(const int *x, const int *y, int count, uint32 color) = 0;
58
59 virtual void setPalette(const byte *palette, uint start, uint count) = 0;
60
61 // 3D scene rendering
62 virtual void begin3D(int camX, int camY, int camZ, int angle, int angleY, const Common::Rect &viewport) = 0;
63 virtual void draw3DWall(int x1, int y1, int x2, int y2, uint32 color) = 0;
64 virtual void draw3DQuad(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, uint32 color) = 0;
65 virtual void draw3DPolygon(const float *x, const float *y, const float *z, int count, uint32 color) = 0;
66 virtual void draw3DLine(float x1, float y1, float z1, float x2, float y2, float z2, uint32 color) = 0;
67 virtual void end3D() = 0;
68
69 // Buffer management
70 virtual void copyToScreen() = 0;
71 virtual void setWireframe(bool enable, int64_t fillColor = -1) = 0;
72 virtual void setXorMode(bool enable) {}
73 virtual void setStippleData(const byte *data) {}
74 virtual void setMacColors(uint32 fg, uint32 bg) {}
75 virtual void setDepthState(bool testEnabled, bool writeEnabled) {}
76 virtual void setDepthRange(float nearVal, float farVal) {}
77 // features.c clipped each wall feature to its own wall (ClipRect(&rClip)).
78 virtual void setFeatureClipX(int left, int right) {}
79 virtual void clearFeatureClipX() {}
80 virtual void setSquarePixelViewport(bool enable) = 0;
81 virtual void setCanvasSize(int width, int height) = 0;
82 virtual void computeScreenViewport() = 0;
83
84 // Window-pixel rect the logical canvas is currently drawn into.
85 const Common::Rect &screenViewport() const { return _screenViewport; }
86
87 // Overlay a RGBA software surface onto the GL framebuffer (for Mac menu bar).
88 virtual void drawSurface(const Graphics::Surface *surf, int x, int y) {}
89 virtual Graphics::Surface *getScreenshot() { return nullptr; }
90 virtual Graphics::PixelFormat getPixelFormat() = 0;
91
92 // Convenience color accessors
93 uint32 white() const { return 255; }
94 uint32 black() const { return 0; }
95
96protected:
97 Common::Rect _screenViewport;
98};
99
100// Window pixels (what the event manager delivers) to logical canvas coords and
101// back, through screenViewport(). Scaling by the plain window/canvas ratio
102// instead lands every hit test half a black bar off. Points inside the bars
103// clamp to the nearest canvas edge.
104Common::Point windowToCanvas(const Common::Rect &viewport, const Common::Point &p, int canvasW, int canvasH);
105Common::Point canvasToWindow(const Common::Rect &viewport, const Common::Point &p, int canvasW, int canvasH);
106
107Common::Rect computeScreenViewport(OSystem *system, int width, int height, bool squarePixels);
108Common::Point computeMacCanvasSize(int screenWidth, int screenHeight, bool widescreen);
109
110// Factory function (follows Freescape pattern: picks best available renderer)
111Renderer *createRenderer(OSystem *system, int width, int height);
112
113} // End of namespace Colony
114
115#endif
Definition: renderer.h:42
Definition: str.h:59
Definition: font.h:83
Definition: system.h:166
TextAlign
Definition: font.h:48
@ kTextAlignLeft
Align the text to the left.
Definition: font.h:51
Definition: rect.h:144
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67