HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Render.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_Render.h ( RE Library, C++)
7  */
8 
9 #ifndef __RE_Render__
10 #define __RE_Render__
11 
12 /*****************************************************************************
13 
14 DESCRIPTION:
15 
16 RE_Render is a switcher for platform-dependent renderers. Code using
17 RE_Render should therefore be platform-independent.
18 
19 *****************************************************************************/
20 
21 #include "RE_API.h"
22 #include <SYS/SYS_Floor.h>
23 #include <SYS/SYS_Math.h>
24 #include <UT/UT_Unicode.h>
25 #include "RE_OGLRender.h"
26 
27 class QWidget;
28 
30 {
31 public:
32  RE_Render(int do_foreground, const char *appname = 0);
33  ~RE_Render() override;
34 
35  static void setMainRender(RE_Render * main);
36  static RE_Render * getMainRender();
37  static bool isMainRenderInitialized();
38 
39  // The list of OpenGL render contexts that are currently available
40  static int getNumRenderContexts();
41  static RE_Render *getRenderContext(int index);
42 
43  static RE_Render *findRenderWithID(int id);
44  static RE_Render *findRenderWithContext(RE_OGLContext context);
45 
46 
47  // Control whether or not to allow adaptive subdivision in the viewport.
48  static bool getAllowAdaptiveSubd();
49  static void setAllowAdaptiveSubd(bool allow);
50 
51  // High DPI mode upscales some elements.
52  static bool isHighDPIMode();
53 
54  // Creates a new OpenGL context using the same drawable as this context.
55  // The returned object is ownerd by getCurrentWindow()
56  RE_Render *createNewRenderContext();
57 
58  // Creates a new OpenGL context using a new offscreen window. Delete the
59  // created window to free the render when finished.
60  static RE_Render *createNewOffscreenContext(UT_UniquePtr<RE_Window> &win);
61 
62 private:
63  static RE_Render * theMainRender;
64 };
65 
66 
67 RE_API extern RE_Render *REgetRender();
70 
71 // Inches are an arbitrary unit that get translated into pixels based on the
72 // current DPI setting of the server (which in turn is modified by the
73 // HOUDINI_UISCALE env variable). Inches scale with the DPI.
74 
75 inline int REtoPixels(fpreal inches)
76 {
77  return RE_OGLRender::inchesToPixels(inches);
78 }
79 
81 {
82  return RE_OGLRender::pixelsToInches(pixels);
83 }
84 
85 // When using pixels, absolute pixel values do not scale with the DPI, they
86 // always assume a DPI of 85. These methds will scale a pixel length using the
87 // current DPI to 85dpi ratio.
88 
89 inline int REtoScaledPixels(int pixels)
90 {
91  if(pixels != 0)
92  {
93  return SYSmax(1, (int) SYSrint(pixels *
95  }
96  return 0;
97 }
98 inline int REfromScaledPixels(int pixels)
99 {
100  return (int) SYSrint(pixels * (RE_DEFAULT_DPI/RE_OGLRender::dpi()));
101 }
102 
103 RE_API extern fpreal REgetScreenToDeviceScale(int screen=-1);
104 
105 #endif // __RE_Render__
#define SYSmax(a, b)
Definition: SYS_Math.h:1570
RE_Render * REgetMainRender()
Definition: RE_Render.h:68
static int inchesToPixels(float i)
#define RE_API
Definition: RE_API.h:10
int REtoPixels(fpreal inches)
Definition: RE_Render.h:75
int REtoScaledPixels(int pixels)
Definition: RE_Render.h:89
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition: glcorearb.h:108
fpreal REtoInches(int pixels)
Definition: RE_Render.h:80
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define RE_DEFAULT_DPI
Definition: RE_Types.h:421
RE_API fpreal REgetScreenToDeviceScale(int screen=-1)
fpreal32 SYSrint(fpreal32 val)
Definition: SYS_Floor.h:163
static bool isMainRenderInitialized()
fpreal64 fpreal
Definition: SYS_Types.h:277
RE_API RE_Render * REgetRender()
GLuint index
Definition: glcorearb.h:786
int REfromScaledPixels(int pixels)
Definition: RE_Render.h:98
static float pixelsToInches(int n)
static int dpi()
bool REisMainRenderInitialized()
Definition: RE_Render.h:69
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:952
static RE_Render * getMainRender()