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 
36 namespace Colony {
37 
38 // CALCROBO.C projects both axes with (coordinate << 8) / depth.
39 const float kProjectionFocalLength = 256.0f;
40 
41 class Renderer {
42 public:
43  virtual ~Renderer() {}
44 
45  // 2D drawing primitives (used for UI overlay, dashboard, etc.)
46  virtual void clear(uint32 color) = 0;
47  virtual void drawLine(int x1, int y1, int x2, int y2, uint32 color) = 0;
48  virtual void drawRect(const Common::Rect &rect, uint32 color) = 0;
49  virtual void fillRect(const Common::Rect &rect, uint32 color) = 0;
50  virtual void drawString(const Graphics::Font *font, const Common::String &str, int x, int y, uint32 color, Graphics::TextAlign align = Graphics::kTextAlignLeft) = 0;
51  virtual void drawEllipse(int x, int y, int rx, int ry, uint32 color) = 0;
52  virtual void fillEllipse(int x, int y, int rx, int ry, uint32 color) = 0;
53  virtual void fillDitherRect(const Common::Rect &rect, uint32 color1, uint32 color2) = 0;
54  virtual void setPixel(int x, int y, uint32 color) = 0;
55  virtual void drawQuad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, uint32 color) = 0;
56  virtual void drawPolygon(const int *x, const int *y, int count, uint32 color) = 0;
57 
58  virtual void setPalette(const byte *palette, uint start, uint count) = 0;
59 
60  // 3D scene rendering
61  virtual void begin3D(int camX, int camY, int camZ, int angle, int angleY, const Common::Rect &viewport) = 0;
62  virtual void draw3DWall(int x1, int y1, int x2, int y2, uint32 color) = 0;
63  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;
64  virtual void draw3DPolygon(const float *x, const float *y, const float *z, int count, uint32 color) = 0;
65  virtual void draw3DLine(float x1, float y1, float z1, float x2, float y2, float z2, uint32 color) = 0;
66  virtual void end3D() = 0;
67 
68  // Buffer management
69  virtual void copyToScreen() = 0;
70  virtual void setWireframe(bool enable, int64_t fillColor = -1) = 0;
71  virtual void setXorMode(bool enable) {}
72  virtual void setStippleData(const byte *data) {}
73  virtual void setMacColors(uint32 fg, uint32 bg) {}
74  virtual void setDepthState(bool testEnabled, bool writeEnabled) {}
75  virtual void setDepthRange(float nearVal, float farVal) {}
76  // features.c clipped each wall feature to its own wall (ClipRect(&rClip)).
77  virtual void setFeatureClipX(int left, int right) {}
78  virtual void clearFeatureClipX() {}
79  virtual void setSquarePixelViewport(bool enable) = 0;
80  virtual void computeScreenViewport() = 0;
81 
82  // Window-pixel rect the logical canvas is currently drawn into.
83  const Common::Rect &screenViewport() const { return _screenViewport; }
84 
85  // Overlay a RGBA software surface onto the GL framebuffer (for Mac menu bar).
86  virtual void drawSurface(const Graphics::Surface *surf, int x, int y) {}
87  virtual Graphics::Surface *getScreenshot() { return nullptr; }
88  virtual Graphics::PixelFormat getPixelFormat() = 0;
89 
90  // Convenience color accessors
91  uint32 white() const { return 255; }
92  uint32 black() const { return 0; }
93 
94 protected:
95  Common::Rect _screenViewport;
96 };
97 
98 // Window pixels (what the event manager delivers) to logical canvas coords and
99 // back, through screenViewport(). Scaling by the plain window/canvas ratio
100 // instead lands every hit test half a black bar off. Points inside the bars
101 // clamp to the nearest canvas edge.
102 Common::Point windowToCanvas(const Common::Rect &viewport, const Common::Point &p, int canvasW, int canvasH);
103 Common::Point canvasToWindow(const Common::Rect &viewport, const Common::Point &p, int canvasW, int canvasH);
104 
105 // Factory function (follows Freescape pattern: picks best available renderer)
106 Renderer *createRenderer(OSystem *system, int width, int height);
107 
108 } // End of namespace Colony
109 
110 #endif
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
Definition: surface.h:67
Definition: pixelformat.h:138
Align the text to the left.
Definition: font.h:51
Definition: rect.h:536
Definition: colony.h:55
Definition: renderer.h:41
Definition: rect.h:144
Definition: system.h:166