GteOverlayEffect.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 <Mathematics/GteVector2.h>
14 #include <Graphics/GteTexture2.h>
17 
18 namespace gte
19 {
20 
22 {
23 public:
24  // Create an overlay that allows you to use a simple color shader or a
25  // simple gray-scale shader.
26  OverlayEffect(std::shared_ptr<ProgramFactory> const& factory,
27  int windowWidth, int windowHeight, int textureWidth, int textureHeight,
28  SamplerState::Filter filter, SamplerState::Mode mode0, SamplerState::Mode mode1,
29  bool useColorPShader);
30 
31  // Create an overlay that uses a pixel shader other than the color or
32  // gray default shaders. The caller is responsible for creating a
33  // sampler for the pixel shader.
34  OverlayEffect(std::shared_ptr<ProgramFactory> const& factory,
35  int windowWidth, int windowHeight, int textureWidth, int textureHeight,
36  std::string const& psSource);
37 
38  // Access to the overlay rectangle (px,py,pw,ph), which is in client
39  // window coordinates. The upper-left corner of the overlay rectangle
40  // is (px,py). The width and height of the rectangle are pw and ph,
41  // respectively. The width and height must be positive. The corner
42  // (px,py) may be chosen outside the client window, allowing you to clip
43  // overlays against the window boundaries.
44  inline void SetOverlayRectangle(std::array<int,4> const& rectangle);
45  inline std::array<int,4> GetOverlayRectangle() const;
46 
47  // Access to the texture rectangle (tx,ty,tw,th), which is in texture
48  // image coordinates. The upper-left corner of the texture rectangle
49  // is (tx,ty). The width and height of the rectangle are tw and th,
50  // respectively. The width and height must be positive. The corner
51  // (tx,ty) may be chosen outside the texture image, but be aware that the
52  // colors drawn outside will depend on the sampler state mode.
53  void SetTextureRectangle(std::array<int,4> const& rectangle);
54  inline std::array<int,4> GetTextureRectangle() const;
55 
56  // Joint setting of rectangles (rare case), allowing for a single vertex
57  // buffer update.
58  void SetRectangles(std::array<int,4> const& overlayRectangle,
59  std::array<int,4> const& textureRectangle);
60 
61  // Test whether the input (x,y) is contained by the overlay rectangle.
62  // This is useful for hit testing in user interfaces.
63  bool Contains(int x, int y) const;
64 
65  // For DX11Engine::Draw(VertexBuffer*,IndexBuffer*,VisualEffect*). The
66  // vertex buffer is also needed for CPU-to-GPU copies when the overlay
67  // and/or texture rectangles are modified.
68  inline std::shared_ptr<VisualProgram> const& GetProgram() const;
69  inline std::shared_ptr<VertexBuffer> const& GetVertexBuffer() const;
70  inline std::shared_ptr<IndexBuffer> const& GetIndexBuffer() const;
71  inline std::shared_ptr<VisualEffect> const& GetEffect() const;
72 
73  // Dynamically update the overlay textures. The first function uses
74  // the default name "imageTexture". The second function allows you
75  // to set textures when you create an overlay with your own pixel
76  // shader.
77  void SetTexture(std::shared_ptr<Texture2> const& texture);
78  void SetTexture(std::string const& textureName,
79  std::shared_ptr<Texture2> const& texture);
80 
81 protected:
82  void Initialize(int windowWidth, int windowHeight, int textureWidth,
83  int textureHeight);
84 
85  struct Vertex
86  {
89  };
90 
91  void UpdateVertexBuffer();
92 
93  float mWindowWidth, mWindowHeight;
94  float mInvTextureWidth, mInvTextureHeight;
96  std::array<int,4> mOverlayRectangle;
97  std::array<int,4> mTextureRectangle;
98  std::shared_ptr<VertexBuffer> mVBuffer;
99  std::shared_ptr<IndexBuffer> mIBuffer;
100  std::shared_ptr<VisualProgram> mProgram;
101  std::shared_ptr<VisualEffect> mEffect;
102 
103  // Shader source code as strings.
110  static std::string const* msVSSource[ProgramFactory::PF_NUM_API];
111  static std::string const* msPSColorSource[ProgramFactory::PF_NUM_API];
112  static std::string const* msPSGraySource[ProgramFactory::PF_NUM_API];
113 };
114 
115 
117  std::array<int, 4> const& rectangle)
118 {
119  mOverlayRectangle = rectangle;
120  UpdateVertexBuffer();
121 }
122 
123 inline std::array<int, 4> OverlayEffect::GetOverlayRectangle() const
124 {
125  return mOverlayRectangle;
126 }
127 
128 inline std::array<int, 4> OverlayEffect::GetTextureRectangle() const
129 {
130  return mTextureRectangle;
131 }
132 
133 inline std::shared_ptr<VisualProgram> const&
135 {
136  return mProgram;
137 }
138 
139 inline std::shared_ptr<VertexBuffer> const&
141 {
142  return mVBuffer;
143 }
144 
145 inline std::shared_ptr<IndexBuffer> const&
147 {
148  return mIBuffer;
149 }
150 
151 inline std::shared_ptr<VisualEffect> const&
153 {
154  return mEffect;
155 }
156 
157 
158 }
std::array< int, 4 > mTextureRectangle
static std::string const msGLSLVSSource
std::shared_ptr< VertexBuffer > mVBuffer
std::shared_ptr< VisualProgram > mProgram
std::shared_ptr< VisualEffect > const & GetEffect() const
std::shared_ptr< VisualProgram > const & GetProgram() const
GLint GLenum GLint x
Definition: glcorearb.h:404
static std::string const msHLSLVSSource
std::shared_ptr< VisualEffect > mEffect
void SetOverlayRectangle(std::array< int, 4 > const &rectangle)
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GLuint texture
Definition: glcorearb.h:410
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1292
std::array< int, 4 > mOverlayRectangle
static std::string const msHLSLPSColorSource
static std::string const msHLSLPSGraySource
std::array< int, 4 > GetTextureRectangle() const
std::shared_ptr< IndexBuffer > mIBuffer
static std::string const msGLSLPSColorSource
static std::string const msGLSLPSGraySource
std::array< int, 4 > GetOverlayRectangle() const
GLint y
Definition: glcorearb.h:98
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63
std::shared_ptr< IndexBuffer > const & GetIndexBuffer() const
std::shared_ptr< VertexBuffer > const & GetVertexBuffer() const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01