36 #ifndef __RE_OGLRender__
37 #define __RE_OGLRender__
84 #if defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
97 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
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"
118 const char *className()
const;
126 {
return reinterpret_cast<RE_Render*
>(
this); }
128 {
return reinterpret_cast<const RE_Render*
>(
this); }
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();
141 static bool hasGL3(
int minor);
142 static bool hasGL4(
int minor);
144 static int glMajorVersion();
145 static int glMinorVersion();
148 int glslMajorVersion();
149 int glslMinorVersion();
164 static void setPerformBadDriverCheck(
bool onoff);
167 static bool hasDriverVersion();
168 static int getDriverMajorVersion();
169 static int getDriverMinorVersion();
170 static int getDriverBuildMajorVersion();
171 static int getDriverBuildMinorVersion();
174 static bool getUsingCoreProfile();
175 static void setUsingCoreProfile(
bool using_core_profile);
182 static void clearGraphicsCache();
187 int64 getFreeTextureMemoryKB(
int64 *largest_chunk =
nullptr);
188 int64 getFreeBufferMemoryKB(
int64 *largest_chunk =
nullptr);
189 int64 getFreeFramebufferMemoryKB(
int64 *largest_chunk =
nullptr);
192 static int64 getInitialFreeMemoryKB();
196 static void exitWithBadDriver();
203 static void updateScreenSize();
208 static bool areScreensUniform();
226 static float pixelsToInches(
int n);
227 static int inchesToPixels(
float i);
228 static int scaledSize(
int size);
234 void checkForSuspendResume();
235 static void addSuspendResumeCB(
void (*cb)(
void*),
void *
data);
236 static void removeSuspendResumeCB(
void (*cb)(
void*),
void *
data);
238 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
245 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
249 void enableMultisample(
bool enable);
250 bool isMultisampleEnabled()
const;
252 void enableAlphaToCoverage(
bool enable);
253 bool isAlphaToCoverage()
const;
255 void getMaxViewportSize(
int &
w,
int &
h)
const;
256 int getMaxColorSamples()
const;
257 int getMaxDepthSamples()
const;
263 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
264 void setWindow(
RE_Window *,
bool attach =
true);
269 bool makeCurrent(
bool ignore_errors =
false);
270 bool makeCurrentQt();
272 {
return theCurrentRender.get() ==
this; }
273 static void resetCurrent();
280 void popOffscreenBuffer();
282 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
289 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
291 const RE_Window *getCurrentWindow()
const;
317 void lockContextForRender();
318 void unlockContextAfterRender();
319 bool tryLockContextForRender();
320 bool isContextLocked()
const;
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 );
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;
348 bool isDebugLabelSupported()
const;
351 bool isDebugging()
const;
353 int pushDebug(
bool enable);
354 void popDebug(
int *nest =
nullptr);
356 int pushDebugGroup(
const char *
name,
int id=1987);
357 void popDebugGroup(
int *nest =
nullptr);
359 void addComment(
const char *
name,
368 int pushDrawFramebuffer();
372 void popDrawFramebuffer(
int *nest =
nullptr);
374 int pushReadFramebuffer();
378 void popReadFramebuffer(
int *nest =
nullptr);
380 void updateFramebuffer();
386 void unregisterFBO(
int id);
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);
401 void clearC(
float *
color =
nullptr);
402 void clearZ(
float z = 1.0);
403 void clearCZ(
float z = 1.0);
412 void enableColorBufferWriting();
413 void disableColorBufferWriting();
414 bool getColorBufferWriting();
415 void updateColorBufferWriting();
424 void popDrawBuffer(
int *nest = 0);
427 bool getDrawBufferIsBlendable();
430 void popReadBuffer(
int *nest = 0);
437 bool isFrontBufferDirty()
const;
438 void setFrontBufferDirty(
bool d);
440 void flush(
int wait=0);
452 void disableScreenMask();
453 void intersectMask2DI(
const UT_DimRect &rect);
456 bool getScreenMask();
459 int getOGLMaxClipPlanes();
460 void enableClipDistance(
int clip_plane,
bool enable);
461 bool clipDistanceEnabled(
int clip_plane)
const;
468 int pushBackfaceCulling();
469 int pushBackfaceCulling(
bool backface);
470 void popBackfaceCulling(
int *nested = 0);
472 bool isBackface()
const;
473 void setBackface(
bool removeBackface);
474 bool getReverseWinding();
475 void setReverseWinding(
bool reverse_winding);
480 bool isPointOffset();
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;
501 int stream_bitfield = 0
x1);
504 void endTransformFeedback();
508 int getNumFeedbackPrimitives(
int stream = 0);
512 bool hasFeedbackBufferOverflow(
int stream = 0);
515 bool isTransformFeedbackEnabled()
const;
517 bool isRasterizeEnabled()
const;
522 float getLineWidth()
const;
523 float getMaxSmoothLineWidth();
531 void setProgramPointSize(
bool enable);
532 bool getProgramPointSize()
const;
540 int pushDepthState();
541 void popDepthState(
int *nest =
nullptr);
545 void enableDepthBufferWriting();
546 void disableDepthBufferWriting();
547 bool getDepthBufferWriting();
548 void updateDepthBufferWriting();
551 void enableDepthTest();
552 void disableDepthTest();
554 void updateDepthTest();
559 void updateZFunction()
const;
563 void enableDepthClamp(
bool b);
564 bool getDepthClamp();
565 void updateDepthClamp();
567 void setDepthRange(
double nr,
double fr);
568 void getDepthRange(
double &nr,
double &fr)
const;
571 int pushStencilState();
572 void popStencilState(
int *nest =
nullptr);
574 void setStencil(
bool enable);
575 void setSClearValue(
int clearValue);
576 void setSWriteMask(
int writeMask);
581 void updateStencilState();
582 void resetSFunction();
583 void resetSWriteMask();
584 void resetSClearValue();
585 void resetSOperation();
588 void enableLogicOp();
589 void disableLogicOp();
594 int pushBlendState();
595 void popBlendState(
int *nesting = 0);
597 bool isBlending()
const;
598 void blend(
int onoff);
613 void blendAlpha(
int onoff = 1);
614 void blendAlphaPremult(
bool onoff =
true);
616 int pushSmoothLines();
617 void popSmoothLines(
int *nesting = 0);
620 void smoothBlendLinesNoFlagChange(
bool by_smooth);
623 int getBlendSmoothLevel()
const;
625 static void allowSmoothLines(
int yn);
626 static int allowsSmoothLines();
638 RE_Shader *override_mat_shader =
nullptr,
639 bool allow_partial_render =
false);
643 RE_Shader *override_mat_shader =
nullptr,
644 bool allow_partial_render =
false);
646 void popMaterial(
int *nest =
nullptr);
662 void popShader(
int *nest =
nullptr);
666 int pushShaderTransformFeedback(
RE_Shader *sh,
668 bool rasterize =
true,
669 int stream_bitfield = 0
x1);
672 bool rasterize =
true,
673 int stream_bitfield = 0
x1);
674 void popShaderTransformFeedback(
int *nest =
nullptr);
680 void setShaderOnlyMode(
bool enable);
681 void requestFixedFunction();
693 void setPatchVertices(
int num_verts);
702 bool setShaderSampleRate(
fpreal rate);
703 fpreal getShaderSampleRate()
const;
705 bool isSampleShading()
const;
733 { popUniform(bindex); }
739 void printBuiltInUniforms(
bool bound_only);
753 {
return myBuiltInUniformSerial; }
769 bool inverse_too =
false);
770 void popObjectMatrix();
775 void setFragmentDerivativeHint(
bool nicest);
776 bool getFragmentDerivativeHint();
783 void setConstAttribF32(
int loc,
int vsize,
const fpreal32 *
data);
786 void setConstAttribF32(
int loc,
int vsize,
const fpreal64 *
data);
789 void setConstAttribF64(
int loc,
int vsize,
const fpreal64 *
data);
792 void setConstAttribI32(
int loc,
int vsize,
const int32 *
data);
795 void setConstAttribU32(
int loc,
int vsize,
const uint32 *
data);
842 void setActiveTexture(
int textureunit);
843 int getActiveTexture()
const;
851 void popTextureState(
int *nest =
nullptr);
860 int findFirstFreeTextureUnit(
int starting_unit = 0)
const;
863 void updateTextureState()
const;
867 {
return myMaxTextureShaderUnits; }
869 {
return myMaxTextureVertexUnits; }
871 {
return myMaxTextureGeometryUnits; }
873 {
return myMaxTextureFragmentUnits; }
875 {
return myMaxTextureAnisotropy; }
880 {
return myMaxTextureSize; }
882 {
return myMaxTexture3DSize; }
884 {
return myMaxTextureRectSize; }
888 {
return myMaxColorBuffers; }
891 {
return myMaxDrawBuffers; }
894 void disableAllTextures();
898 bool bindImageTexture(
int image_unit,
903 void unbindImageTexture(
int image_unit);
909 int pushReadAlignment(
const void *
data,
int scansize);
910 void popReadAlignment(
int *nest =
nullptr);
912 int pushWriteAlignment(
const void *
data,
int scansize);
913 void popWriteAlignment(
int *nest =
nullptr);
916 void useSeamlessMaps(
bool enable);
917 bool usingSeamlessMaps();
928 int num_layers,
int size = 64 );
934 RE_OGLTexture *getRandomSampleMaskTexture(
unsigned int seed,
int nsamples,
941 int convert16bit = 0);
947 bool is3DLUTSupported()
const;
949 void buildRasterTextureGeometry(
955 void displayRasterTexture(
float x,
float y,
float z,
958 void displayRasterTexture(
float x,
float y,
float z,
962 void displayRasterTexture(
float x,
float y,
float z,
968 float alpha_mult=1.0
f);
974 void saveRaster(
int x,
int y,
int w,
int h,
978 bool use_backbuf =
true);
987 void setViewportFontOffset(
int x,
int y);
988 int getViewportFontOffsetX()
const;
989 int getViewportFontOffsetY()
const;
1012 bool region_support);
1013 void endConditionalRender();
1017 void enablePrimitiveRestart(
bool enable);
1018 void setPrimitiveRestartIndex(
unsigned int index);
1022 void drawViewportPoint(
const fpreal32 p[3],
1027 void drawViewportString(
const fpreal32 p[3],
1033 void postDrawViewportString();
1036 static void destroyShaderObject(
unsigned int progid,
bool unreg,
1038 static void destroyTextureObject(
unsigned int texid,
RE_OGLTexture *tex);
1039 static void destroyRenderbufferObject(
unsigned int rb);
1040 static void destroyBufferObject(
unsigned int buf);
1041 static void destroySync(
void *sync);
1043 static void clearCachedUniformBuffer(
int id);
1046 void destroyVertexArrayObject(
unsigned int vao);
1047 void destroyQuery(
unsigned int query);
1048 void destroyFramebufferObject(
unsigned int fbo);
1054 void unbindPipeline();
1059 void invalidateCachedState();
1070 void enableSubBufferDrawing(
bool enable);
1079 RE_OGLRender(
int do_foreground,
const char *appname = 0);
1083 #define RE_FLAG_STATE(RE_NAME,GL_FLAG) \
1084 void enable##RE_NAME () { if( myState.my##RE_NAME##State != 1 ) { ::glEnable( GL_FLAG ); myState.my##RE_NAME##State = 1; } } \
1085 void disable##RE_NAME () { if( myState.my##RE_NAME##State != 0 ) { ::glDisable( 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 () { myState.my##RE_NAME##State = ::glIsEnabled( GL_FLAG ); } \
1088 void invalidate##RE_NAME() { myState.my##RE_NAME##State = 3; }
1093 #undef RE_FLAG_STATE
1095 #define RE_FLAG_11_STATE(RE_NAME,GL_FLAG) \
1096 void enable##RE_NAME () { if( (myState.my##RE_NAME##State) != 1 && hasGL11() ) {::glEnable( GLenum(GL_FLAG) ); myState.my##RE_NAME##State = 1; } } \
1097 void disable##RE_NAME () { if( myState.my##RE_NAME##State && hasGL11() ) { ::glDisable( GLenum(GL_FLAG) ); myState.my##RE_NAME##State = 0; } } \
1098 bool get##RE_NAME () { if(myState.my##RE_NAME##State == 3) update##RE_NAME(); return (myState.my##RE_NAME##State==1) ; } \
1099 void update##RE_NAME () { if( hasGL11() ) { myState.my##RE_NAME##State = ::glIsEnabled( GLenum(GL_FLAG) ); } else { myState.my##RE_NAME##State = 0; } } \
1100 void invalidate##RE_NAME() { if(hasGL11()) myState.my##RE_NAME##State=3; }
1105 #undef RE_FLAG_11_STATE
1107 void updateOffsetAmount();
1109 static bool initGLVersionInfo();
1110 virtual void initGLState();
1111 virtual void initGLExtensions();
1112 virtual void updateGLState();
1113 virtual void updateStacks();
1116 static void determineTwinView();
1117 bool switchContextForRender(
bool ignore_errors);
1123 void updateBlendSmoothState();
1124 int privPushBlendSmoothState(
bool smooth_too);
1125 void privPopBlendSmoothState(
bool smooth_too,
int *idx);
1127 void setupDebugging();
1129 void freePendingObjects();
1133 void assignPushedUniforms();
1139 void updateViewport();
1145 static RE_SOperation oglToREsoperation(
int oglSOperation );
1148 static const char *bufferName(
GLint e);
1149 static const char *faceName(
GLint e);
1150 static const char *hintName(
GLint e);
1151 static const char *cullName(
GLint e);
1164 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1176 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1272 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1311 void suspendTestPatternRender();
1312 bool suspendTestPatternCheck();
1339 if(!myR->isContextLocked())
1341 myR->lockContextForRender();
1342 myLockedFlag =
true;
1350 myR->unlockContextAfterRender();
1447 return (
float)n /
dpi();
1475 if (ui_scale == 1.0)
1478 fpreal scaled_size = ui_scale * size + 0.5;
1479 if (scaled_size < 1.0)
1486 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1494 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1505 RE_OGLRender::getCurrentDrawable()
const {
return myCurDrawable; }
1508 RE_OGLRender::getCurrentDrawable() {
return myCurDrawable; }
1535 enablePointOffset();
1537 disablePointOffset();
1546 disableLineOffset();
1555 disableFillOffset();
int getMaxDrawBuffers() const
UT_IntArray myPendingDeleteFBOs
RE_OGLExt * getExt() const
static int scaledSize(int size)
static int getDriverMajorVersion()
GLboolean GLboolean GLboolean b
RE_PrimType getFeedbackMode() const
bool isRasterizeEnabled() const
int myDebugGroupStackSize
bool isInitialized() const
UT_Vector2F myLineWidthRange
bool isFrontBufferDirty() const
GLenum GLenum GLenum GLenum GLenum scale
void setPointSize(fpreal32 size)
OGLDrawable myPushedDrawable
GLenum GLuint GLint GLint layer
static int inchesToPixels(float i)
#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
#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...
GLenum GLsizei GLenum GLenum const void * image
static UT_Array< std::pair< RE_Visual *, RE_DisplayMode > > theVisuals
static int allowsSmoothLines()
UT_IntArray myPendingDeleteQueries
void pointOffset(bool onoff)
GLuint const GLchar * name
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
static RE_WindowList * theWindowList
GLubyte GLubyte GLubyte GLubyte w
GLdouble GLdouble GLdouble GLdouble q
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
int myMaxDebugGroupStackSize
RE_OGLTexture * mySuspendTestTexture
void getOffsetAmount(float *variable, float *constant) const
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()
GLint GLint GLsizei GLint GLenum GLenum type
int myMaxTextureGeometryUnits
int getBlendSmoothLevel() const
UT_IntArray & getBoundUniformBlocks()
RE_OcclusionQuery * myActiveQuery
int getMaxShaderTextureUnits() const
int getMaxVertexTextureUnits() const
void bumpBuiltInUniformSerial()
static RE_Window * theMainContextWindow
GLuint GLfloat GLfloat GLfloat x1
static int theDriverMajor
RE_Geometry * mySuspendBox
unsigned int RE_TextureID
GLuint GLint GLboolean layered
UT_StopWatch * mySuspendCheckTimer
bool contextIsValid() const
GLuint GLfloat GLfloat y0
bool myActiveConditionalRender
GLdouble GLdouble GLdouble z
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
#define RE_MAX_TEXTURE_STATE_STACK
UT_Array< RE_FeedbackPrimitivesWrittenQuery * > myTransformFeedbackWrittenQuery
int myViewportFontOffsetY
OPENVDB_API void initialize()
Global registration of basic types.
static UT_ThreadSpecificValue< RE_OGLRender * > theCurrentRender
void polygonOffset(bool onoff)
int myMaxTextureFragmentUnits
int myMaxTransformFeedbackComponents
static void allowSmoothLines(int yn)
RE_OGLFramebuffer * mySuspendResultFBO
bool myContextInitialized
int myMaxTextureVertexUnits
fpreal32 SYSrint(fpreal32 val)
GLuint GLfloat GLfloat GLfloat GLfloat y1
#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
GLenum GLuint GLenum GLsizei const GLchar * buf
static int theDotsPerInch
int myViewportFontOffsetX
int myShaderOnlyModeCount
static int theDriverBuildMajor
const RE_Render * getRender() const
GLint GLint GLsizei GLint GLenum format
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
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
GLsizei const GLfloat * value
static float pixelsToInches(int n)
static bool hasDriverVersion()
int64 getRenderCount() const
bool myTransformFeedbackEnabled
int getMaxVertexAttribs() const
static bool theUsingCoreProfile
RE_Window * mySavedMainThreadCurrentWindow
static bool hasGL3(int minor)
RE_OGLVertexArrayList * myCurrentVAO
GLint GLenum GLboolean GLsizei stride
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
GLfloat GLfloat GLfloat alpha
UT_Array< re_ConstVertexAttrib > myConstVertexAttribs
RE_Shader * myShaderOnlyActiveShader
#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()