Jetson Inference
DNN Vision Library
glDisplay.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef __GL_VIEWPORT_H__
24 #define __GL_VIEWPORT_H__
25 
26 
27 #include "glUtility.h"
28 #include "glTexture.h"
29 
30 #include <time.h>
31 
32 
37 class glDisplay
38 {
39 public:
47  static glDisplay* Create( float r=0.05f, float g=0.05f, float b=0.05f, float a=1.0f );
48 
57  static glDisplay* Create( const char* title, float r=0.05f, float g=0.05f, float b=0.05f, float a=1.0f );
58 
62  ~glDisplay();
63 
68  void BeginRender( bool userEvents=true );
69 
73  void EndRender();
74 
79  void Render( glTexture* texture, float x=5.0f, float y=30.0f );
80 
87  void Render( float* image, uint32_t width, uint32_t height, float x=5.0f, float y=30.0f, bool normalize=true );
88 
96  void RenderOnce( float* image, uint32_t width, uint32_t height, float x=5.0f, float y=30.0f, bool normalize=true );
97 
101  void UserEvents();
102 
106  void onEvent( uint msg, int a, int b );
107 
111  inline bool IsOpen() const { return !mWindowClosed; }
112 
116  inline bool IsClosed() const { return mWindowClosed; }
117 
121  inline float GetFPS() const { return 1000000000.0f / mAvgTime; }
122 
126  inline uint32_t GetWidth() const { return mWidth; }
127 
131  inline uint32_t GetHeight() const { return mHeight; }
132 
136  void SetTitle( const char* str );
137 
145  inline void SetBackgroundColor( float r, float g, float b, float a ) { mBgColor[0] = r; mBgColor[1] = g; mBgColor[2] = b; mBgColor[3] = a; }
146 
150  static const char* DEFAULT_TITLE;
151 
152 protected:
153  glDisplay();
154 
155  bool initWindow();
156  bool initGL();
157 
158  static const int screenIdx = 0;
159 
160  Display* mDisplayX;
161  Screen* mScreenX;
162  XVisualInfo* mVisualX;
163  Window mWindowX;
164  GLXContext mContextGL;
168 
169  uint32_t mWidth;
170  uint32_t mHeight;
171 
172  timespec mLastTime;
173  float mAvgTime;
174  float mBgColor[4];
175 };
176 
177 #endif
178 
Screen * mScreenX
Definition: glDisplay.h:161
timespec mLastTime
Definition: glDisplay.h:172
bool IsOpen() const
Returns true if the window is open.
Definition: glDisplay.h:111
static const char * DEFAULT_TITLE
Default title bar name.
Definition: glDisplay.h:150
bool initWindow()
float mBgColor[4]
Definition: glDisplay.h:174
Window mWindowX
Definition: glDisplay.h:163
Atom mWindowClosedMsg
Definition: glDisplay.h:167
GLXContext mContextGL
Definition: glDisplay.h:164
uint32_t GetHeight() const
Get the height of the window (in pixels)
Definition: glDisplay.h:131
void RenderOnce(float *image, uint32_t width, uint32_t height, float x=5.0f, float y=30.0f, bool normalize=true)
Begin the frame, render one CUDA float4 image using OpenGL interop, and end the frame.
bool mWindowClosed
Definition: glDisplay.h:166
bool IsClosed() const
Returns true if the window has been closed.
Definition: glDisplay.h:116
uint32_t GetWidth() const
Get the width of the window (in pixels)
Definition: glDisplay.h:126
void onEvent(uint msg, int a, int b)
UI event handler.
void BeginRender(bool userEvents=true)
Clear window and begin rendering a frame.
float mAvgTime
Definition: glDisplay.h:173
void SetBackgroundColor(float r, float g, float b, float a)
Set the background color.
Definition: glDisplay.h:145
XVisualInfo * mVisualX
Definition: glDisplay.h:162
OpenGL display window / video viewer.
Definition: glDisplay.h:37
static glDisplay * Create(float r=0.05f, float g=0.05f, float b=0.05f, float a=1.0f)
Create a new maximized openGL display window.
static const int screenIdx
Definition: glDisplay.h:158
Display * mDisplayX
Definition: glDisplay.h:160
bool initGL()
uint32_t mWidth
Definition: glDisplay.h:169
float GetFPS() const
Get the average frame time (in milliseconds).
Definition: glDisplay.h:121
~glDisplay()
Destroy window.
void SetTitle(const char *str)
Set the window title string.
void UserEvents()
Process UI events.
OpenGL texture with CUDA interoperability.
Definition: glTexture.h:35
void Render(glTexture *texture, float x=5.0f, float y=30.0f)
Render an OpenGL texture.
glTexture * mInteropTex
Definition: glDisplay.h:165
uint32_t mHeight
Definition: glDisplay.h:170
void EndRender()
Finish rendering and refresh / flip the backbuffer.