HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_OGLRender.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_OGLRender.h ( RE Library, C++)
7  *
8  * COMMENTS:
9  * Interface class for Open GL. Comamnds are grouped, in this order,
10  * under these tags:
11  *
12  * - RENDERING ENVIRONMENT (gl version, extensions, driver)
13  * - MONITOR SCREEN (monitor setup)
14  * - DISPLAY MODE & WINDOWS (windows, visuals)
15  * - ERROR REPORTING (gl errors)
16  * - FRAMEBUFFER OBJECTS
17  * - BUFFER CONTROL
18  * - FRUSTUM & CLIPPING
19  * - TRANSFORMATION
20  * - COLOR
21  * - LINE & POINT STYLES
22  * - STENCIL, LOGIC & DEPTH
23  * - BLENDING & SMOOTHING
24  * - DISPLAY LISTS
25  * - MATERIALS
26  * - GLSL SHADERS
27  * - TEXTURING
28  * - LIGHTING & SHADING
29  * - PICKING
30  * - RASTER OPERATIONS
31  * - SIMPLE PRIMITIVES (rect, circles, arcs)
32  * - FONT RENDERING
33  * - SURFACES (nurbs)
34  * - OBSOLETE DRAWING METHODS (begin/end stuff, vertex calls)
35  */
36 #ifndef __RE_OGLRender__
37 #define __RE_OGLRender__
38 
39 #include "RE_API.h"
40 
41 #include <SYS/SYS_Floor.h>
42 #include <SYS/SYS_Types.h>
43 
44 #include <UT/UT_Array.h>
45 #include <UT/UT_Assert.h>
46 #include <UT/UT_Color.h>
47 #include <UT/UT_IntArray.h>
48 #include <UT/UT_ArrayMap.h>
49 #include <UT/UT_Pixel.h>
50 #include <UT/UT_Rect.h>
51 #include <UT/UT_SpinLock.h>
52 #include <UT/UT_Thread.h>
54 #include <UT/UT_Vector2.h>
55 #include <UT/UT_VectorTypes.h>
56 
57 #include <PXL/PXL_Common.h>
58 
59 #include "RE_Extension.h"
60 #include "RE_Material.h"
61 #include "RE_OGL.h"
62 #include "RE_OGLExt.h"
63 #include "RE_OGLState.h"
64 #include "RE_RenderFlush.h"
65 #include "RE_Texture.h"
66 #include "RE_TextureTypes.h"
67 #include "RE_Uniform.h"
68 
69 #include <utility>
70 
71 template <typename ITEM_T> class UT_StringMap;
72 class UT_WorkBuffer;
73 class UT_StopWatch;
74 class UT_StringHolder;
75 class IMG_Raster;
76 class TIL_Raster;
77 class PXL_Raster;
78 class PXL_Lookup;
79 
80 class RE_Cursor;
82 class RE_FontBuffers;
83 class RE_Geometry;
84 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
85 class RE_GLDrawable;
86 #endif
87 class RE_OcclusionQuery;
88 class RE_OGLFramebuffer;
89 class RE_OGLTexture;
92 class RE_Render;
93 class RE_Server;
94 class RE_Shader;
95 class RE_ShaderHandle;
96 class RE_Visual;
97 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
98 class RE_Window;
99 class RE_WindowList;
100 #endif
101 
102 #define OPEN_GL
103 
104 // These values are the keys in the table returned by getDriverInfoDict().
105 #define RE_DRIVER_INFO_VENDOR "OpenGL Vendor"
106 #define RE_DRIVER_INFO_RENDERER "OpenGL Renderer"
107 #define RE_DRIVER_INFO_VERSION "OpenGL Version"
108 #define RE_DRIVER_INFO_SHADING_LANGUAGE "OpenGL Shading Language"
109 #define RE_DRIVER_INFO_DETECTED "Detected"
110 
111 // --------------------------------------------------------------------------
112 
114 {
115 public:
116  ~RE_OGLRender() override;
117 
118  const char *className() const;
119  int getContextID() const { return myUniqueID; }
120 
121  static void initialize();
122  bool isInitialized() const { return !firstInitialize; }
123 
124  // For RE_OGLRender methods to pass an RE_Render * to various objects
126  { return reinterpret_cast<RE_Render*>(this); }
127  const RE_Render *getRender() const
128  { return reinterpret_cast<const RE_Render*>(this); }
129 
130  // RENDERING ENVIRONMENT ------------------------------------------------
131  // You can use these methods to query support for a specific OpenGL
132  // version on the machine Houdini is running on.
133  static bool hasGL11();
134  static bool hasGL12();
135  static bool hasGL13();
136  static bool hasGL14();
137  static bool hasGL15();
138  static bool hasGL20();
139  static bool hasGL21();
140 
141  static bool hasGL3(int minor);
142  static bool hasGL4(int minor);
143 
144  static int glMajorVersion();
145  static int glMinorVersion();
146 
147  // Determines the version of GLSL. Currently it's either 1.xx or 0.0 (unsup)
148  int glslMajorVersion(); // 1
149  int glslMinorVersion(); // 0, 10, 20, 30, 40 or 50
150  int glslMaxOutputComponents(RE_ShaderType stage);
151  int glslMaxUniformComponents(RE_ShaderType stage);
152 
153  bool hasGLExtension(RE_Extension e) const;
154 
155  // Low-level hardware and driver verisons. Use these only to work
156  // around driver issues. All other features should use the GL version,
157  // or RE_OGLExt.
158 
159  // Returns the hardware doing the rendering.
160  static RE_GraphicsDevice getGraphicsDevice();
161 
162  // By default, we early exit without OpenGL 3.3, use this to disable
163  // for just querying GL info.
164  static void setPerformBadDriverCheck(bool onoff);
165 
166  // The driver version. NVidia uses XX.XX, while ATI uses X.XX.XX
167  static bool hasDriverVersion();
168  static int getDriverMajorVersion();
169  static int getDriverMinorVersion();
170  static int getDriverBuildMajorVersion();
171  static int getDriverBuildMinorVersion();
172  static void getDriverInfo(UT_WorkBuffer &info);
173  static const UT_StringMap<UT_StringHolder> &getDriverInfoDict();
174  static bool getUsingCoreProfile();
175  static void setUsingCoreProfile(bool using_core_profile);
176 
177  // Access to the RE_OGLExt methods. Should not be used outside of RE; use
178  // hasGLExtension() instead.
179  RE_OGLExt *getExt() const;
180 
181  // clear out all VBOs and textures in the graphics cache.
182  static void clearGraphicsCache();
183 
184  // Queries to return the total free memory, and optionally the largest
185  // available chunk of memory on the GPU. Extension RE_EXT_MEMORY_QUERY
186  // is required.
187  int64 getFreeTextureMemoryKB(int64 *largest_chunk = nullptr);
188  int64 getFreeBufferMemoryKB(int64 *largest_chunk = nullptr);
189  int64 getFreeFramebufferMemoryKB(int64 *largest_chunk = nullptr);
190 
191  // Returns the amount of free memory on the GPU when Houdini first started.
192  static int64 getInitialFreeMemoryKB();
193 
194  // Call in the case of a fatal startup error due to insufficient driver
195  // support.
196  static void exitWithBadDriver();
197 
198  // MONITOR SCREEN ---------------------------------------------------------
199 
200  static int resX();
201  static int resY();
202 
203  static void updateScreenSize();
204 
205  // Multi-monitor support. Primary monitor is screen 0.
206  //
207  // returns true if all the screens are the same size
208  static bool areScreensUniform();
209  // returns a work area for the screen(s) occupied by 'area', for use when
210  // multiple screens aren't uniform in size.
211  static UT_DimRect getWorkAreaForScreen(UT_DimRect area);
212 
213  // this method positions rect entirely on one screen, shifting if
214  // required. If screen_hint is not -1, the screen containing that
215  // coord will be used. It returns the screen chosen.
216  //
217  static int positionOnScreen(UT_DimRect &area,
218  int screen_hint=-1);
219 
220  // returns true if the area fits entirely within one of the work areas.
221  static bool positionOkay(const UT_DimRect &area);
222 
223  static int dpi(); // system dpi * UI scale
224  static fpreal uiScale(); // UI scale factor (HOUDINI_UISCALE)
225  static void scaleUI(fpreal scale);
226  static float pixelsToInches(int n);
227  static int inchesToPixels(float i);
228  static int scaledSize(int size);
229  static fpreal scaledSize(fpreal size);
230 
231  // does a quick check to determine if the computer entered a suspend (sleep)
232  // mode, where many GPU computed textures and buffers will need to be
233  // recomputed.
234  void checkForSuspendResume();
235  static void addSuspendResumeCB(void (*cb)(void*), void *data);
236  static void removeSuspendResumeCB(void (*cb)(void*), void *data);
237 
238 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
239  // DISPLAY MODE & WINDOWS ----------------------------------------------
240 #else
241  // DISPLAY MODE ----------------------------------------------
242 #endif
243 
244  RE_DisplayMode getMode() const;
245 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
246  RE_VisualType getVisualType() const;
247 #endif
248 
249  void enableMultisample(bool enable);
250  bool isMultisampleEnabled() const;
251 
252  void enableAlphaToCoverage(bool enable);
253  bool isAlphaToCoverage() const;
254 
255  void getMaxViewportSize(int &w, int &h) const;
256  int getMaxColorSamples() const;
257  int getMaxDepthSamples() const;
258 
259  static RE_Visual *getVisualForMode(RE_DisplayMode newmode);
260  static RE_Server *getServer();
261  static RE_Cursor *getCursor(const char *name);
262 
263 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
264  void setWindow(RE_Window *, bool attach = true);
265 #else
266  void setDrawable(RE_GLDrawable *drawable, bool attach=true);
267 #endif
268 
269  bool makeCurrent(bool ignore_errors = false);
270  bool makeCurrentQt();
271  bool isCurrent() const
272  { return theCurrentRender.get() == this; }
273  static void resetCurrent();
274  bool contextIsValid() const { return (bool)myContext; }
275  RE_OGLContext getContext() const { return myContext; }
276 
277  // When using Pbuffers instead of FBOs, we have to set them up as the
278  // render target. You cannot push more than 1 buffer at a time.
279  bool pushOffscreenBuffer(OGLDrawable type);
280  void popOffscreenBuffer();
281 
282 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
283  // This is the context of the main window, which should persist always.
284  void setMainContext(RE_Window *w);
285  static RE_Window *getMainContext();
286 #endif
287 
288  static RE_OGLRender *getCurrentRender();
289 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
290  static RE_WindowList *getWindowList();
291  const RE_Window *getCurrentWindow() const;
292  RE_Window *getCurrentWindow();
293 #else
294  const RE_GLDrawable *getCurrentDrawable() const;
295  RE_GLDrawable *getCurrentDrawable();
296 #endif
297 
298  // These methods prepares for another thread to access OpenGL.
299  // They are called from the same thread that will be accessing OpenGL.
300  // If they're called from the main thread, they do nothing.
301  //
302  // These methods work by giving each thread its own OpenGL context.
303  // Because other threads do not know when the main thread changes the
304  // OpenGL context or drawable, they must call the prepare...() method
305  // to explicitly set their context, before they main RE/OGL calls.
306  //
307  // These methods do not provide support for concurrent access to RE
308  // from multiple threads: only one thread at a time may make RE calls.
309  // The main thread must be blocked while the other thread makes the
310  // calls. That other thread must call lock...() while the main thread
311  // is blocked, make its RE calls, call unlock...(), and only then may it
312  // unblock the main thread.
313  //
314  // These methods are called by HOMF_HOMGLAutoLock so HOMF methods can
315  // call code that eventually makes OpenGL calls, even when the Python
316  // interpreter is running in a separate thread.
317  void lockContextForRender();
318  void unlockContextAfterRender();
319  bool tryLockContextForRender();
320  bool isContextLocked() const;
321 
322  void bumpRenderCount() { myRenderCount ++; }
323  void resetRenderCount() { myRenderCount = 0; }
324  int64 getRenderCount() const { return myRenderCount; }
325 
326  // ERROR REPORTING --------------------------------------------------
327  int getGLError();
328  int getNextGLError();
329  void clearGLErrors();
330  const char *getGLErrorString( int error );
331  void printGLError(const char *header,
332  bool assert = false );
333  void printAllGLErrors( const char *header,
334  bool assert = false );
335 
336  void dumpNewState(bool show_all = false,
337  bool show_shader_blocks = true);
338  void dumpViewportState(bool show_all = false);
339  void dumpTextureState() const;
340  void dumpVertexAttributes() const;
341  void dumpFragmentTests(bool show_all = false) const;
342  void dumpRasterizeState(bool show_all = false) const;
343  void dumpTextureCacheState(int stack_level =-1) const;
344 
345  void getLimits(UT_WorkBuffer &os);
346 
347  // RE_EXT_DEBUG_OUTPUT2 (GL_KHR_debug) required with env HOUDINI_OGL_DEBUG>0
348  bool isDebugLabelSupported() const;
349 
350  // HOUDINI_OGL_DEBUG > 0 and RE_EXT_DEBUG_OUTPUT2 is supported.
351  bool isDebugging() const;
352 
353  int pushDebug(bool enable);
354  void popDebug(int *nest = nullptr);
355 
356  int pushDebugGroup(const char *name, int id=1987);
357  void popDebugGroup(int *nest = nullptr);
358 
359  void addComment(const char *name,
361  int id =1987);
362 
363 
364  // FRAMEBUFFER OBJECTS -------------------------------------------------
365 
366  // There are two bindings for framebuffers, read and draw. If
367  // RE_EXT_FRAME_BUFFER_OBJECT_ARB is not supported, these will be the same.
368  int pushDrawFramebuffer(); // no change to FBO state
369  int pushDrawFramebuffer(RE_OGLFramebuffer *fb);
370  void setDrawFramebuffer(RE_OGLFramebuffer *fb);
371  RE_OGLFramebuffer *getDrawFramebuffer();
372  void popDrawFramebuffer(int *nest = nullptr);
373 
374  int pushReadFramebuffer(); // no change to FBO state
375  int pushReadFramebuffer(RE_OGLFramebuffer *fb);
376  void setReadFramebuffer(RE_OGLFramebuffer *fb);
377  RE_OGLFramebuffer *getReadFramebuffer();
378  void popReadFramebuffer(int *nest = nullptr);
379 
380  void updateFramebuffer();
381  // Only called by RE_OGLFramebuffer; updates the current FBO state.
382  void updateCurrentFramebuffer(RE_OGLFramebuffer *fb,
383  bool for_draw);
384 
385  void registerFBO(RE_OGLFramebuffer *fb, int fb_id);
386  void unregisterFBO(int id);
387  RE_OGLFramebuffer *getFBO(int id) const;
388 
389  // Sample state
390  void useSampleMask(bool use);
391  bool usingSampleMask() const;
392  int getMaxIntegerSamples() const;
393  int getSampleMask(int mask_number);
394  void setSampleMask(int mask_number, int mask);
395  static int getMatteMaskForSampleCount(int samples);
396 
397  // BUFFER CONTROL -------------------------------------------------------
398 
399  // If possible, call clearCZ() instead of clear() followed by clearZ(),
400  // since a single clearCZ() is much faster on all post-Indy machines.
401  void clearC(float *color = nullptr);
402  void clearZ(float z = 1.0);
403  void clearCZ(float z = 1.0);
404  void clearS();
405 
406  // Using these methods, you can disable updates to the colour and/or depth
407  // bits of the frame buffer. Be careful with these, since the associated
408  // calculations will still be performed (eg. even if color buffer updates
409  // are disabled, useless lighting calculations are still done if
410  // GL_LIGHTING is enabled). Same with GL_DEPTH_TEST. So you can easily
411  // write inefficient code.
412  void enableColorBufferWriting();
413  void disableColorBufferWriting();
414  bool getColorBufferWriting();
415  void updateColorBufferWriting();
416 
417  void setColorMask(bool red, bool green, bool blue, bool alpha);
418  void getColorMask(bool &red, bool &green, bool &blue, bool &alpha);
419 
420  bool swapbuffers();
421 
422  // By default, the buffer is not changed (RE_BUFFER_UNINIT)
423  int pushDrawBuffer( RE_RenderBuf buf = RE_BUFFER_UNINIT);
424  void popDrawBuffer(int *nest = 0);
425  void setDrawBuffer( RE_RenderBuf buf );
426  RE_RenderBuf getDrawBuffer();
427  bool getDrawBufferIsBlendable();
428 
429  int pushReadBuffer( RE_RenderBuf buf = RE_BUFFER_UNINIT);
430  void popReadBuffer(int *nest = 0);
431  void setReadBuffer( RE_RenderBuf buf );
432  RE_RenderBuf getReadBuffer();
433 
434  // set by the current window, UI_Window::setContext(). returns if the
435  // front buffer has been written to since last swap (for marquee drawing)
436  //
437  bool isFrontBufferDirty() const;
438  void setFrontBufferDirty(bool d);
439 
440  void flush(int wait=0);
441 
442  /// Ensure all writes are complete to the specified resource(s).
443  /// GL4.2, RE_EXT_BUFFER_STORE or RE_EXT_SHADER_LOAD_STORE must be
444  /// supported, or this will return false, doing nothing.
445  bool memoryBarrier(RE_MemoryBarrierBitfield barriers);
446 
447  // FRUSTUM & CLIPPING ------------------------------------------------
448 
449  // masked rendering (scissor)
450  void viewport2DI(const UT_DimRect &rect);
451  void screenMask2DI(const UT_DimRect &rect);
452  void disableScreenMask();
453  void intersectMask2DI(const UT_DimRect &rect);
454  UT_DimRect getScreenMask2DI();
455  UT_DimRect getViewport2DI();
456  bool getScreenMask();
457 
458  // Clip distance enables
459  int getOGLMaxClipPlanes();
460  void enableClipDistance(int clip_plane, bool enable);
461  bool clipDistanceEnabled(int clip_plane) const;
462 
463  // Active Occlusion query (only 1 active at a time)
464  void setActiveOcclusionQuery(RE_OcclusionQuery *q);
465  RE_OcclusionQuery *getActiveOcclusionQuery() const;
466 
467  // Backface culling
468  int pushBackfaceCulling();
469  int pushBackfaceCulling(bool backface);
470  void popBackfaceCulling(int *nested = 0);
471 
472  bool isBackface() const;
473  void setBackface(bool removeBackface);
474  bool getReverseWinding();
475  void setReverseWinding(bool reverse_winding);
476  RE_FaceMode getCullFace() const;
477  void setCullFace(RE_FaceMode m);
478 
479  // polygon/line offset
480  bool isPointOffset();
481  bool isLineOffset();
482  bool isPolygonOffset();
483  void pointOffset( bool onoff );
484  void lineOffset( bool onoff );
485  void polygonOffset( bool onoff );
486  void setOffsetAmount( float variable, float constant );
487  void getOffsetAmount(float *variable, float *constant) const;
488 
489 
490 
491  // Start collecting vertex/geometry shader attribute output into buffers.
492  // There must be a shader active, and this shader must have one or more
493  // transform feedback buffers enabled. 'mode' must be one of RE_PRIM_POINTS,
494  // RE_PRIM_LINES, or RE_PRIM_TRIANGLES, and only those types can be
495  // rendered. 'rasterize_too' controls whether primitives continue on to the
496  // fragment shader to be rasterized or stop at the transform feedback stage.
497  // 'stream_bitfield' allows multiple vertex streams to be captured when GL4
498  // is present (bit N = vertex stream N).
499  bool beginTransformFeedback(RE_PrimType mode,
500  bool rasterize_too,
501  int stream_bitfield = 0x1);
502 
503  // only call end if begin returned true.
504  void endTransformFeedback();
505 
506  // returns the number of primitives collected in the transform feedback
507  // buffers. Must be called after endTransformFeedback().
508  int getNumFeedbackPrimitives(int stream = 0);
509 
510  // Returns true if the feedback buffers overflowed. Must be called after
511  // endTransformFeedback()
512  bool hasFeedbackBufferOverflow(int stream = 0);
513 
514  // Transform feedback state queries.
515  bool isTransformFeedbackEnabled() const;
516  RE_PrimType getFeedbackMode() const;
517  bool isRasterizeEnabled() const;
518 
519  // Line & Point sizes
520  int pushLineWidth(float w);
521  void popLineWidth(int *nest = nullptr);
522  float getLineWidth() const;
523  float getMaxSmoothLineWidth();
524 
525  int pushPointSize(float size, bool program_point_size = false);
526  void popPointSize(int *nest = nullptr);
527  void setPointSize(float size);
528 
529  // If enabled, point size is taken from vertex or geometry shader's
530  // gl_PointSize output
531  void setProgramPointSize(bool enable);
532  bool getProgramPointSize() const;
533 
534  // STENCIL, LOGIC & DEPTH ------------------------------------------------
535 
536  // The depth state consists of the depth test bit, depth compare function
537  // depth clamp, and the depth buffer writemask. Note that pushBlendState()
538  // can affect the depth buffer writemask, so it is important that if they
539  // are nested, the order of the pops is reversed from the pushes.
540  int pushDepthState();
541  void popDepthState(int *nest = nullptr);
542 
543  // In order to enable depth buffer writes, a depth buffer must be present
544  // in the current window or framebuffer.
545  void enableDepthBufferWriting();
546  void disableDepthBufferWriting();
547  bool getDepthBufferWriting();
548  void updateDepthBufferWriting();
549 
550  // Depth testing must be enabled for depth buffer writes to have any effect.
551  void enableDepthTest();
552  void disableDepthTest();
553  bool getDepthTest();
554  void updateDepthTest();
555 
556  // The depth function only has an effect if depth testing is enabled.
557  void setZFunction(RE_ZFunction func);
558  RE_ZFunction getZFunction() const;
559  void updateZFunction() const;
560 
561  // Depth clamping causes objects outside of [near,far] to clamp their Z to
562  // near or far. By default it is off.
563  void enableDepthClamp(bool b);
564  bool getDepthClamp();
565  void updateDepthClamp();
566 
567  void setDepthRange(double nr, double fr);
568  void getDepthRange(double &nr, double &fr) const;
569 
570  // Stencil state
571  int pushStencilState();
572  void popStencilState(int *nest = nullptr);
573  bool isStencil();
574  void setStencil(bool enable);
575  void setSClearValue(int clearValue);
576  void setSWriteMask(int writeMask);
577  void setSFunction(RE_SFunction func, int ref, int mask);
578  void setSOperation(RE_SOperation sfail,
581  void updateStencilState();
582  void resetSFunction();
583  void resetSWriteMask();
584  void resetSClearValue();
585  void resetSOperation();
586 
587  // Logic state
588  void enableLogicOp();
589  void disableLogicOp();
590  void invertPixels();
591  void xorPixels();
592 
593  // BLENDING and SMOOTHING -----------------------------------------------
594  int pushBlendState();
595  void popBlendState(int *nesting = 0);
596 
597  bool isBlending() const;
598  void blend(int onoff);
599  void setBlendFunction(RE_BlendSourceFactor sourceFactor,
600  RE_BlendDestFactor destFactor);
601  bool setAlphaBlendFunction(RE_BlendSourceFactor sourceFactor,
602  RE_BlendDestFactor destFactor,
603  bool force = false);
604  void getBlendFunction(RE_BlendSourceFactor* sourceFactor,
605  RE_BlendDestFactor* destFactor);
606  void getAlphaBlendFunction(RE_BlendSourceFactor *sourceFactor,
607  RE_BlendDestFactor *destFactor);
608  void setBlendEquation(RE_BlendEquation eq);
609  RE_BlendEquation getBlendEquation();
610 
611  // blendAlpha uses (Sa, 1-Sa). blendAlphaPremult uses (1, 1-Sa) (assumes
612  // color is premultiplied)
613  void blendAlpha(int onoff = 1);
614  void blendAlphaPremult(bool onoff = true);
615 
616  int pushSmoothLines();
617  void popSmoothLines(int *nesting = 0);
618  void forceSmooth();
619  void smoothBlendLines(RE_SmoothMode mode);
620  void smoothBlendLinesNoFlagChange(bool by_smooth);
621  RE_SmoothMode getSmoothLines();
622 
623  int getBlendSmoothLevel() const;
624 
625  static void allowSmoothLines(int yn);
626  static int allowsSmoothLines();
627 
628  static int getGLBlendSource(RE_BlendSourceFactor sourceFactor);
629  static int getGLBlendDest(RE_BlendDestFactor destFactor);
630 
631  // MATERIALS -------------------------------------------------------------
632 
633  // The layer here is indexed from 0, while the layers in the GU_Details
634  // are indexed from 1.
635  void setMaterial(const RE_MaterialPtr &mat,
636  int layer=0, bool texture=true,
638  RE_Shader *override_mat_shader = nullptr,
639  bool allow_partial_render = false);
640  int pushMaterial(const RE_MaterialPtr &mat,
641  int layer=0, bool texture=true,
643  RE_Shader *override_mat_shader = nullptr,
644  bool allow_partial_render = false);
645  int pushMaterial();
646  void popMaterial(int *nest = nullptr);
647 
648 
649  // material used as a default material
650  const RE_MaterialPtr &getDefaultMaterial();
651 
652  // GLSL SHADERS ---------------------------------------------------------
653 
654  int pushShader(); // no change to state
655  int pushShader(RE_Shader *s);
656  int pushShader(RE_ShaderHandle &sh);
657 
658  void bindShader(RE_Shader *s);
659  void bindShader(RE_ShaderHandle &sh);
660 
661  RE_Shader *getShader();
662  void popShader(int *nest = nullptr);
663 
664  void updateShader(RE_Shader *s); // only called by RE_Shader.
665 
666  int pushShaderTransformFeedback(RE_Shader *sh,
668  bool rasterize = true,
669  int stream_bitfield = 0x1);
670  int pushShaderTransformFeedback(RE_ShaderHandle &sh,
672  bool rasterize = true,
673  int stream_bitfield = 0x1);
674  void popShaderTransformFeedback(int *nest = nullptr);
675 
676  // When on, the GL shader will never be set back to nullptr by popShader();
677  // however, an RE_Geometry::draw() command when the shader should be nullptr
678  // will enter fixed function mode. This is basically a 'lazy pop' mode.
679  // immediate mode begin/end should not be used with this shading mode.
680  void setShaderOnlyMode(bool enable);
681  void requestFixedFunction();
682 
683  /// Set the tesselation default outer level parameters (with no tess control
684  /// shader) for the tesselator. Requires RE_EXT_TESS_SHADER or GL4.
685  void setPatchOuterLevel(const UT_Vector4F &outer);
686 
687  /// Set the tesselation default inner level parameters (with no tess control
688  /// shader) for the tesselator. Requires RE_EXT_TESS_SHADER or GL4.
689  void setPatchInnerLevel(const UT_Vector2F &inner);
690 
691  /// Set the number of vertices per patch for tesselation. Requires
692  /// RE_EXT_TESS_SHADER or GL4.
693  void setPatchVertices(int num_verts);
694 
695  // for multisampled buffers on GL4+ hardware, the fragment shader can be
696  // run to produce more than one color sample. The rate is a fraction between
697  // 0.0 and 1.0, which will guarentee at least ceil(rate*samples) color
698  // samples are produced in multisampled buffers. Note this can degrade
699  // performance substantially for some heavy fragment shaders.
700  // If RE_EXT_SAMPLE_SHADING is unsupported, this has no effect and
701  // setShaderSampleRate() will return false.
702  bool setShaderSampleRate(fpreal rate);
703  fpreal getShaderSampleRate() const;
704 
705  bool isSampleShading() const;
706 
707  // Assign a new uniform value to built-in uniform. If nullptr is passed,
708  // the value is unchanged but the current value copied to the uniform stack.
709  void pushUniform(RE_UniformBuiltIn bindex,
710  RE_Uniform *var = nullptr);
711  // Assign raw values to a built-in uniform. The array must be at least of
712  // size getUniform(builtin_var_type)->getByteSize().
713  void pushUniformData(RE_UniformBuiltIn bindex,
714  const void *data);
715  void pushUniformInt(RE_UniformBuiltIn bindex, int i);
716  void pushUniformColor(RE_UniformBuiltIn bindex,
717  const UT_Color &clr, fpreal32 alpha = 1.0f);
718  void pushUniformSampler(RE_UniformBuiltIn bindex,
719  RE_Texture *tex);
720  void pushUniformMatrix(RE_UniformBuiltIn bindex,
721  const UT_Matrix4D &mat);
722  void assignUniformData(RE_UniformBuiltIn bindex,
723  const void *data);
724  void assignUniformInt(RE_UniformBuiltIn bindex, int i);
725  void assignUniformSampler(RE_UniformBuiltIn bindex,
726  RE_Texture *tex);
727  void assignUniformColor(RE_UniformBuiltIn bindex,
728  const UT_Color &clr, fpreal32 alpha = 1.0f);
729  void assignUniformMatrix(RE_UniformBuiltIn bindex,
730  const UT_Matrix4D &mat);
731  void popUniform(RE_UniformBuiltIn bindex);
733  { popUniform(bindex); }
734 
735  RE_Uniform *getUniform(RE_UniformBuiltIn builtin_var_type) const;
736 
737  // Prints all builtins that have been assigned, or only those which the
738  // current shader has bound (if bound_only is true).
739  void printBuiltInUniforms(bool bound_only);
740 
741  // Print a single builtin's current value.
742  void printBuiltInUniform(RE_UniformBuiltIn b);
743 
744  // Bind all builtin uniforms to the shader. Returns the # of uniforms bound
745  int bindBuiltInUniforms(RE_Shader *s);
746 
747  // Bind the specified uniform to the shader. returns true if a uniform was
748  // present to bind.
749  bool bindBuiltInUniform(RE_Shader *s,
750  RE_UniformBuiltIn uniform);
751 
753  { return myBuiltInUniformSerial; }
754  void bumpBuiltInUniformSerial() { myBuiltInUniformSerial++; }
755 
756  // Assigns a generic uniform, which will be bound to any shaders with this
757  // name. These will override any uniform values when the shader is bound, or
758  // values on the current shader when the uniform is pushed. The name and
759  // uniform type must match exactly for an override to occur.
760  // If more than one uniform of the same name and type is pushed, the last
761  // one pushed takes precedent. Popping it will restore the previous uniform.
762  void pushUniform(RE_Uniform &uniform);
763  void popUniform(RE_Uniform &uniform);
764 
765 
766  // Push the object matrix and update the object and object-view uniforms.
767  // If inverse_too is true, compute and push the inverse object matrix.
768  void pushObjectMatrix(const UT_Matrix4D &obj,
769  bool inverse_too = false);
770  void popObjectMatrix();
771 
772 
773 
774  // Sets a GLSL hint to compute derivatives - fast = false, nice = true
775  void setFragmentDerivativeHint(bool nicest);
776  bool getFragmentDerivativeHint();
777 
778  // Maximum number of vertex attributes supported for vertex shader input
779  int getMaxVertexAttribs() const { return myMaxVertexAttribs; }
780 
781  // Set a vertex attribute at input 'loc' to 'vsize' constant values.
782  // 'vsize' must be between 1 and 4.
783  void setConstAttribF32(int loc, int vsize, const fpreal32 *data);
784 
785  // Set a vertex attribute to constant values. Downcasts to FP32 in GL call.
786  void setConstAttribF32(int loc, int vsize, const fpreal64 *data);
787 
788  // Set a vertex attribute to constant values. Sets as proper FP64.
789  void setConstAttribF64(int loc, int vsize, const fpreal64 *data);
790 
791  // Set a vertex attribute to constant values.
792  void setConstAttribI32(int loc, int vsize, const int32 *data);
793 
794  // Set a vertex attribute to constant values.
795  void setConstAttribU32(int loc, int vsize, const uint32 *data);
796 
797  // Notify the context that 'list' is now the current VAO.
798  bool setCurrentVAO(RE_OGLVertexArrayList *list);
799 
800  // Query the current VAO.
801  RE_OGLVertexArrayList *getCurrentVAO();
802 
803  // Query the default VAO for this context.
804  RE_OGLVertexArrayList *getDefaultVAO() { return myDefaultVAO; }
805 
806  // Don't call this.
807  void setDefaultVAO(RE_OGLVertexArrayList *vao) { myDefaultVAO = vao;}
808 
809  // Notify the context that 'list' is being deleted, and any referenece
810  // should be cleared.
811  void resetCurrentVAO(RE_OGLVertexArrayList *deleted_list);
812 
813  // Returns a list of the currently bound uniform blocks to this context.
814  UT_IntArray &getBoundUniformBlocks() { return myState.myBoundUniformBlocks;}
815 
816  // TEXTURING -------------------------------------------------------------
817 
818  // Bind the given texture to the specified, or active, texture unit. The
819  // texturing mode can be optionally set at the same time (if not set to
820  // UNKNOWN). If texturing for the texture's type is not enabled on the
821  // texturing unit, it is enabled.
822  void bindTexture(const RE_OGLTexture *tex,
823  int unit = RE_ACTIVE_UNIT,
825  void verifyTextureIsNotBound(RE_OGLTexture *texture);
826 
827  // Bind texture buffer 'id' to 'unit' and return the previously bound
828  // texture at 'unit'. This is only used by low-level RE methods.
829  RE_TextureID bindTextureBuffer(int id, int unit);
830 
831  // Unbind all instances of texture 'tex'. This can be an expensive call.
832  void unbindTexture(const RE_OGLTexture *tex);
833 
834  // Query & set the active texture units. Note these are 0 based,
835  // not GL_TEXTURE0 based.
836  void setActiveTexture(int textureunit);
837  int getActiveTexture() const;
838 
839  // Save the texture state for the specified texture unit, or all of
840  // them (RE_ALL_UNITS). If the entire state is pushed, the active texture
841  // unit is saved as well. RE_ALL_UNITS is relatively expensive, so use
842  // with care. push returns a nesting index which can be passed to pop to
843  // ensure proper nesting of push/pop calls.
844  int pushTextureState(int textureunit = RE_ACTIVE_UNIT);
845  void popTextureState(int *nest = nullptr);
846 
847  // The type and texture object currently bound to the given,
848  // or current (-1), texture unit
849  RE_TextureDimension getBoundTextureType(int texunit = RE_ACTIVE_UNIT) const;
850  const RE_OGLTexture *getBoundTexture(int texunit = RE_ACTIVE_UNIT) const;
851 
852  // Returns the first texture unit with no bound unit, starting the search
853  // at starting_unit. -1 is returned if no free units are available.
854  int findFirstFreeTextureUnit(int starting_unit = 0) const;
855 
856  // Reads in initial values for all the textures.
857  void updateTextureState() const;
858 
859  // Query the maximum number of texture units we support.
861  { return myMaxTextureShaderUnits; }
863  { return myMaxTextureVertexUnits; }
865  { return myMaxTextureGeometryUnits; }
867  { return myMaxTextureFragmentUnits; }
869  { return myMaxTextureAnisotropy; }
870 
871  // Query the maximum size of a texture that is supported (either width or
872  // height)
873  int getMaxTextureSize() const
874  { return myMaxTextureSize; }
876  { return myMaxTexture3DSize; }
878  { return myMaxTextureRectSize; }
879 
880  // Query the maximum number of frame buffer color attachments.
881  int getMaxColorBuffers() const
882  { return myMaxColorBuffers; }
883  // Query the max number of draw buffers.
884  int getMaxDrawBuffers() const
885  { return myMaxDrawBuffers; }
886 
887  // This will disable for all texture units.
888  void disableAllTextures();
889  void removeTextureRefs(RE_OGLTexture *tex);
890 
891  // Bind a texture as an image (requires RE_EXT_IMAGE_LOAD_STORE or GL4.2)
892  bool bindImageTexture(int image_unit,
893  RE_Texture *image,
894  RE_BufferAccess image_access,
895  bool layered,
896  int layer);
897  void unbindImageTexture(int image_unit);
898 
899  //
900 
901  // These methods ensure that the pixel store options are set so that the
902  //
903  int pushReadAlignment(const void *data, int scansize);
904  void popReadAlignment(int *nest = nullptr);
905 
906  int pushWriteAlignment(const void *data, int scansize);
907  void popWriteAlignment(int *nest = nullptr);
908 
909  // Enables seamless cubemap filtering for all cubemaps, if supported.
910  void useSeamlessMaps(bool enable);
911  bool usingSeamlessMaps();
912 
913  // Returns an 8b RGBA 64x64 texture with 0-1 random values in all comps.
914  RE_OGLTexture *getRandomTexture(unsigned int seed, bool interp,
915  int size = 64);
916 
917  // Returns an 8b RGBA size^3 3D texture with 0-1 random values
918  RE_OGLTexture *getRandomTexture3D(unsigned int seed, bool interp,
919  int size = 32);
920  // Returns an 8b RGBA size^2 2D texture array of size 'num_layers'
921  RE_OGLTexture *getRandomTextureArray(unsigned int seed, bool interp,
922  int num_layers, int size = 64 );
923 
924  // returns an int32 single channel texture that returns a random sample
925  // mask. The texture is size x (nsamples+1) in size, with each row having
926  // 'N' bits randomly enabled, where N is the row # (0..nsamples). This can
927  // be used for gl_SampleMask
928  RE_OGLTexture *getRandomSampleMaskTexture(unsigned int seed, int nsamples,
929  int size = 64);
930 
931  // Texture Image drawing ------------------------------------------------
932 
933  // makes a texture out of the raster, and stores the id in the raster.
934  void convertRasterToTexture(PXL_Raster *raster,
935  int convert16bit = 0);
936  void convertLUTToTexture(PXL_Lookup *lookup);
937  bool setupShaderForLUT(RE_Shader *shader,
938  PXL_Lookup *lookup,
939  float gamma,
940  bool add_shader);
941  bool is3DLUTSupported() const;
942 
943  void buildRasterTextureGeometry(
946  fpreal32 u0, fpreal32 v0,
948  RE_Geometry &geo);
949  void displayRasterTexture(float x, float y, float z,
950  const PXL_Raster *raster,
951  const RE_RasterOpts *opts = 0);
952  void displayRasterTexture(float x, float y, float z,
953  float w, float h,
954  const IMG_Raster *raster,
955  const RE_RasterOpts *opts = 0);
956  void displayRasterTexture(float x, float y, float z,
957  int w, int h,
958  UT_RGBA *r, int stride,
959  float zoomx=-1.0f,
960  float zoomy=-1.0f,
961  int dither=1,
962  float alpha_mult=1.0f);
963 
964  // The saveRaster method saves the front buffer to a raster. The
965  // raster should be the same size as the w and h parms. As well,
966  // currently, we only support 8 bit channels in the raster. A zoom of -1
967  // uses the current zoom (default).
968  void saveRaster(int x, int y, int w, int h,
969  IMG_Raster *r, bool use_backbuf = true);
970  TIL_Raster * saveRaster(int x, int y, int w, int h,
971  PXL_DataFormat format, bool alphatoo,
972  bool use_backbuf = true);
973 
974 
975  // The following method is used to align text in the viewport where the
976  // current xform makes attempting to use textMove* impractical for this
977  // purpose.
978  // NOTE: Clipping is performed using the actual raster position (set
979  // through textMove*) and not the offset position.
980  // NOTE: Only works for bitmap fonts, not texture fonts.
981  void setViewportFontOffset(int x, int y);
982  int getViewportFontOffsetX() const;
983  int getViewportFontOffsetY() const;
984 
985  RE_FontBuffers *fetchFontBufferFromPool(int size);
986  void returnFontBufferToPool(RE_FontBuffers *buf);
987 
988  // DRAWING METHODS -------------------------------------------------------
989 
990  // Begin a conditional render based on an occlusion query's samples result.
991  // If the query returns zero samples, all drawing is ignored until
992  // the conditional render is ended. Otherwise, rendering is done as normal.
993  // Conditional rendering cannot be nested.
994  //
995  // 'render_wait' specifies whether the render should wait for the results
996  // of the occlusion query, if they are not available.
997  // 'region_support' allows the conditional render to happen at a fine
998  // grain level, which is implementation specific.
999 
1000  // beginConditionalRender() will return false if the the query_object has
1001  // not be run yet, if a conditional render is already in progress, or if
1002  // RE_EXT_CONDITIONAL_RENDER is not supported. Do not call
1003  // endConditionalRender() in this case.
1004  bool beginConditionalRender(RE_OcclusionQuery *query_obj,
1005  bool render_wait,
1006  bool region_support);
1007  void endConditionalRender();
1008 
1009  // enables a primitive restart index, which begins a new primitive when
1010  // using an element buffer.
1011  void enablePrimitiveRestart(bool enable);
1012  void setPrimitiveRestartIndex(unsigned int index);
1013 
1014  // A few higher level functions for simple tasks rendering to the
1015  // viewport. These encapsulate a lot of boilerplate code.
1016  void drawViewportPoint(const fpreal32 p[3],
1017  fpreal32 size);
1018  void preDrawViewportString(UT_Matrix4D &view,
1019  UT_Matrix4D &proj,
1020  UT_DimRect &viewport);
1021  void drawViewportString(const fpreal32 p[3],
1022  const char *str,
1023  const UT_Color *clr = nullptr,
1024  const UT_Matrix4D *view = nullptr,
1025  const UT_Matrix4D *proj = nullptr,
1026  const UT_DimRect *viewport = nullptr);
1027  void postDrawViewportString();
1028 
1029  // Called by various RE classes; do not call directly.
1030  static void destroyShaderObject(unsigned int progid, bool unreg,
1031  bool shader);
1032  static void destroyTextureObject(unsigned int texid, RE_OGLTexture *tex);
1033  static void destroyRenderbufferObject(unsigned int rb);
1034  static void destroyBufferObject(unsigned int buftype, unsigned int buf);
1035  static void destroySync(void *sync);
1036 
1037  static void clearCachedUniformBuffer(int id);
1038 
1039  // Context specific objects
1040  void destroyVertexArrayObject(unsigned int vao);
1041  void destroyQuery(unsigned int query);
1042  void destroyFramebufferObject(unsigned int fbo);
1043 
1044  void fetchDriverInfo(UT_WorkBuffer &info, bool full_info);
1045 
1046  // unbind common objects that might get stomped on by HDK calls:
1047  // shader, VAO, textures
1048  void unbindPipeline();
1049 
1050  // Invalidates all cached state. Useful when GL calls outside of RE are
1051  // used which change the GL state away from the cached state, and it is too
1052  // difficult to track the state, which is often the case with HDK plugins.
1053  void invalidateCachedState();
1054 
1055  // If GL calls outside of RE are used and change the state without restoring
1056  // it, call this method to update RE_OGLRender to the new state. This method
1057  // is somewhat expensive (causing a GPU/CPU sync) and should not be called
1058  // frequently or performance will suffer.
1059  void resync() { updateGLState(); }
1060 
1061 // Private methods ----------------------------------------------------------
1062 protected:
1063 
1064  /// Protected constructor to avoid having it created standalone. Strong
1065  /// assumptions are made that RE_OGLRender objects are always an instance
1066  /// of an RE_Render subclass.
1067  RE_OGLRender(int do_foreground, const char *appname = 0);
1068 
1069  // use macros for state change functions. Member variables are in
1070  // RE_OGLState.
1071 #define RE_FLAG_STATE(RE_NAME,GL_FLAG) \
1072  void enable##RE_NAME () { if( myState.my##RE_NAME##State != 1 ) { ::glEnable( GL_FLAG ); myState.my##RE_NAME##State = 1; } } \
1073  void disable##RE_NAME () { if( myState.my##RE_NAME##State != 0 ) { ::glDisable( GL_FLAG ); myState.my##RE_NAME##State = 0; } } \
1074  bool get##RE_NAME () { if(myState.my##RE_NAME##State == 3) update##RE_NAME(); return (myState.my##RE_NAME##State ==1); } \
1075  void update##RE_NAME () { myState.my##RE_NAME##State = ::glIsEnabled( GL_FLAG ); } \
1076  void invalidate##RE_NAME() { myState.my##RE_NAME##State = 3; }
1077 
1078  RE_FLAG_STATE(Scissor,GL_SCISSOR_TEST);
1079  RE_FLAG_STATE(LineSmoothing,GL_LINE_SMOOTH);
1080  RE_FLAG_STATE(Stencil,GL_STENCIL_TEST);
1081 #undef RE_FLAG_STATE
1082 
1083 #define RE_FLAG_11_STATE(RE_NAME,GL_FLAG) \
1084  void enable##RE_NAME () { if( (myState.my##RE_NAME##State) != 1 && hasGL11() ) {::glEnable( GLenum(GL_FLAG) ); myState.my##RE_NAME##State = 1; } } \
1085  void disable##RE_NAME () { if( myState.my##RE_NAME##State && hasGL11() ) { ::glDisable( GLenum(GL_FLAG) ); myState.my##RE_NAME##State = 0; } } \
1086  bool get##RE_NAME () { if(myState.my##RE_NAME##State == 3) update##RE_NAME(); return (myState.my##RE_NAME##State==1) ; } \
1087  void update##RE_NAME () { if( hasGL11() ) { myState.my##RE_NAME##State = ::glIsEnabled( GLenum(GL_FLAG) ); } else { myState.my##RE_NAME##State = 0; } } \
1088  void invalidate##RE_NAME() { if(hasGL11()) myState.my##RE_NAME##State=3; }
1089 
1093 #undef RE_FLAG_11_STATE
1094 
1095  void updateOffsetAmount();
1096 
1097  static bool initGLVersionInfo();
1098  virtual void initGLState();
1099  virtual void initGLExtensions();
1100  virtual void updateGLState();// load the following state variables
1101  virtual void updateStacks();
1102  void switchTexture(int textureunit, const RE_OGLTexture *texture);
1103 
1104  static void determineTwinView();
1105  bool switchContextForRender(bool ignore_errors);
1106 
1107 #ifdef WIN32
1108 private:
1109 #endif
1110 
1111  void updateBlendSmoothState();
1112  int privPushBlendSmoothState(bool smooth_too);
1113  void privPopBlendSmoothState(bool smooth_too, int *idx);
1114 
1115  void setupDebugging();
1116 
1117  void freePendingObjects();
1118 
1119  UT_DimRect adjustFramebufferViewport(const UT_DimRect &rect, bool to_fbo);
1120 
1121  void assignPushedUniforms();
1122 
1123  void fetchDriverInfoDict(UT_StringMap<UT_StringHolder> &dict);
1124 
1125 protected:
1126  // get the viewportState from GL
1127  void updateViewport();
1128 
1129  static RE_ZFunction oglToREzfunc( int oglZFunc );
1130  static int reToOGLzfunc( RE_ZFunction reZFunc );
1131  static RE_SFunction oglToREsfunc( int oglSFunc );
1132  static int reToOGLsfunc( RE_SFunction reSFunc );
1133  static RE_SOperation oglToREsoperation( int oglSOperation );
1134  static int reToOGLsoperation( RE_SOperation reSOperation );
1135 
1136  static const char *bufferName(GLint e);
1137  static const char *faceName(GLint e);
1138  static const char *hintName(GLint e);
1139  static const char *cullName(GLint e);
1140 
1141  // ---------------------------------------------------------------------
1142  // Cached OpenGL State
1143 
1145 
1146  // ------------------------------------------------------------------------
1147  // State independent data
1148 
1150 
1152 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1155 #else
1156  RE_GLDrawable *myCurDrawable;
1157 #endif
1159 
1161 
1164 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1166 #endif
1168 
1171 
1183 
1186 
1192 
1195 
1197 
1198  // Bound built-in uniform list for RE_Uniform.
1201  int myBuiltInStackIndex[RE_UNIFORM_BUILT_IN__count];
1202 
1204 
1205  int myViewportFontOffsetX, myViewportFontOffsetY;
1206 
1208 
1210  bool myMaterialTextureStack[RE_MAX_TEXTURE_STATE_STACK];
1211  int myMaterialLayerStack[RE_MAX_TEXTURE_STATE_STACK];
1214 
1224 
1228 
1232 
1235 
1237 
1243 
1245 
1246  // Static data ----------------------------------------------------------
1247  static int majorGLVersion;
1248  static int minorGLVersion;
1251 
1253  static int theXRes;
1254  static int theYRes;
1255  static int theDotsPerInch;
1258 
1260 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1263 #endif
1264 
1265  // Card and driver info
1267  static int theDriverMajor;
1268  static int theDriverMinor;
1271  static bool theUsingCoreProfile;
1272 
1273  // These objects are per-context.
1277 
1279 
1281  {
1282  public:
1284  : is_cached(false), type(RE_GPU_FLOAT32), vector_size(4)
1285  { value[0] = 0.0; value[1] = 0.0; value[2] = 0.0; value[3] = 0.0; }
1289  fpreal64 value[4];// This is just a scratch buffer for comparing
1290  };
1291 
1295 
1296  // Suspend check on Linux
1297  void suspendTestPatternRender();
1298  bool suspendTestPatternCheck();
1299 
1306 
1307 protected:
1310 
1311  // which thread this context was created in.
1312  ut_thread_id_t myNativeThread;
1314 
1315  friend class RE_RenderFlush;
1316 };
1317 
1319 {
1320 public:
1322  : myR(r),
1323  myLockedFlag(false)
1324  {
1325  if(!myR->isContextLocked())
1326  {
1327  myR->lockContextForRender();
1328  myLockedFlag = true;
1329  }
1330  }
1331 
1333  {
1334  if(myLockedFlag)
1335  {
1336  myR->unlockContextAfterRender();
1337  }
1338  }
1339 
1340 private:
1341  RE_OGLRender *myR;
1342  bool myLockedFlag;
1343 };
1344 
1345 
1346 // Inlines ---------------------------------------------------------------
1347 
1348 inline bool
1350  ((majorGLVersion >= 1) &&
1351  (minorGLVersion >= 1))); };
1352 inline bool
1354  ((majorGLVersion >= 1) &&
1355  (minorGLVersion >= 2))); };
1356 inline bool
1358  ((majorGLVersion >= 1) &&
1359  (minorGLVersion >= 3))); };
1360 inline bool
1362  ((majorGLVersion >= 1) &&
1363  (minorGLVersion >= 4))); };
1364 inline bool
1366  ((majorGLVersion >= 1) &&
1367  (minorGLVersion >= 5))); };
1368 inline bool
1370  ((majorGLVersion >= 2) &&
1371  (minorGLVersion >= 0))); };
1372 inline bool
1374  ((majorGLVersion >= 2) &&
1375  (minorGLVersion >= 1))); };
1376 
1377 inline bool
1378 RE_OGLRender::hasGL3(int minor) { return ((majorGLVersion > 3) ||
1379  ((majorGLVersion == 3) &&
1380  (minorGLVersion >= minor))); };
1381 
1382 inline bool
1383 RE_OGLRender::hasGL4(int minor) { return ((majorGLVersion > 4) ||
1384  ((majorGLVersion == 4) &&
1385  (minorGLVersion >= minor))); };
1386 
1389 
1392 
1393 inline RE_GraphicsDevice
1395 
1397 {
1398  return !(theDriverMajor == 0
1399  && theDriverMinor == 0
1400  && theDriverBuildMajor == 0
1401  && theDriverBuildMinor == 0);
1402 }
1407 
1408 inline RE_OGLExt *RE_OGLRender::getExt() const { return myExt; }
1410 {
1411  UT_ASSERT_P( myExt );
1412  return myExt->hasExtension( e );
1413 }
1414 
1415 inline int RE_OGLRender::resX() { return theXRes; }
1416 inline int RE_OGLRender::resY() { return theYRes; }
1417 inline int RE_OGLRender::dpi()
1418 {
1419  return SYSrint(theDotsPerInch * uiScale());
1420 }
1421 
1423 {
1424  if(theUIScale <= 0.0)
1425  return 1.0;
1426 
1427  return theUIScale;
1428 }
1429 
1430 inline float
1432 {
1433  return (float)n / dpi();
1434 }
1435 
1436 inline int
1438 {
1439  return (int)SYSrint(i*(float)dpi());
1440 }
1441 
1442 inline int
1444 {
1445  return (int)scaledSize((fpreal)size);
1446 }
1447 
1448 inline fpreal
1450 {
1451 #if defined(MBSD)
1452  // Native Qt widgets are automatically scaled by the OS using the display's
1453  // backing scale factor. Scaling again will make native Qt UI look
1454  // comically out-of-place.
1455  return size;
1456 #else
1457  if (size == 0)
1458  return size;
1459 
1460  fpreal ui_scale = uiScale();
1461  if (ui_scale == 1.0)
1462  return size;
1463 
1464  fpreal scaled_size = ui_scale * size + 0.5;
1465  if (scaled_size < 1.0)
1466  return 1.0;
1467 
1468  return scaled_size;
1469 #endif
1470 }
1471 
1472 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1473 inline RE_Window *
1475 #endif
1476 
1477 inline RE_OGLRender *
1479 
1480 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1481 inline RE_WindowList *
1483 
1484 inline const RE_Window *
1486 
1487 inline RE_Window *
1489 #else
1490 inline const RE_GLDrawable *
1491 RE_OGLRender::getCurrentDrawable() const { return myCurDrawable; }
1492 
1493 inline RE_GLDrawable *
1494 RE_OGLRender::getCurrentDrawable() { return myCurDrawable; }
1495 #endif
1496 
1497 inline bool
1499 { return myFrontBufferDirty;}
1500 
1501 inline void
1503 { myFrontBufferDirty = d; }
1504 
1505 inline int
1507 
1508 inline bool
1509 RE_OGLRender::isPointOffset() { return getPointOffset(); }
1510 
1511 inline bool
1512 RE_OGLRender::isLineOffset() { return getLineOffset(); }
1513 
1514 inline bool
1515 RE_OGLRender::isPolygonOffset() { return getFillOffset(); }
1516 
1517 inline void
1519 {
1520  if( onoff )
1521  enablePointOffset();
1522  else
1523  disablePointOffset();
1524 }
1525 
1526 inline void
1528 {
1529  if( onoff )
1530  enableLineOffset();
1531  else
1532  disableLineOffset();
1533 }
1534 
1535 inline void
1537 {
1538  if( onoff )
1539  enableFillOffset();
1540  else
1541  disableFillOffset();
1542 }
1543 
1544 inline void
1545 RE_OGLRender::getOffsetAmount(float *variable, float *constant) const
1546 {
1547  *variable = myState._offset_variable;
1548  *constant = myState._offset_constant;
1549 }
1550 
1551 inline bool
1553 {
1555 }
1556 inline int
1558 {
1559  return myState.myBlendSmoothLevel;
1560 }
1561 
1564 
1565 inline int
1567 { return myViewportFontOffsetX; }
1568 
1569 inline int
1571 { return myViewportFontOffsetY; }
1572 
1573 
1574 inline bool
1576 {
1578 }
1579 
1580 inline RE_PrimType
1582 {
1583  return myTransformFeedbackType;
1584 }
1585 
1586 inline bool
1588 {
1589  return myRasterizeEnabled;
1590 }
1591 
1592 inline RE_Uniform *
1594 {
1595  return myBuiltInUniforms[builtin_var_type];
1596 }
1597 
1598 inline bool
1600 {
1601  return myDebugLabelSupported;
1602 }
1603 
1604 inline bool
1606 {
1607  return myDebuggingSupported;
1608 }
1609 
1610 #endif
GLdouble s
Definition: glew.h:1390
int getMaxDrawBuffers() const
Definition: RE_OGLRender.h:884
UT_IntArray myPendingDeleteFBOs
RE_OGLExt * getExt() const
static int scaledSize(int size)
static int getDriverMajorVersion()
RE_PrimType getFeedbackMode() const
bool isRasterizeEnabled() const
bool myMultisampleEnable
int myDebugGroupStackSize
bool isInitialized() const
Definition: RE_OGLRender.h:122
int GLint
Definition: cl.hpp:165
UT_Vector2F myLineWidthRange
GLsizeiptr size
Definition: glew.h:1681
GLuint GLuint stream
Definition: glew.h:7265
int int32
Definition: SYS_Types.h:39
GLenum GLint ref
Definition: glew.h:1845
bool isFrontBufferDirty() const
GLuint const GLchar * name
Definition: glew.h:1814
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1520
void setPointSize(fpreal32 size)
OGLDrawable myPushedDrawable
static int inchesToPixels(float i)
#define RE_API
Definition: RE_API.h:10
bool mySampleShading
#define RE_FLAG_11_STATE(RE_NAME, GL_FLAG)
GLenum mode
Definition: glew.h:2163
int myFragmentDerivativeHint
int getMaxTexture3DSize() const
Definition: RE_OGLRender.h:875
static RE_GraphicsDevice theDevice
GLuint index
Definition: glew.h:1814
GLuint GLdouble u1
Definition: glew.h:3446
static int theDriverBuildMinor
RE_FaceMode
Definition: RE_Types.h:441
RE_TextureMode
RE_OGLFramebuffer * mySuspendTestFBO
RE_PrimType myTransformFeedbackType
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:13880
RE_GraphicsDevice
Definition: RE_Types.h:618
bool myDebugLabelSupported
#define GL_STENCIL_TEST
Definition: glew.h:456
int64 myBuiltInUniformSerial
GLuint GLfloat GLfloat GLfloat x1
Definition: glew.h:12681
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
bool isBlending() const
int getContextID() const
Definition: RE_OGLRender.h:119
static bool hasGL20()
GLenum query
Definition: glew.h:5704
void resetRenderCount()
Definition: RE_OGLRender.h:323
int64 myRenderCount
bool isPolygonOffset()
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
RE_Severity
Definition: RE_Types.h:607
static UT_Array< std::pair< RE_Visual *, RE_DisplayMode > > theVisuals
const GLdouble * m
Definition: glew.h:9124
static bool hasGL12()
static int allowsSmoothLines()
UT_IntArray myPendingDeleteQueries
GLhandleARB obj
Definition: glew.h:6236
void pointOffset(bool onoff)
GLuint shader
Definition: glew.h:1813
GLenum GLint GLuint mask
Definition: glew.h:1845
RE_TextureDimension
UT_IntArray myClipDistance
int myMaxTextureAnisotropy
UT_RecursiveSpinLock myOpenGLLock
float fpreal32
Definition: SYS_Types.h:200
GLboolean red
Definition: glew.h:2171
GLenum GLsizei GLenum GLenum const void * image
Definition: glew.h:4943
int getViewportFontOffsetX() const
#define GL_POLYGON_OFFSET_POINT
Definition: glew.h:727
bool isPointOffset()
static int glMinorVersion()
static fpreal uiScale()
static RE_GraphicsDevice getGraphicsDevice()
void lineOffset(bool onoff)
static int minorGLVersion
int myMaxVertexAttribs
int myMaxTextureRectSize
GLdouble GLdouble z
Definition: glew.h:1559
static RE_WindowList * theWindowList
int myMaxTexture3DSize
static bool hasGL14()
double fpreal64
Definition: SYS_Types.h:201
GLuint interp
Definition: glew.h:8277
RE_ShaderType
Definition: RE_Types.h:228
bool isCurrent() const
Definition: RE_OGLRender.h:271
static bool hasGL13()
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1414
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4648
int myMaxDebugGroupStackSize
RE_OGLTexture * mySuspendTestTexture
void getOffsetAmount(float *variable, float *constant) const
RE_GPUType
Definition: RE_Types.h:44
static fpreal theUIScale
UT_IntArray myPendingDeleteVertexArrays
int getMaxColorBuffers() const
Definition: RE_OGLRender.h:881
int getOGLMaxClipPlanes()
RE_Window * currentWindow
RE_Uniform * getUniform(RE_UniformBuiltIn builtin_var_type) const
bool myDebuggingSupported
static int getDriverMinorVersion()
GLint GLboolean layered
Definition: glew.h:3601
int myMaxTextureGeometryUnits
int getBlendSmoothLevel() const
UT_IntArray & getBoundUniformBlocks()
Definition: RE_OGLRender.h:814
RE_OcclusionQuery * myActiveQuery
GLclampf f
Definition: glew.h:3499
static int theXRes
int getMaxShaderTextureUnits() const
Definition: RE_OGLRender.h:860
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
#define RE_ACTIVE_UNIT
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
void pushLineWidth()
#define GL_POLYGON_OFFSET_FILL
Definition: glew.h:760
int getMaxVertexTextureUnits() const
Definition: RE_OGLRender.h:862
void bumpBuiltInUniformSerial()
Definition: RE_OGLRender.h:754
static RE_Window * theMainContextWindow
*tasks wait()
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:134
static int theDriverMajor
RE_Geometry * mySuspendBox
unsigned int RE_TextureID
UT_StopWatch * mySuspendCheckTimer
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
bool contextIsValid() const
Definition: RE_OGLRender.h:274
bool myActiveConditionalRender
GLsizei n
Definition: glew.h:4040
RE_SmoothMode
Definition: RE_Types.h:435
static RE_Server * theServer
UT_ArrayMap< int, RE_OGLFramebuffer * > myFBOTable
GLclampf green
Definition: glew.h:1520
int getViewportFontOffsetY() const
RE_BlendEquation
Definition: RE_Types.h:509
long long int64
Definition: SYS_Types.h:116
static RE_Window * getMainContext()
static int getDriverBuildMinorVersion()
png_const_structrp png_const_inforp int * unit
Definition: png.h:2161
#define RE_MAX_TEXTURE_STATE_STACK
RE_UniformBuiltIn
Definition: RE_Uniform.h:28
UT_Array< RE_FeedbackPrimitivesWrittenQuery * > myTransformFeedbackWrittenQuery
GLuint GLfloat GLfloat y0
Definition: glew.h:12681
static int resY()
GLclampf GLclampf blue
Definition: glew.h:1520
int myViewportFontOffsetY
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
RE_MemoryBarrierBitfield
Definition: RE_Types.h:526
int glslMinorVersion()
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:291
RE_DisplayMode
Definition: RE_Types.h:550
RE_ZFunction
Definition: RE_Types.h:448
PXL_DataFormat
Definition: PXL_Common.h:20
GLuint color
Definition: glew.h:7902
static UT_ThreadSpecificValue< RE_OGLRender * > theCurrentRender
void polygonOffset(bool onoff)
int myMaxTextureFragmentUnits
int myMaxTransformFeedbackComponents
static void allowSmoothLines(int yn)
short currentDisplayMode
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
RE_OGLFramebuffer * mySuspendResultFBO
bool myContextInitialized
OGLDrawable myDrawable
int myMaxTextureVertexUnits
GLenum GLenum dpfail
Definition: glew.h:1847
fpreal32 SYSrint(fpreal32 val)
Definition: SYS_Floor.h:163
#define RE_FLAG_STATE(RE_NAME, GL_FLAG)
RE_OGLExt * myExt
bool hasExtension(RE_Extension ext)
Definition: RE_OGLExt.h:35
RE_OGLTexture * mySuspendResultTexture
int getMaxTextureSize() const
Definition: RE_OGLRender.h:873
RE_OGLVertexArrayList * getDefaultVAO()
Definition: RE_OGLRender.h:804
bool hasGLExtension(RE_Extension e) const
GLsizei stride
Definition: glew.h:1523
int getMaxFragmentTextureUnits() const
Definition: RE_OGLRender.h:866
GLuint GLfloat x0
Definition: glew.h:12681
RE_OGLContext getContext() const
Definition: RE_OGLRender.h:275
bool isDebugging() const
int myVertexMaxStreams
static int theDotsPerInch
void bumpRenderCount()
Definition: RE_OGLRender.h:322
int myViewportFontOffsetX
int myShaderOnlyModeCount
static int theDriverBuildMajor
RE_OGLState myState
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
const RE_Render * getRender() const
Definition: RE_OGLRender.h:127
GLfloat GLfloat p
Definition: glew.h:16321
static int getDriverBuildMajorVersion()
static bool theSmoothLinesAllowed
RE_RenderAutoLock(RE_OGLRender *r)
GLenum GLenum GLenum dppass
Definition: glew.h:1847
GLenum func
Definition: glcorearb.h:782
static RE_WindowList * getWindowList()
RE_BufferAccess
Definition: RE_Types.h:294
void pushPointSize(fpreal32 size)
Point options that can change per-point.
bool isTransformFeedbackEnabled() const
int glslMajorVersion()
RE_Render * getRender()
Definition: RE_OGLRender.h:125
UT_Array< RE_Uniform * > myPushedUniforms
int64 getBuiltInUniformSerial() const
Definition: RE_OGLRender.h:752
static bool hasGL15()
bool myIsAllowingOtherThreads
#define GL_POLYGON_OFFSET_LINE
Definition: glew.h:728
fpreal64 fpreal
Definition: SYS_Types.h:277
void popLineWidth()
static int theDriverMinor
const RE_Window * getCurrentWindow() const
static bool hasGL4(int minor)
bool isDebugLabelSupported() const
RE_SOperation
Definition: RE_Types.h:472
int myMaxTextureShaderUnits
GLenum GLuint texture
Definition: glew.h:2361
RE_OGLContext myContext
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
fpreal myShaderSampleRate
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition: glew.h:12681
GLint GLboolean GLint layer
Definition: glew.h:3601
RE_VisualType
Definition: RE_Types.h:600
int getTextureAnisotropyLimit() const
Definition: RE_OGLRender.h:868
GLint maxClipPlanes
RE_BlendSourceFactor
Definition: RE_Types.h:484
static bool hasGL11()
ut_thread_id_t myNativeThread
int myMaxTransformFeedbackBuffers
static float pixelsToInches(int n)
GLfloat v0
Definition: glew.h:1848
static int dpi()
unsigned int uint32
Definition: SYS_Types.h:40
static bool hasDriverVersion()
GLuint GLenum texunit
Definition: glew.h:9244
UT_IntArray myDebugStack
bool myMaterialLighting
int64 getRenderCount() const
Definition: RE_OGLRender.h:324
int myBlendSmoothLevel
Definition: RE_OGLState.h:120
RE_RenderBuf
Definition: RE_Types.h:407
bool myTransformFeedbackEnabled
int getMaxVertexAttribs() const
Definition: RE_OGLRender.h:779
static bool theUsingCoreProfile
RE_Window * mySavedMainThreadCurrentWindow
static bool hasGL3(int minor)
RE_OGLVertexArrayList * myCurrentVAO
bool myRasterizeEnabled
bool isLineOffset()
float _offset_variable
Definition: RE_OGLState.h:65
re_BlendSmoothState myBlendSmoothStack[RE_SMOOTH_STACK_SIZE]
Definition: RE_OGLState.h:121
int getMaxGeometryTextureUnits() const
Definition: RE_OGLRender.h:864
void popUniformData(RE_UniformBuiltIn bindex)
Definition: RE_OGLRender.h:732
void setDefaultVAO(RE_OGLVertexArrayList *vao)
Definition: RE_OGLRender.h:807
RE_ShaderTarget
Definition: RE_Types.h:250
GLsizei samples
Definition: glew.h:2998
static UT_ThreadSpecificValue< RE_OGLRender * > theLastRender
static int resX()
void popPointSize()
int getMaxTextureRectangleSize()
Definition: RE_OGLRender.h:877
static bool hasGL21()
QOpenGLContext * RE_OGLContext
Definition: RE_Types.h:915
RE_Uniform * myBuiltInUniforms[RE_UNIFORM_BUILT_IN__count]
void setFrontBufferDirty(bool d)
UT_Array< RE_PrimitivesGeneratedQuery * > myTransformFeedbackPrimitiveQuery
UT_Array< re_ConstVertexAttrib > myConstVertexAttribs
static int theYRes
RE_Shader * myShaderOnlyActiveShader
GLenum GLuint GLsizei const GLchar * buf
Definition: glew.h:2580
GLenum GLenum variable
Definition: glew.h:13879
#define GL_LINE_SMOOTH
Definition: glew.h:417
RE_PrimType
Definition: RE_Types.h:193
RE_SFunction
Definition: RE_Types.h:460
GLsizei const GLfloat * value
Definition: glew.h:1849
float _offset_constant
Definition: RE_OGLState.h:66
GLboolean enable
Definition: glew.h:2745
bool myFrontBufferDirty
#define RE_BUFFER_STACK_SIZE
Definition: RE_Types.h:901
RE_OGLVertexArrayList * myDefaultVAO
RE_Extension
Definition: RE_Extension.h:4
GLfloat GLfloat v1
Definition: glew.h:1852
RE_OGLContext pushedGraphicsContext
bool firstInitialize
GLenum sfail
Definition: glew.h:1847
bool myMultisampleAlphaToCoverage
Definition: RE_Uniform.h:375
int myOpenGLContextLockCount
static int majorGLVersion
GA_API const UT_StringHolder area
static RE_OGLRender * getCurrentRender()
Simple interface to building a shader from a .prog file.
#define GL_SCISSOR_TEST
Definition: glew.h:7992
RE_BlendDestFactor
Definition: RE_Types.h:497
static int glMajorVersion()