Pioneer
Graphics.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef _GRAPHICS_H
5 #define _GRAPHICS_H
6 
7 #include "RenderTarget.h"
8 #include <memory>
9 #include <vector>
10 
11 /*
12  * bunch of reused 3d drawy routines.
13  * XXX most of this is to be removed
14  */
15 namespace Graphics {
16 
17  enum RendererType {
21  };
22 
23  const char *RendererNameFromType(const RendererType rType);
24 
25  // requested video settings
26  struct Settings {
28  bool fullscreen;
29  bool hidden;
34  int vsync;
36  int height;
37  int width;
38  const char *iconFile;
39  const char *title;
40  };
41 
42  class Renderer;
43 
44  typedef Renderer *(*RendererCreateFunc)(const Settings &vs);
46 
47  //for querying available modes
48  struct VideoMode {
49  VideoMode(int w, int h) :
50  width(w),
51  height(h) {}
52 
53  int width;
54  int height;
55  };
56 
57  // Lightweight representation of viewport bounds to simplify viewport state management
58  struct Viewport {
60  x(0),
61  y(0),
62  w(0),
63  h(0) {}
64 
65  Viewport(int32_t _x, int32_t _y, int32_t _w, int32_t _h) :
66  x(_x),
67  y(_y),
68  w(_w),
69  h(_h) {}
70 
71  int32_t x, y, w, h;
72  };
73 
74  class Material;
75  extern Material *vtxColorMaterial;
76 
77  int GetScreenWidth();
78  int GetScreenHeight();
79 
80  float GetFov();
81  void SetFov(float);
82  float GetFovFactor(); //cached 2*tan(fov/2) for LOD
83 
84  // Project a point in the renderer's current coordinate system to screenspace
85  // as defined by Renderer::GetViewport.
86  // TODO: find a better place to hang this off of; this is too useful to be tied to a renderer object
87  vector3d ProjectToScreen(const Renderer *r, const vector3d &in);
88  vector3f ProjectToScreen(const Renderer *r, const vector3f &in);
89 
90  // does SDL video init, constructs appropriate Renderer
92  void Uninit();
93  std::vector<VideoMode> GetAvailableVideoModes();
94 
95  struct ScreendumpState {
96  std::unique_ptr<Uint8[]> pixels;
97  Uint32 width;
98  Uint32 height;
99  Uint32 stride;
100  Uint32 bpp;
101  };
102 } // namespace Graphics
103 
104 #endif /* _RENDER_H */
Definition: Material.h:81
Definition: Renderer.h:39
Definition: Background.h:13
Renderer * Init(Settings vs)
Definition: Graphics.cpp:99
void SetFov(float fov)
Definition: Graphics.cpp:54
Material * vtxColorMaterial
Definition: Graphics.cpp:34
Renderer *(* RendererCreateFunc)(const Settings &vs)
Definition: Graphics.h:44
RendererType
Definition: Graphics.h:17
@ RENDERER_DUMMY
Definition: Graphics.h:18
@ RENDERER_OPENGL_3x
Definition: Graphics.h:19
@ MAX_RENDERER_TYPE
Definition: Graphics.h:20
float GetFovFactor()
Definition: Graphics.cpp:60
vector3f ProjectToScreen(const Renderer *r, const vector3f &in)
Definition: Graphics.cpp:65
float GetFov()
Definition: Graphics.cpp:49
void Uninit()
Definition: Graphics.cpp:162
const char * RendererNameFromType(const RendererType rType)
Definition: Graphics.cpp:15
std::vector< VideoMode > GetAvailableVideoModes()
Definition: Graphics.cpp:172
int GetScreenWidth()
Definition: Graphics.cpp:39
void RegisterRenderer(RendererType type, RendererCreateFunc fn)
Definition: Graphics.cpp:26
int GetScreenHeight()
Definition: Graphics.cpp:44
Definition: Graphics.h:95
std::unique_ptr< Uint8[]> pixels
Definition: Graphics.h:96
Uint32 height
Definition: Graphics.h:98
Uint32 stride
Definition: Graphics.h:99
Uint32 bpp
Definition: Graphics.h:100
Uint32 width
Definition: Graphics.h:97
Definition: Graphics.h:26
bool useAnisotropicFiltering
Definition: Graphics.h:31
RendererType rendererType
Definition: Graphics.h:27
int height
Definition: Graphics.h:36
bool gl3ForwardCompatible
Definition: Graphics.h:33
const char * title
Definition: Graphics.h:39
bool fullscreen
Definition: Graphics.h:28
bool useTextureCompression
Definition: Graphics.h:30
int vsync
Definition: Graphics.h:34
int requestedSamples
Definition: Graphics.h:35
int width
Definition: Graphics.h:37
const char * iconFile
Definition: Graphics.h:38
bool enableDebugMessages
Definition: Graphics.h:32
bool hidden
Definition: Graphics.h:29
Definition: Graphics.h:48
int height
Definition: Graphics.h:54
int width
Definition: Graphics.h:53
VideoMode(int w, int h)
Definition: Graphics.h:49
Definition: Graphics.h:58
int32_t w
Definition: Graphics.h:71
int32_t x
Definition: Graphics.h:71
Viewport()
Definition: Graphics.h:59
Viewport(int32_t _x, int32_t _y, int32_t _w, int32_t _h)
Definition: Graphics.h:65
int32_t y
Definition: Graphics.h:71
int32_t h
Definition: Graphics.h:71