GteWindow2.cpp
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 #include <GTEnginePCH.h>
11 using namespace gte;
12 
14  :
15  Window(parameters),
16  mClampToWindow(true),
17  mDoFlip(false),
18  mScreenTextureNeedsUpdate(false)
19 {
20  if (parameters.allowResize)
21  {
22  parameters.created = false;
23  return;
24  }
25 
26  mOverlay = std::make_shared<OverlayEffect>(mProgramFactory, mXSize, mYSize, mXSize, mYSize,
28 
29  mScreenTexture = std::make_shared<Texture2>(DF_R8G8B8A8_UNORM, mXSize, mYSize);
30  mScreenTexture->SetUsage(Resource::DYNAMIC_UPDATE);
31  mOverlay->SetTexture(mScreenTexture);
32 
33  // The default is to disable depth and stenciling. For layered drawing in
34  // the z-direction, an application can choose to restore the default mode
35  // of depth and stenciling turned on.
36  mNoDepthStencilState = std::make_shared<DepthStencilState>();
37  mNoDepthStencilState->depthEnable = false;
38  mNoDepthStencilState->stencilEnable = false;
39  mEngine->SetDepthStencilState(mNoDepthStencilState);
40 
41  // Callback function for ImageUtility2 functions.
42  mDrawPixel = [this](int x, int y) { SetPixel(x, y, mPixelColor); };
43  mPixelColor = 0;
44 }
45 
46 bool Window2::OnResize(int, int)
47 {
48  // See the comments in GteWindow.h.
49  return false;
50 }
51 
53 {
55  {
56  mEngine->Update(mScreenTexture);
58  }
59 
60  mEngine->Draw(mOverlay);
62  mEngine->DisplayColorBuffer(0);
63 }
64 
66 {
67  // Stub for derived classes.
68 }
69 
70 void Window2::ClearScreen(unsigned int color)
71 {
72  unsigned int const numTexels = mScreenTexture->GetNumElements();
73  unsigned int* texels = mScreenTexture->Get<unsigned int>();
74  for (unsigned int i = 0; i < numTexels; ++i)
75  {
76  *texels++ = color;
77  }
78 }
79 
80 void Window2::SetPixel(int x, int y, unsigned int color)
81 {
82  if (mClampToWindow)
83  {
85  {
86  return;
87  }
88  }
89 
90  if (mDoFlip)
91  {
92  y = mYSize - 1 - y;
93  }
94 
95  mScreenTexture->Get<unsigned int>()[x + mXSize * y] = color;
96 }
97 
98 unsigned int Window2::GetPixel(int x, int y)
99 {
100  if (mClampToWindow)
101  {
103  {
104  return 0;
105  }
106  }
107 
108  if (mDoFlip)
109  {
110  y = mYSize - 1 - y;
111  }
112 
113  return mScreenTexture->Get<unsigned int>()[x + mXSize * y];
114 }
115 
116 void Window2::DrawThickPixel(int x, int y, int thick, unsigned int color)
117 {
118  mPixelColor = color;
120 }
121 
122 void Window2::DrawLine(int x0, int y0, int x1, int y1, unsigned int color)
123 {
124  mPixelColor = color;
125  ImageUtility2::DrawLine(x0, y0, x1, y1, mDrawPixel);
126 }
127 
128 void Window2::DrawRectangle(int xMin, int yMin, int xMax, int yMax, unsigned int color, bool solid)
129 {
130  mPixelColor = color;
131  ImageUtility2::DrawRectangle(xMin, yMin, xMax, yMax, solid, mDrawPixel);
132 }
133 
134 void Window2::DrawCircle(int xCenter, int yCenter, int radius, unsigned int color, bool solid)
135 {
136  mPixelColor = color;
137  ImageUtility2::DrawCircle(xCenter, yCenter, radius, solid, mDrawPixel);
138 }
139 
140 void Window2::DrawEllipse(int xCenter, int yCenter, int xExtent, int yExtent, unsigned int color)
141 {
142  mPixelColor = color;
143  ImageUtility2::DrawEllipse(xCenter, yCenter, xExtent, yExtent, mDrawPixel);
144 }
145 
146 void Window2::DrawFloodFill4(int x, int y, unsigned int foreColor, unsigned int backColor)
147 {
148  ImageUtility2::DrawFloodFill4<unsigned int>(x, y, mXSize, mYSize, foreColor, backColor,
149  [this](int x, int y, unsigned int color) { SetPixel(x, y, color); },
150  [this](int x, int y) { return GetPixel(x, y); });
151 }
void DrawEllipse(int xCenter, int yCenter, int xExtent, int yExtent, unsigned int color)
Definition: GteWindow2.cpp:140
static void DrawCircle(int xCenter, int yCenter, int radius, bool solid, std::function< void(int, int)> const &callback)
DYNAMIC_UPDATE
Definition: GteResource.h:42
GLuint color
Definition: glcorearb.h:1256
void DrawFloodFill4(int x, int y, unsigned int foreColor, unsigned int backColor)
Definition: GteWindow2.cpp:146
static void DrawLine(int x0, int y0, int x1, int y1, std::function< void(int, int)> const &callback)
virtual bool OnResize(int xSize, int ySize) override
Definition: GteWindow2.cpp:46
void DrawRectangle(int xMin, int yMin, int xMax, int yMax, unsigned int color, bool solid)
Definition: GteWindow2.cpp:128
std::shared_ptr< ProgramFactory > mProgramFactory
GLint GLenum GLint x
Definition: glcorearb.h:404
bool mDoFlip
Definition: GteWindow2.h:94
void SetPixel(int x, int y, unsigned int color)
Definition: GteWindow2.cpp:80
std::shared_ptr< Texture2 > mScreenTexture
Definition: GteWindow2.h:89
std::function< void(int, int)> mDrawPixel
Definition: GteWindow2.h:91
virtual void OnDisplay() override
Definition: GteWindow2.cpp:52
unsigned int mPixelColor
Definition: GteWindow2.h:92
GLfixed y1
Definition: glext.h:4952
std::shared_ptr< DepthStencilState > mNoDepthStencilState
Definition: GteWindow2.h:90
MIN_P_MAG_P_MIP_P
bool mClampToWindow
Definition: GteWindow2.h:93
bool mScreenTextureNeedsUpdate
Definition: GteWindow2.h:95
GLuint GLfloat x0
Definition: glext.h:9013
virtual void DrawScreenOverlay()
Definition: GteWindow2.cpp:65
std::shared_ptr< OverlayEffect > mOverlay
Definition: GteWindow2.h:88
std::shared_ptr< GraphicsEngine > mEngine
Definition: GLX/GteWindow.h:69
static void DrawEllipse(int xCenter, int yCenter, int xExtent, int yExtent, std::function< void(int, int)> const &callback)
void ClearScreen(unsigned int color)
Definition: GteWindow2.cpp:70
static void DrawRectangle(int xMin, int yMin, int xMax, int yMax, bool solid, std::function< void(int, int)> const &callback)
GLuint GLfloat GLfloat GLfloat x1
Definition: glext.h:9013
void DrawCircle(int xCenter, int yCenter, int radius, unsigned int color, bool solid)
Definition: GteWindow2.cpp:134
Window2(Parameters &parameters)
Definition: GteWindow2.cpp:13
DF_R8G8B8A8_UNORM
Definition: GteDataFormat.h:20
GLuint GLfloat GLfloat y0
Definition: glext.h:9013
static void DrawThickPixel(int x, int y, int thick, std::function< void(int, int)> const &callback)
void DrawThickPixel(int x, int y, int thick, unsigned int color)
Definition: GteWindow2.cpp:116
void DrawLine(int x0, int y0, int x1, int y1, unsigned int color)
Definition: GteWindow2.cpp:122
unsigned int GetPixel(int x, int y)
Definition: GteWindow2.cpp:98
GLint y
Definition: glcorearb.h:98
CLAMP


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