GteBaseEngine.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Graphics/GteBlendState.h>
11 #include <Graphics/GteBuffer.h>
13 #include <Graphics/GteFont.h>
17 #include <array>
18 #include <memory>
19 
20 namespace gte
21 {
22 
24 {
25 public:
26  // Abstract base class.
27  virtual ~BaseEngine();
28 
29  // Viewport management. The measurements are in window coordinates. The
30  // origin of the window is (x,y), the window width is w, and the window
31  // height is h. The depth range for the view volume is [zmin,zmax]. The
32  // DX12 viewport is left-handed with origin the upper-left corner of the
33  // window, the x-axis is directed rightward, the y-axis is directed
34  // downward, and the depth range is a subset of [0,1].
35  virtual void SetViewport(int x, int y, int w, int h) = 0;
36  virtual void GetViewport(int& x, int& y, int& w, int& h) const = 0;
37  virtual void SetDepthRange(float zmin, float zmax) = 0;
38  virtual void GetDepthRange(float& zmin, float& zmax) const = 0;
39 
40  // Window resizing.
41  virtual bool Resize(unsigned int w, unsigned int h) = 0;
42 
43  // Support for clearing the color, depth, and stencil back buffers.
44  inline void SetClearColor(std::array<float, 4> const& clearColor);
45  inline void SetClearDepth(float clearDepth);
46  inline void SetClearStencil(unsigned int clearStencil);
47  inline std::array<float, 4> const& GetClearColor() const;
48  inline float GetClearDepth() const;
49  inline unsigned int GetClearStencil() const;
50  virtual void DisplayColorBuffer(unsigned int syncInterval) = 0;
51 
52  // Support for bitmapped fonts used in text rendering. The default font
53  // is Arial (height 18, no italics, no bold).
54  virtual void SetFont(std::shared_ptr<Font> const& font);
55  inline std::shared_ptr<Font> const& GetFont() const;
56  inline void SetDefaultFont();
57  inline std::shared_ptr<Font> const& GetDefaultFont() const;
58 
59  // Global drawing state. The default states are shown in GteBlendState.h,
60  // GteDepthStencil.h, and GteRasterizerState.h.
61  virtual void SetBlendState(std::shared_ptr<BlendState> const& state) = 0;
62  inline std::shared_ptr<BlendState> const& GetBlendState() const;
63  inline void SetDefaultBlendState();
64  inline std::shared_ptr<BlendState> const& GetDefaultBlendState() const;
65 
66  virtual void SetDepthStencilState(std::shared_ptr<DepthStencilState> const& state) = 0;
67  inline std::shared_ptr<DepthStencilState> const& GetDepthStencilState() const;
68  inline void SetDefaultDepthStencilState();
69  inline std::shared_ptr<DepthStencilState> const& GetDefaultDepthStencilState() const;
70 
71  virtual void SetRasterizerState(std::shared_ptr<RasterizerState> const& state) = 0;
72  inline std::shared_ptr<RasterizerState> const& GetRasterizerState() const;
73  inline void SetDefaultRasterizerState();
74  inline std::shared_ptr<RasterizerState> const& GetDefaultRasterizerState() const;
75 
76  // Support for copying from CPU to GPU via mapped memory.
77  virtual bool Update(std::shared_ptr<Buffer> const& buffer) = 0;
78  virtual bool Update(std::shared_ptr<TextureSingle> const& texture) = 0;
79 
80  // TODO: Include this here for now until DX12 engine has drawing
81  // encapsulated.
82  virtual uint64_t Draw(std::shared_ptr<OverlayEffect> const& effect) = 0;
83 
84 protected:
85  // Abstract base class. Base engine objects may not be copied.
86  BaseEngine();
87  BaseEngine(BaseEngine const&) = delete;
88  BaseEngine& operator=(BaseEngine const&) = delete;
89 
90  // Helpers for construction and destruction.
91  void CreateDefaultGlobalState();
92  virtual void DestroyDefaultGlobalState();
93 
94  // The window size.
95  unsigned int mXSize, mYSize;
96 
97  // Clear values.
98  std::array<float, 4> mClearColor;
99  float mClearDepth;
100  unsigned int mClearStencil;
101 
102  // Fonts for text rendering.
103  std::shared_ptr<Font> mDefaultFont;
104  std::shared_ptr<Font> mActiveFont;
105 
106  // Global state.
107  std::shared_ptr<BlendState> mDefaultBlendState;
108  std::shared_ptr<BlendState> mActiveBlendState;
109  std::shared_ptr<DepthStencilState> mDefaultDepthStencilState;
110  std::shared_ptr<DepthStencilState> mActiveDepthStencilState;
111  std::shared_ptr<RasterizerState> mDefaultRasterizerState;
112  std::shared_ptr<RasterizerState> mActiveRasterizerState;
113 };
114 
115 
116 inline void BaseEngine::SetClearColor(std::array<float, 4> const& clearColor)
117 {
118  mClearColor = clearColor;
119 }
120 
121 inline void BaseEngine::SetClearDepth(float clearDepth)
122 {
123  mClearDepth = clearDepth;
124 }
125 
126 inline void BaseEngine::SetClearStencil(unsigned int clearStencil)
127 {
128  mClearStencil = clearStencil;
129 }
130 
131 inline std::array<float, 4> const& BaseEngine::GetClearColor() const
132 {
133  return mClearColor;
134 }
135 
136 inline float BaseEngine::GetClearDepth() const
137 {
138  return mClearDepth;
139 }
140 
141 inline unsigned int BaseEngine::GetClearStencil() const
142 {
143  return mClearStencil;
144 }
145 
146 inline std::shared_ptr<Font> const& BaseEngine::GetFont() const
147 {
148  return mActiveFont;
149 }
150 
152 {
153  SetFont(mDefaultFont);
154 }
155 
156 inline std::shared_ptr<Font> const& BaseEngine::GetDefaultFont() const
157 {
158  return mDefaultFont;
159 }
160 
161 inline std::shared_ptr<BlendState> const& BaseEngine::GetBlendState() const
162 {
163  return mActiveBlendState;
164 }
165 
167 {
168  SetBlendState(mDefaultBlendState);
169 }
170 
171 inline std::shared_ptr<BlendState> const& BaseEngine::GetDefaultBlendState() const
172 {
173  return mDefaultBlendState;
174 }
175 
176 inline std::shared_ptr<DepthStencilState> const& BaseEngine::GetDepthStencilState() const
177 {
178  return mActiveDepthStencilState;
179 }
180 
182 {
183  SetDepthStencilState(mDefaultDepthStencilState);
184 }
185 
186 inline std::shared_ptr<DepthStencilState> const& BaseEngine::GetDefaultDepthStencilState() const
187 {
188  return mDefaultDepthStencilState;
189 }
190 
191 inline std::shared_ptr<RasterizerState> const& BaseEngine::GetRasterizerState() const
192 {
193  return mActiveRasterizerState;
194 }
195 
197 {
198  SetRasterizerState(mDefaultRasterizerState);
199 }
200 
201 inline std::shared_ptr<RasterizerState> const& BaseEngine::GetDefaultRasterizerState() const
202 {
203  return mDefaultRasterizerState;
204 }
205 
206 }
std::shared_ptr< RasterizerState > mDefaultRasterizerState
std::shared_ptr< Font > mActiveFont
std::shared_ptr< RasterizerState > mActiveRasterizerState
std::shared_ptr< BlendState > mActiveBlendState
std::array< float, 4 > const & GetClearColor() const
std::shared_ptr< BlendState > const & GetDefaultBlendState() const
void SetDefaultDepthStencilState()
GLint GLenum GLint x
Definition: glcorearb.h:404
void SetClearColor(std::array< float, 4 > const &clearColor)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:852
std::array< float, 4 > mClearColor
Definition: GteBaseEngine.h:98
unsigned int mClearStencil
GLuint texture
Definition: glcorearb.h:410
void SetClearDepth(float clearDepth)
void SetClearStencil(unsigned int clearStencil)
std::shared_ptr< DepthStencilState > mActiveDepthStencilState
GLclampd zmax
Definition: glext.h:6450
std::shared_ptr< Font > mDefaultFont
std::shared_ptr< BlendState > const & GetBlendState() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:1997
std::shared_ptr< RasterizerState > const & GetDefaultRasterizerState() const
std::shared_ptr< DepthStencilState > const & GetDepthStencilState() const
unsigned int mYSize
Definition: GteBaseEngine.h:95
std::shared_ptr< BlendState > mDefaultBlendState
float GetClearDepth() const
GLuint buffer
Definition: glcorearb.h:655
std::shared_ptr< RasterizerState > const & GetRasterizerState() const
void SetDefaultBlendState()
std::shared_ptr< Font > const & GetDefaultFont() const
std::shared_ptr< DepthStencilState > mDefaultDepthStencilState
unsigned int GetClearStencil() const
std::shared_ptr< DepthStencilState > const & GetDefaultDepthStencilState() const
void SetDefaultRasterizerState()
GLint y
Definition: glcorearb.h:98
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
std::shared_ptr< Font > const & GetFont() const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59