NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CommonControls.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 #include "gui/Window.hpp"
30 #include "base/Timer.hpp"
31 #include "base/Array.hpp"
32 #include "base/Hash.hpp"
33 
34 namespace FW
35 {
36 //------------------------------------------------------------------------
37 
38 class StateDump;
39 
40 //------------------------------------------------------------------------
41 
43 {
44 public:
45 
46  //------------------------------------------------------------------------
47 
48  enum Feature
49  {
59 
61  Feature_All = (1 << 9) - 1,
63  };
64 
65  //------------------------------------------------------------------------
66 
68  {
69  public:
70  StateObject (void) {}
71  virtual ~StateObject (void) {}
72 
73  virtual void readState (StateDump& d) = 0;
74  virtual void writeState (StateDump& d) const = 0;
75  };
76 
77 private:
78  struct Key;
79 
80  //------------------------------------------------------------------------
81 
82  struct Message
83  {
84  String string;
85  String volatileID;
86  F32 highlightTime;
87  U32 abgr;
88  };
89 
90  //------------------------------------------------------------------------
91 
92  struct Toggle
93  {
94  bool* boolTarget;
95  S32* enumTarget;
96  S32 enumValue;
97  bool* dirtyNotify;
98 
99  bool isButton;
100  bool isSeparator;
101  Key* key;
102  String title;
103  F32 highlightTime;
104 
105  bool visible;
106  Vec2f pos;
107  Vec2f size;
108  };
109 
110  //------------------------------------------------------------------------
111 
112  struct Slider
113  {
114  F32* floatTarget;
115  S32* intTarget;
116  bool* dirtyNotify;
117 
118  F32 slack;
119  F32 minValue;
120  F32 maxValue;
121  bool isExponential;
122  Key* increaseKey;
123  Key* decreaseKey;
124  String format;
125  F32 speed;
126  F32 highlightTime;
127 
128  bool visible;
129  bool stackWithPrevious;
130  Vec2f pos;
131  Vec2f size;
132  Vec2f blockPos;
133  Vec2f blockSize;
134  };
135 
136  //------------------------------------------------------------------------
137 
138  struct Key
139  {
140  String id;
141  Array<Toggle*> toggles;
142  Array<Slider*> sliderIncrease;
143  Array<Slider*> sliderDecrease;
144  };
145 
146  //------------------------------------------------------------------------
147 
148 public:
149  CommonControls (U32 features = Feature_Default);
150  virtual ~CommonControls (void);
151 
152  virtual bool handleEvent (const Window::Event& ev);
153 
154  void message (const String& str, const String& volatileID = "", U32 abgr = 0xffffffffu);
155 
156  void addToggle (bool* target, const String& key, const String& title, bool* dirtyNotify = NULL) { FW_ASSERT(target); addToggle(target, NULL, 0, false, key, title, dirtyNotify); }
157  void addToggle (S32* target, S32 value, const String& key, const String& title, bool* dirtyNotify = NULL) { FW_ASSERT(target); addToggle(NULL, target, value, false, key, title, dirtyNotify); }
158  void addButton (bool* target, const String& key, const String& title, bool* dirtyNotify = NULL) { FW_ASSERT(target); addToggle(target, NULL, 0, true, key, title, dirtyNotify); }
159  void addButton (S32* target, S32 value, const String& key, const String& title, bool* dirtyNotify = NULL) { FW_ASSERT(target); addToggle(NULL, target, value, true, key, title, dirtyNotify); }
160  void addSeparator (void) { addToggle(NULL, NULL, 0, false, "", "", NULL); }
161  void setControlVisibility(bool visible) { m_controlVisibility = visible; } // applies to next addXxx()
162 
163  void addSlider (F32* target, F32 minValue, F32 maxValue, bool isExponential, const String& increaseKey, const String& decreaseKey, const String& format, F32 speed = 0.25f, bool* dirtyNotify = NULL) { addSlider(target, NULL, minValue, maxValue, isExponential, increaseKey, decreaseKey, format, speed, dirtyNotify); }
164  void addSlider (S32* target, S32 minValue, S32 maxValue, bool isExponential, const String& increaseKey, const String& decreaseKey, const String& format, F32 speed = 0.0f, bool* dirtyNotify = NULL) { addSlider(NULL, target, (F32)minValue, (F32)maxValue, isExponential, increaseKey, decreaseKey, format, speed, dirtyNotify); }
165  void beginSliderStack (void) { m_sliderStackBegun = true; m_sliderStackEmpty = true; }
166  void endSliderStack (void) { m_sliderStackBegun = false; }
167 
168  void removeControl (const void* target);
169  void resetControls (void);
170 
171  void setStateFilePrefix (const String& prefix) { m_stateFilePrefix = prefix; }
172  void setScreenshotFilePrefix(const String& prefix) { m_screenshotFilePrefix = prefix; }
173  String getStateFileName (int idx) const { return sprintf("%s%03d.dat", m_stateFilePrefix.getPtr(), idx); }
174  String getScreenshotFileName(void) const;
175 
176  void addStateObject (StateObject* obj) { if (obj && !m_stateObjs.contains(obj)) m_stateObjs.add(obj); }
177  void removeStateObject (StateObject* obj) { m_stateObjs.removeItem(obj); }
178  bool loadState (const String& fileName);
179  bool saveState (const String& fileName);
180  bool loadStateDialog (void);
181  bool saveStateDialog (void);
182 
183  void showControls (bool show) { m_showControls = show; }
184  void showFPS (bool show) { m_showFPS = show; }
185  bool getShowControls (void) const { return m_showControls; }
186  bool getShowFPS (void) const { return m_showFPS; }
187 
188  F32 getKeyBoost (void) const;
189  void flashButtonTitles (void);
190 
191 private:
192  bool hasFeature (Feature feature) { return ((m_features & feature) != 0); }
193  void render (GLContext* gl);
194 
195  void addToggle (bool* boolTarget, S32* enumTarget, S32 enumValue, bool isButton, const String& key, const String& title, bool* dirtyNotify);
196  void addSlider (F32* floatTarget, S32* intTarget, F32 minValue, F32 maxValue, bool isExponential, const String& increaseKey, const String& decreaseKey, const String& format, F32 speed, bool* dirtyNotify);
197  Key* getKey (const String& id);
198 
199  void layout (const Vec2f& viewSize, F32 fontHeight);
200  void clearActive (void);
201  void updateActive (const Vec2f& mousePos);
202  F32 updateHighlightFade (F32* highlightTime);
203  U32 fadeABGR (U32 abgr, F32 fade);
204 
205  static void selectToggle (Toggle* t);
206 
207  F32 getSliderY (const Slider* s, bool applySlack) const;
208  void setSliderY (Slider* s, F32 y);
209  static F32 getSliderValue (const Slider* s, bool applySlack);
210  static void setSliderValue (Slider* s, F32 v);
211  static String getSliderLabel (const Slider* s);
212  static void sliderKeyDown (Slider* s, int dir);
213  void enterSliderValue (Slider* s);
214 
215  static void drawPanel (GLContext* gl, const Vec2f& pos, const Vec2f& size, U32 interiorABGR, U32 topLeftABGR, U32 bottomRightABGR);
216 
217 private:
218  CommonControls (const CommonControls&); // forbidden
219  CommonControls& operator= (const CommonControls&); // forbidden
220 
221 private:
222  const U32 m_features;
223  Window* m_window;
224  Timer m_timer;
225 
226  bool m_showControls;
227  bool m_showFPS;
228  String m_stateFilePrefix;
229  String m_screenshotFilePrefix;
230 
231  Array<Message> m_messages;
232  Array<Toggle*> m_toggles;
233  Array<Slider*> m_sliders;
234  Array<StateObject*> m_stateObjs;
235  Hash<String, Key*> m_keyHash;
236 
237  bool m_sliderStackBegun;
238  bool m_sliderStackEmpty;
239  bool m_controlVisibility;
240 
241  Vec2f m_viewSize;
242  F32 m_fontHeight;
243  F32 m_rightX;
244 
245  S32 m_activeSlider;
246  S32 m_activeToggle;
247  bool m_dragging;
248  F32 m_avgFrameTime;
249  bool m_screenshot;
250 };
251 
252 //------------------------------------------------------------------------
253 }
bool getShowControls(void) const
bool saveStateDialog(void)
void addStateObject(StateObject *obj)
#define NULL
Definition: Defs.hpp:39
const char * getPtr(void) const
Definition: String.hpp:51
virtual ~CommonControls(void)
void showControls(bool show)
bool loadStateDialog(void)
void addToggle(bool *target, const String &key, const String &title, bool *dirtyNotify=NULL)
void addSlider(S32 *target, S32 minValue, S32 maxValue, bool isExponential, const String &increaseKey, const String &decreaseKey, const String &format, F32 speed=0.0f, bool *dirtyNotify=NULL)
void setStateFilePrefix(const String &prefix)
void beginSliderStack(void)
void addSlider(F32 *target, F32 minValue, F32 maxValue, bool isExponential, const String &increaseKey, const String &decreaseKey, const String &format, F32 speed=0.25f, bool *dirtyNotify=NULL)
bool getShowFPS(void) const
CommonControls(U32 features=Feature_Default)
F32 getKeyBoost(void) const
void removeStateObject(StateObject *obj)
bool loadState(const String &fileName)
virtual void readState(StateDump &d)=0
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum target
Definition: DLLImports.inl:315
virtual void writeState(StateDump &d) const =0
String getScreenshotFileName(void) const
float F32
Definition: Defs.hpp:89
void setScreenshotFilePrefix(const String &prefix)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat y
Definition: DLLImports.inl:363
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v
Definition: DLLImports.inl:329
void setControlVisibility(bool visible)
#define FW_ASSERT(X)
Definition: Defs.hpp:67
signed int S32
Definition: Defs.hpp:88
void addToggle(S32 *target, S32 value, const String &key, const String &title, bool *dirtyNotify=NULL)
String sprintf(const char *fmt,...)
Definition: Defs.cpp:241
void addButton(S32 *target, S32 value, const String &key, const String &title, bool *dirtyNotify=NULL)
unsigned int U32
Definition: Defs.hpp:85
void addButton(bool *target, const String &key, const String &title, bool *dirtyNotify=NULL)
String getStateFileName(int idx) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction f
Definition: DLLImports.inl:88
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value
Definition: DLLImports.inl:84
void showFPS(bool show)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: DLLImports.inl:349
void flashButtonTitles(void)
virtual bool handleEvent(const Window::Event &ev)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr size
Definition: DLLImports.inl:319
void removeControl(const void *target)
bool saveState(const String &fileName)
void message(const String &str, const String &volatileID="", U32 abgr=0xffffffffu)