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);
836 void setActiveTexture(
int textureunit);
837 int getActiveTexture()
const;
845 void popTextureState(
int *nest =
nullptr);
854 int findFirstFreeTextureUnit(
int starting_unit = 0)
const;
857 void updateTextureState()
const;
861 {
return myMaxTextureShaderUnits; }
863 {
return myMaxTextureVertexUnits; }
865 {
return myMaxTextureGeometryUnits; }
867 {
return myMaxTextureFragmentUnits; }
869 {
return myMaxTextureAnisotropy; }
874 {
return myMaxTextureSize; }
876 {
return myMaxTexture3DSize; }
878 {
return myMaxTextureRectSize; }
882 {
return myMaxColorBuffers; }
885 {
return myMaxDrawBuffers; }
888 void disableAllTextures();
892 bool bindImageTexture(
int image_unit,
897 void unbindImageTexture(
int image_unit);
903 int pushReadAlignment(
const void *
data,
int scansize);
904 void popReadAlignment(
int *nest =
nullptr);
906 int pushWriteAlignment(
const void *
data,
int scansize);
907 void popWriteAlignment(
int *nest =
nullptr);
910 void useSeamlessMaps(
bool enable);
911 bool usingSeamlessMaps();
922 int num_layers,
int size = 64 );
928 RE_OGLTexture *getRandomSampleMaskTexture(
unsigned int seed,
int nsamples,
934 void convertRasterToTexture(
PXL_Raster *raster,
935 int convert16bit = 0);
941 bool is3DLUTSupported()
const;
943 void buildRasterTextureGeometry(
949 void displayRasterTexture(
float x,
float y,
float z,
952 void displayRasterTexture(
float x,
float y,
float z,
956 void displayRasterTexture(
float x,
float y,
float z,
962 float alpha_mult=1.0
f);
968 void saveRaster(
int x,
int y,
int w,
int h,
972 bool use_backbuf =
true);
981 void setViewportFontOffset(
int x,
int y);
982 int getViewportFontOffsetX()
const;
983 int getViewportFontOffsetY()
const;
1006 bool region_support);
1007 void endConditionalRender();
1011 void enablePrimitiveRestart(
bool enable);
1012 void setPrimitiveRestartIndex(
unsigned int index);
1016 void drawViewportPoint(
const fpreal32 p[3],
1021 void drawViewportString(
const fpreal32 p[3],
1027 void postDrawViewportString();
1030 static void destroyShaderObject(
unsigned int progid,
bool unreg,
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);
1037 static void clearCachedUniformBuffer(
int id);
1040 void destroyVertexArrayObject(
unsigned int vao);
1041 void destroyQuery(
unsigned int query);
1042 void destroyFramebufferObject(
unsigned int fbo);
1048 void unbindPipeline();
1053 void invalidateCachedState();
1067 RE_OGLRender(
int do_foreground,
const char *appname = 0);
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; }
1081 #undef RE_FLAG_STATE
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; }
1093 #undef RE_FLAG_11_STATE
1095 void updateOffsetAmount();
1097 static bool initGLVersionInfo();
1098 virtual void initGLState();
1099 virtual void initGLExtensions();
1100 virtual void updateGLState();
1101 virtual void updateStacks();
1104 static void determineTwinView();
1105 bool switchContextForRender(
bool ignore_errors);
1111 void updateBlendSmoothState();
1112 int privPushBlendSmoothState(
bool smooth_too);
1113 void privPopBlendSmoothState(
bool smooth_too,
int *idx);
1115 void setupDebugging();
1117 void freePendingObjects();
1121 void assignPushedUniforms();
1127 void updateViewport();
1133 static RE_SOperation oglToREsoperation(
int oglSOperation );
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);
1152 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1164 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1260 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1297 void suspendTestPatternRender();
1298 bool suspendTestPatternCheck();
1325 if(!myR->isContextLocked())
1327 myR->lockContextForRender();
1328 myLockedFlag =
true;
1336 myR->unlockContextAfterRender();
1433 return (
float)n /
dpi();
1461 if (ui_scale == 1.0)
1464 fpreal scaled_size = ui_scale * size + 0.5;
1465 if (scaled_size < 1.0)
1472 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1480 #if !defined(EXPERIMENTAL_GL_DRAWABLE_FEEL)
1491 RE_OGLRender::getCurrentDrawable()
const {
return myCurDrawable; }
1494 RE_OGLRender::getCurrentDrawable() {
return myCurDrawable; }
1521 enablePointOffset();
1523 disablePointOffset();
1532 disableLineOffset();
1541 disableFillOffset();
int getMaxDrawBuffers() const
UT_IntArray myPendingDeleteFBOs
RE_OGLExt * getExt() const
static int scaledSize(int size)
static int getDriverMajorVersion()
RE_PrimType getFeedbackMode() const
bool isRasterizeEnabled() const
int myDebugGroupStackSize
bool isInitialized() const
UT_Vector2F myLineWidthRange
bool isFrontBufferDirty() const
GLuint const GLchar * name
GLclampf GLclampf GLclampf alpha
void setPointSize(fpreal32 size)
OGLDrawable myPushedDrawable
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
GLenum GLenum GLenum GLenum GLenum scale
bool myDebugLabelSupported
int64 myBuiltInUniformSerial
GLuint GLfloat GLfloat GLfloat x1
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static UT_Array< std::pair< RE_Visual *, RE_DisplayMode > > theVisuals
static int allowsSmoothLines()
UT_IntArray myPendingDeleteQueries
void pointOffset(bool onoff)
UT_IntArray myClipDistance
int myMaxTextureAnisotropy
UT_RecursiveSpinLock myOpenGLLock
GLenum GLsizei GLenum GLenum const void * image
int getViewportFontOffsetX() const
#define GL_POLYGON_OFFSET_POINT
static int glMinorVersion()
static RE_GraphicsDevice getGraphicsDevice()
void lineOffset(bool onoff)
static int minorGLVersion
static RE_WindowList * theWindowList
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()
int myMaxTextureGeometryUnits
int getBlendSmoothLevel() const
UT_IntArray & getBoundUniformBlocks()
RE_OcclusionQuery * myActiveQuery
int getMaxShaderTextureUnits() const
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
#define GL_POLYGON_OFFSET_FILL
int getMaxVertexTextureUnits() const
void bumpBuiltInUniformSerial()
static RE_Window * theMainContextWindow
GLint GLenum GLsizei GLint GLsizei const void * data
static int theDriverMajor
RE_Geometry * mySuspendBox
unsigned int RE_TextureID
UT_StopWatch * mySuspendCheckTimer
GLubyte GLubyte GLubyte GLubyte w
bool contextIsValid() const
bool myActiveConditionalRender
static RE_Server * theServer
UT_ArrayMap< int, RE_OGLFramebuffer * > myFBOTable
int getViewportFontOffsetY() const
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
GLuint GLfloat GLfloat y0
int myViewportFontOffsetY
GLfloat GLfloat GLfloat GLfloat h
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)
GLuint GLuint GLsizei GLenum type
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
GLdouble GLdouble GLdouble b
const RE_Render * getRender() const
static int getDriverBuildMajorVersion()
static bool theSmoothLinesAllowed
RE_RenderAutoLock(RE_OGLRender *r)
GLenum GLenum GLenum dppass
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
#define GL_POLYGON_OFFSET_LINE
static int theDriverMinor
const RE_Window * getCurrentWindow() const
static bool hasGL4(int minor)
bool isDebugLabelSupported() const
int myMaxTextureShaderUnits
GLdouble GLdouble GLdouble r
fpreal myShaderSampleRate
GLuint GLfloat GLfloat GLfloat GLfloat y1
GLint GLboolean GLint layer
int getTextureAnisotropyLimit() const
ut_thread_id_t myNativeThread
int myMaxTransformFeedbackBuffers
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
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
GLenum GLuint GLsizei const GLchar * buf
GLsizei const GLfloat * value
#define RE_BUFFER_STACK_SIZE
RE_OGLVertexArrayList * myDefaultVAO
RE_OGLContext pushedGraphicsContext
bool myMultisampleAlphaToCoverage
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.
static int glMajorVersion()