36 #ifndef __RE_OGLRender__
37 #define __RE_OGLRender__
101 #define RE_DRIVER_INFO_VENDOR "OpenGL Vendor"
102 #define RE_DRIVER_INFO_RENDERER "OpenGL Renderer"
103 #define RE_DRIVER_INFO_VERSION "OpenGL Version"
104 #define RE_DRIVER_INFO_SHADING_LANGUAGE "OpenGL Shading Language"
105 #define RE_DRIVER_INFO_DETECTED "Detected"
114 const char *className()
const;
122 {
return reinterpret_cast<RE_Render*
>(
this); }
124 {
return reinterpret_cast<const RE_Render*
>(
this); }
129 static bool hasGL11();
130 static bool hasGL12();
131 static bool hasGL13();
132 static bool hasGL14();
133 static bool hasGL15();
134 static bool hasGL20();
135 static bool hasGL21();
137 static bool hasGL3(
int minor);
138 static bool hasGL4(
int minor);
140 static int glMajorVersion();
141 static int glMinorVersion();
144 int glslMajorVersion();
145 int glslMinorVersion();
160 static void setPerformBadDriverCheck(
bool onoff);
163 static bool hasDriverVersion();
164 static int getDriverMajorVersion();
165 static int getDriverMinorVersion();
166 static int getDriverBuildMajorVersion();
167 static int getDriverBuildMinorVersion();
170 static bool getUsingCoreProfile();
171 static void setUsingCoreProfile(
bool using_core_profile);
178 static void clearGraphicsCache();
183 int64 getFreeTextureMemoryKB(
int64 *largest_chunk =
nullptr);
184 int64 getFreeBufferMemoryKB(
int64 *largest_chunk =
nullptr);
185 int64 getFreeFramebufferMemoryKB(
int64 *largest_chunk =
nullptr);
188 static int64 getInitialFreeMemoryKB();
192 static void exitWithBadDriver();
199 static void updateScreenSize();
204 static bool areScreensUniform();
222 static float pixelsToInches(
int n);
223 static int inchesToPixels(
float i);
224 static int scaledSize(
int size);
230 void checkForSuspendResume();
231 static void addSuspendResumeCB(
void (*cb)(
void*),
void *
data);
232 static void removeSuspendResumeCB(
void (*cb)(
void*),
void *
data);
239 void enableMultisample(
bool enable);
240 bool isMultisampleEnabled()
const;
242 void enableAlphaToCoverage(
bool enable);
243 bool isAlphaToCoverage()
const;
245 void getMaxViewportSize(
int &
w,
int &
h)
const;
246 int getMaxColorSamples()
const;
247 int getMaxDepthSamples()
const;
253 void setWindow(
RE_Window *,
bool attach =
true);
255 bool makeCurrent(
bool ignore_errors =
false);
256 bool makeCurrentQt();
258 {
return theCurrentRender.get() ==
this; }
259 static void resetCurrent();
266 void popOffscreenBuffer();
274 const RE_Window *getCurrentWindow()
const;
296 void lockContextForRender();
297 void unlockContextAfterRender();
298 bool tryLockContextForRender();
299 bool isContextLocked()
const;
307 int getNextGLError();
308 void clearGLErrors();
309 const char *getGLErrorString(
int error );
310 void printGLError(
const char *header,
311 bool assert =
false );
312 void printAllGLErrors(
const char *header,
313 bool assert =
false );
315 void dumpNewState(
bool show_all =
false,
316 bool show_shader_blocks =
true);
317 void dumpViewportState(
bool show_all =
false);
318 void dumpTextureState()
const;
319 void dumpVertexAttributes()
const;
320 void dumpFragmentTests(
bool show_all =
false)
const;
321 void dumpRasterizeState(
bool show_all =
false)
const;
322 void dumpTextureCacheState(
int stack_level =-1)
const;
327 bool isDebugLabelSupported()
const;
330 bool isDebugging()
const;
332 int pushDebug(
bool enable);
333 void popDebug(
int *nest =
nullptr);
335 int pushDebugGroup(
const char *
name,
int id=1987);
336 void popDebugGroup(
int *nest =
nullptr);
338 void addComment(
const char *
name,
347 int pushDrawFramebuffer();
351 void popDrawFramebuffer(
int *nest =
nullptr);
353 int pushReadFramebuffer();
357 void popReadFramebuffer(
int *nest =
nullptr);
359 void updateFramebuffer();
365 void unregisterFBO(
int id);
369 void useSampleMask(
bool use);
370 bool usingSampleMask()
const;
371 int getMaxIntegerSamples()
const;
372 int getSampleMask(
int mask_number);
373 void setSampleMask(
int mask_number,
int mask);
374 static int getMatteMaskForSampleCount(
int samples);
380 void clearC(
float *
color =
nullptr);
381 void clearZ(
float z = 1.0);
382 void clearCZ(
float z = 1.0);
391 void enableColorBufferWriting();
392 void disableColorBufferWriting();
393 bool getColorBufferWriting();
394 void updateColorBufferWriting();
403 void popDrawBuffer(
int *nest = 0);
406 bool getDrawBufferIsBlendable();
409 void popReadBuffer(
int *nest = 0);
416 bool isFrontBufferDirty()
const;
417 void setFrontBufferDirty(
bool d);
419 void flush(
int wait=0);
431 void disableScreenMask();
432 void intersectMask2DI(
const UT_DimRect &rect);
435 bool getScreenMask();
438 int getOGLMaxClipPlanes();
439 void enableClipDistance(
int clip_plane,
bool enable);
440 bool clipDistanceEnabled(
int clip_plane)
const;
447 int pushBackfaceCulling();
448 int pushBackfaceCulling(
bool backface);
449 void popBackfaceCulling(
int *nested = 0);
451 bool isBackface()
const;
452 void setBackface(
bool removeBackface);
453 bool getReverseWinding();
454 void setReverseWinding(
bool reverse_winding);
459 bool isPointOffset();
461 bool isPolygonOffset();
462 void pointOffset(
bool onoff );
463 void lineOffset(
bool onoff );
464 void polygonOffset(
bool onoff );
465 void setOffsetAmount(
float variable,
float constant );
466 void getOffsetAmount(
float *variable,
float *constant)
const;
480 int stream_bitfield = 0x1);
483 void endTransformFeedback();
487 int getNumFeedbackPrimitives(
int stream = 0);
491 bool hasFeedbackBufferOverflow(
int stream = 0);
494 bool isTransformFeedbackEnabled()
const;
496 bool isRasterizeEnabled()
const;
501 float getLineWidth()
const;
502 float getMaxSmoothLineWidth();
510 void setProgramPointSize(
bool enable);
511 bool getProgramPointSize()
const;
519 int pushDepthState();
520 void popDepthState(
int *nest =
nullptr);
524 void enableDepthBufferWriting();
525 void disableDepthBufferWriting();
526 bool getDepthBufferWriting();
527 void updateDepthBufferWriting();
530 void enableDepthTest();
531 void disableDepthTest();
533 void updateDepthTest();
538 void updateZFunction()
const;
542 void enableDepthClamp(
bool b);
543 bool getDepthClamp();
544 void updateDepthClamp();
546 void setDepthRange(
double nr,
double fr);
547 void getDepthRange(
double &nr,
double &fr)
const;
550 int pushStencilState();
551 void popStencilState(
int *nest =
nullptr);
553 void setStencil(
bool enable);
554 void setSClearValue(
int clearValue);
555 void setSWriteMask(
int writeMask);
560 void updateStencilState();
561 void resetSFunction();
562 void resetSWriteMask();
563 void resetSClearValue();
564 void resetSOperation();
567 void enableLogicOp();
568 void disableLogicOp();
574 int pushBlendState();
575 void popBlendState(
int *nesting = 0);
577 bool isBlending()
const;
578 void blend(
int onoff);
593 void blendAlpha(
int onoff = 1);
594 void blendAlphaPremult(
bool onoff =
true);
596 int pushSmoothLines();
597 void popSmoothLines(
int *nesting = 0);
600 void smoothBlendLinesNoFlagChange(
bool by_smooth);
603 int getBlendSmoothLevel()
const;
605 static void allowSmoothLines(
int yn);
606 static int allowsSmoothLines();
618 RE_Shader *override_mat_shader =
nullptr,
619 bool allow_partial_render =
false);
623 RE_Shader *override_mat_shader =
nullptr,
624 bool allow_partial_render =
false);
626 void popMaterial(
int *nest =
nullptr);
642 void popShader(
int *nest =
nullptr);
646 int pushShaderTransformFeedback(
RE_Shader *sh,
649 int stream_bitfield = 0x1);
653 int stream_bitfield = 0x1);
654 void popShaderTransformFeedback(
int *nest =
nullptr);
660 void setShaderOnlyMode(
bool enable);
661 void requestFixedFunction();
673 void setPatchVertices(
int num_verts);
682 bool setShaderSampleRate(
fpreal rate);
683 fpreal getShaderSampleRate()
const;
685 bool isSampleShading()
const;
713 { popUniform(bindex); }
719 void printBuiltInUniforms(
bool bound_only);
733 {
return myBuiltInUniformSerial; }
749 bool inverse_too =
false);
750 void popObjectMatrix();
755 void setFragmentDerivativeHint(
bool nicest);
756 bool getFragmentDerivativeHint();
763 void setConstAttribF32(
int loc,
int vsize,
const fpreal32 *
data);
766 void setConstAttribF32(
int loc,
int vsize,
const fpreal64 *
data);
769 void setConstAttribF64(
int loc,
int vsize,
const fpreal64 *
data);
772 void setConstAttribI32(
int loc,
int vsize,
const int32 *
data);
775 void setConstAttribU32(
int loc,
int vsize,
const uint32 *
data);
812 int bindTextureRaw(
int id,
int unit);
823 void setActiveTexture(
int textureunit);
824 int getActiveTexture()
const;
832 void popTextureState(
int *nest =
nullptr);
841 int findFirstFreeTextureUnit(
int starting_unit = 0)
const;
844 void updateTextureState()
const;
848 {
return myMaxTextureShaderUnits; }
850 {
return myMaxTextureVertexUnits; }
852 {
return myMaxTextureGeometryUnits; }
854 {
return myMaxTextureFragmentUnits; }
856 {
return myMaxTextureAnisotropy; }
861 {
return myMaxTextureSize; }
863 {
return myMaxTexture3DSize; }
865 {
return myMaxTextureRectSize; }
869 {
return myMaxColorBuffers; }
872 {
return myMaxDrawBuffers; }
875 void disableAllTextures();
879 bool bindImageTexture(
int image_unit,
884 void unbindImageTexture(
int image_unit);
890 int pushReadAlignment(
const void *
data,
int scansize);
891 void popReadAlignment(
int *nest =
nullptr);
893 int pushWriteAlignment(
const void *
data,
int scansize);
894 void popWriteAlignment(
int *nest =
nullptr);
897 void useSeamlessMaps(
bool enable);
898 bool usingSeamlessMaps();
909 int num_layers,
int size = 64 );
915 RE_OGLTexture *getRandomSampleMaskTexture(
unsigned int seed,
int nsamples,
922 int convert16bit = 0);
928 bool is3DLUTSupported()
const;
930 void buildRasterTextureGeometry(
937 void displayRasterTexture(
float x,
float y,
float z,
940 void displayRasterTexture(
float x,
float y,
float z,
944 void displayRasterTexture(
float x,
float y,
float z,
950 float alpha_mult=1.0
f);
956 void saveRaster(
int x,
int y,
int w,
int h,
960 bool use_backbuf =
true);
969 void setViewportFontOffset(
int x,
int y);
970 int getViewportFontOffsetX()
const;
971 int getViewportFontOffsetY()
const;
994 bool region_support);
995 void endConditionalRender();
999 void enablePrimitiveRestart(
bool enable);
1000 void setPrimitiveRestartIndex(
unsigned int index);
1004 void drawViewportPoint(
const fpreal32 p[3],
1009 void drawViewportString(
const fpreal32 p[3],
1015 void postDrawViewportString();
1018 static void destroyShaderObject(
unsigned int progid,
bool unreg,
1020 static void destroyTextureObject(
unsigned int texid,
RE_OGLTexture *tex);
1021 static void destroyRenderbufferObject(
unsigned int rb);
1022 static void destroyBufferObject(
unsigned int buf);
1023 static void destroySync(
void *sync);
1025 static void clearCachedUniformBuffer(
int id);
1028 void destroyVertexArrayObject(
unsigned int vao);
1029 void destroyQuery(
unsigned int query);
1030 void destroyFramebufferObject(
unsigned int fbo);
1036 void unbindPipeline();
1041 void invalidateCachedState();
1052 void enableSubBufferDrawing(
bool enable);
1061 RE_OGLRender(
int do_foreground,
const char *appname = 0);
1065 #define RE_FLAG_STATE(RE_NAME,GL_FLAG) \
1066 void enable##RE_NAME () { if( myState.my##RE_NAME##State != 1 ) { ::glEnable( GL_FLAG ); myState.my##RE_NAME##State = 1; } } \
1067 void disable##RE_NAME () { if( myState.my##RE_NAME##State != 0 ) { ::glDisable( GL_FLAG ); myState.my##RE_NAME##State = 0; } } \
1068 bool get##RE_NAME () { if(myState.my##RE_NAME##State == 3) update##RE_NAME(); return (myState.my##RE_NAME##State ==1); } \
1069 void update##RE_NAME () { myState.my##RE_NAME##State = ::glIsEnabled( GL_FLAG ); } \
1070 void invalidate##RE_NAME() { myState.my##RE_NAME##State = 3; }
1075 #undef RE_FLAG_STATE
1077 #define RE_FLAG_11_STATE(RE_NAME,GL_FLAG) \
1078 void enable##RE_NAME () { if( (myState.my##RE_NAME##State) != 1 && hasGL11() ) {::glEnable( GLenum(GL_FLAG) ); myState.my##RE_NAME##State = 1; } } \
1079 void disable##RE_NAME () { if( myState.my##RE_NAME##State && hasGL11() ) { ::glDisable( GLenum(GL_FLAG) ); myState.my##RE_NAME##State = 0; } } \
1080 bool get##RE_NAME () { if(myState.my##RE_NAME##State == 3) update##RE_NAME(); return (myState.my##RE_NAME##State==1) ; } \
1081 void update##RE_NAME () { if( hasGL11() ) { myState.my##RE_NAME##State = ::glIsEnabled( GLenum(GL_FLAG) ); } else { myState.my##RE_NAME##State = 0; } } \
1082 void invalidate##RE_NAME() { if(hasGL11()) myState.my##RE_NAME##State=3; }
1087 #undef RE_FLAG_11_STATE
1089 void updateOffsetAmount();
1091 static bool initGLVersionInfo();
1092 virtual void initGLState();
1093 virtual void initGLExtensions();
1094 virtual void updateGLState();
1095 virtual void updateStacks();
1098 static void determineTwinView();
1099 bool switchContextForRender(
bool ignore_errors);
1105 void updateBlendSmoothState();
1106 int privPushBlendSmoothState(
bool smooth_too);
1107 void privPopBlendSmoothState(
bool smooth_too,
int *idx);
1109 void setupDebugging();
1111 void freePendingObjects();
1115 void assignPushedUniforms();
1121 void updateViewport();
1127 static RE_SOperation oglToREsoperation(
int oglSOperation );
1130 static const char *bufferName(
GLint e);
1131 static const char *faceName(
GLint e);
1132 static const char *hintName(
GLint e);
1133 static const char *cullName(
GLint e);
1285 void suspendTestPatternRender();
1286 bool suspendTestPatternCheck();
1313 if(!myR->isContextLocked())
1315 myR->lockContextForRender();
1316 myLockedFlag =
true;
1324 myR->unlockContextAfterRender();
1421 return (
float)n /
dpi();
1449 if (ui_scale == 1.0)
1452 fpreal scaled_size = ui_scale * size + 0.5;
1453 if (scaled_size < 1.0)
1499 enablePointOffset();
1501 disablePointOffset();
1510 disableLineOffset();
1519 disableFillOffset();
int getMaxDrawBuffers() const
UT_IntArray myPendingDeleteFBOs
RE_OGLExt * getExt() const
static int scaledSize(int size)
static int getDriverMajorVersion()
GLenum GLuint GLenum GLsizei const GLchar * buf
RE_PrimType getFeedbackMode() const
bool isRasterizeEnabled() const
int myDebugGroupStackSize
RV_API RV_VKImagePtr getRandomTextureArray(RV_Render *r, unsigned int seed, bool interp, int num_layers, int size=64)
Returns an 8b RGBA size^2 2D texture array of size 'num_layers'.
bool isInitialized() const
UT_Vector2F myLineWidthRange
bool isFrontBufferDirty() const
void setPointSize(fpreal32 size)
OGLDrawable myPushedDrawable
static int inchesToPixels(float i)
void rasterize(const PointDataTreeOrGridT &points, TransferT &transfer, const FilterT &filter=NullFilter(), InterrupterT *interrupter=nullptr)
Perform potentially complex rasterization from a user defined transfer scheme.
#define RE_FLAG_11_STATE(RE_NAME, GL_FLAG)
int myFragmentDerivativeHint
int getMaxTexture3DSize() const
static RE_GraphicsDevice theDevice
static int theDriverBuildMinor
RE_OGLFramebuffer * mySuspendTestFBO
RE_PrimType myTransformFeedbackType
GLdouble GLdouble GLdouble z
#define GL_POLYGON_OFFSET_POINT
bool myDebugLabelSupported
int64 myBuiltInUniformSerial
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
static UT_Array< std::pair< RE_Visual *, RE_DisplayMode > > theVisuals
GLenum GLenum GLsizei void * image
static int allowsSmoothLines()
UT_IntArray myPendingDeleteQueries
void pointOffset(bool onoff)
GLdouble GLdouble GLdouble q
UT_IntArray myClipDistance
bool subBufferDrawingEnabled() const
int myMaxTextureAnisotropy
UT_RecursiveSpinLock myOpenGLLock
GLenum GLenum GLenum dppass
int getViewportFontOffsetX() const
static int glMinorVersion()
static RE_GraphicsDevice getGraphicsDevice()
#define GL_POLYGON_OFFSET_FILL
void lineOffset(bool onoff)
static int minorGLVersion
GLenum GLuint GLint GLint layer
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
static RE_WindowList * theWindowList
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
int myMaxDebugGroupStackSize
RE_OGLTexture * mySuspendTestTexture
void getOffsetAmount(float *variable, float *constant) const
GA_API const UT_StringHolder scale
UT_IntArray myPendingDeleteVertexArrays
int getMaxColorBuffers() const
int getOGLMaxClipPlanes()
RE_Window * currentWindow
RE_Uniform * getUniform(RE_UniformBuiltIn builtin_var_type) const
bool myDebuggingSupported
static int getDriverMinorVersion()
int myMaxTextureGeometryUnits
int getBlendSmoothLevel() const
UT_IntArray & getBoundUniformBlocks()
RE_OcclusionQuery * myActiveQuery
int getMaxShaderTextureUnits() const
int getMaxVertexTextureUnits() const
void bumpBuiltInUniformSerial()
static RE_Window * theMainContextWindow
static int theDriverMajor
RE_Geometry * mySuspendBox
unsigned int RE_TextureID
GLuint GLint GLboolean layered
UT_StopWatch * mySuspendCheckTimer
GLint GLint GLsizei GLint GLenum format
bool contextIsValid() const
GLint GLenum GLboolean GLsizei stride
bool myActiveConditionalRender
static RE_Server * theServer
UT_ArrayMap< int, RE_OGLFramebuffer * > myFBOTable
int getViewportFontOffsetY() const
HUSD_API const char * raster()
static RE_Window * getMainContext()
static int getDriverBuildMinorVersion()
png_const_structrp png_const_inforp int * unit
GLfloat GLfloat GLfloat alpha
#define RE_MAX_TEXTURE_STATE_STACK
SIM_API const UT_StringHolder rotation
UT_Array< RE_FeedbackPrimitivesWrittenQuery * > myTransformFeedbackWrittenQuery
int myViewportFontOffsetY
GLuint const GLchar * name
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
static UT_ThreadSpecificValue< RE_OGLRender * > theCurrentRender
void polygonOffset(bool onoff)
int myMaxTextureFragmentUnits
int myMaxTransformFeedbackComponents
static void allowSmoothLines(int yn)
GLboolean GLboolean GLboolean b
RE_OGLFramebuffer * mySuspendResultFBO
bool myContextInitialized
int myMaxTextureVertexUnits
fpreal32 SYSrint(fpreal32 val)
#define RE_FLAG_STATE(RE_NAME, GL_FLAG)
bool hasExtension(RE_Extension ext)
RE_OGLTexture * mySuspendResultTexture
int getMaxTextureSize() const
RE_OGLVertexArrayList * getDefaultVAO()
bool hasGLExtension(RE_Extension e) const
int getMaxFragmentTextureUnits() const
RE_OGLContext getContext() const
static int theDotsPerInch
int myViewportFontOffsetX
int myShaderOnlyModeCount
static int theDriverBuildMajor
const RE_Render * getRender() const
static int getDriverBuildMajorVersion()
static bool theSmoothLinesAllowed
GLfloat GLfloat GLfloat GLfloat h
RE_RenderAutoLock(RE_OGLRender *r)
static RE_WindowList * getWindowList()
void pushPointSize(fpreal32 size)
Point options that can change per-point.
bool isTransformFeedbackEnabled() const
SIM_API const UT_StringHolder force
UT_Array< RE_Uniform * > myPushedUniforms
int64 getBuiltInUniformSerial() const
bool myIsAllowingOtherThreads
static int theDriverMinor
const RE_Window * getCurrentWindow() const
static bool hasGL4(int minor)
bool isDebugLabelSupported() const
int myMaxTextureShaderUnits
fpreal myShaderSampleRate
int getTextureAnisotropyLimit() const
ut_thread_id_t myNativeThread
int myMaxTransformFeedbackBuffers
static float pixelsToInches(int n)
static bool hasDriverVersion()
RV_API RV_VKImagePtr getRandomTexture(RV_Render *r, unsigned int seed, bool interp, int size=64)
Returns an 8b RGBA 64x64 texture with 0-1 random values in all comps.
int64 getRenderCount() const
GLubyte GLubyte GLubyte GLubyte w
bool myTransformFeedbackEnabled
int getMaxVertexAttribs() const
static bool theUsingCoreProfile
RE_Window * mySavedMainThreadCurrentWindow
static bool hasGL3(int minor)
RE_OGLVertexArrayList * myCurrentVAO
re_BlendSmoothState myBlendSmoothStack[RE_SMOOTH_STACK_SIZE]
int getMaxGeometryTextureUnits() const
void popUniformData(RE_UniformBuiltIn bindex)
void setDefaultVAO(RE_OGLVertexArrayList *vao)
static UT_ThreadSpecificValue< RE_OGLRender * > theLastRender
int getMaxTextureRectangleSize()
QOpenGLContext * RE_OGLContext
RE_Uniform * myBuiltInUniforms[RE_UNIFORM_BUILT_IN__count]
void setFrontBufferDirty(bool d)
UT_Array< RE_PrimitivesGeneratedQuery * > myTransformFeedbackPrimitiveQuery
UT_Array< re_ConstVertexAttrib > myConstVertexAttribs
RE_Shader * myShaderOnlyActiveShader
png_structrp int png_fixed_point red
RV_API RV_VKImagePtr getRandomTexture3D(RV_Render *r, unsigned int seed, bool interp, int size=32)
Returns an 8b RGBA size^3 3D texture with 0-1 random values.
#define RE_BUFFER_STACK_SIZE
RE_OGLVertexArrayList * myDefaultVAO
RE_OGLContext pushedGraphicsContext
bool myMultisampleAlphaToCoverage
int myOpenGLContextLockCount
static int majorGLVersion
#define GL_POLYGON_OFFSET_LINE
GA_API const UT_StringHolder area
static RE_OGLRender * getCurrentRender()
Simple interface to building a shader from a .prog file.
static int glMajorVersion()