VTK  9.6.20260209
vtkOpenGLRenderWindow.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
34
35#ifndef vtkOpenGLRenderWindow_h
36#define vtkOpenGLRenderWindow_h
37
38#include "vtkRect.h" // for vtkRecti
39#include "vtkRenderWindow.h"
40#include "vtkRenderingOpenGL2Module.h" // For export macro
41#include "vtkType.h" // for ivar
42#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
43#include <map> // for ivar
44#include <set> // for ivar
45#include <string> // for ivar
46
47VTK_ABI_NAMESPACE_BEGIN
48class vtkIdList;
51class vtkOpenGLHardwareSupport;
57class vtkTexture;
61class vtkOpenGLState;
63
64class VTKRENDERINGOPENGL2_EXPORT VTK_MARSHALAUTO vtkOpenGLRenderWindow : public vtkRenderWindow
65{
66public:
68#if !(defined(__APPLE__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__))
72#endif
73 void PrintSelf(ostream& os, vtkIndent indent) override;
74
78 void Start() override;
79
84 void Frame() override;
85
89 const char* GetRenderingBackend() override;
90
92
98
100
105 unsigned char* GetPixelData(int x, int y, int x2, int y2, int front, int right) override;
107 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right) override;
109 int x, int y, int x2, int y2, unsigned char* data, int front, int right) override;
111 int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front, int right) override;
113
115
118 float* GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right = 0) override;
120 int x, int y, int x2, int y2, int front, vtkFloatArray* data, int right = 0) override;
122 int x, int y, int x2, int y2, float* data, int front, int blend = 0, int right = 0) override;
123 int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray* data, int front, int blend = 0,
124 int right = 0) override;
125 void ReleaseRGBAPixelData(float* data) override;
126 unsigned char* GetRGBACharPixelData(
127 int x, int y, int x2, int y2, int front, int right = 0) override;
129 int x, int y, int x2, int y2, int front, vtkUnsignedCharArray* data, int right = 0) override;
130 int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char* data, int front,
131 int blend = 0, int right = 0) override;
132 int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray* data, int front,
133 int blend = 0, int right = 0) override;
135
137
140 float* GetZbufferData(int x1, int y1, int x2, int y2) override;
141 int GetZbufferData(int x1, int y1, int x2, int y2, float* z) override;
142 int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
143 int SetZbufferData(int x1, int y1, int x2, int y2, float* buffer) override;
144 int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray* buffer) override;
146
151
156
161
165 int GetDepthBufferSize() override;
166
171
176 int GetColorBufferSizes(int* rgba) override;
177
183 int GetColorBufferInternalFormat(int attachmentPoint);
184
188 virtual void OpenGLInit();
189
190 // Initialize the state of OpenGL that VTK wants for this window
191 virtual void OpenGLInitState();
192
193 // Initialize VTK for rendering in a new OpenGL context
194 virtual void OpenGLInitContext();
195
201 void GetOpenGLVersion(int& major, int& minor);
202
207
212
217
219
224
229
235
240 void WaitForCompletion() override;
241
245 virtual void DrawPixels(
246 int x1, int y1, int x2, int y2, int numComponents, int dataType, void* data);
247
252 virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin,
253 int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents,
254 int dataType, void* data);
255
260 virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void* data);
261
266
273 virtual bool IsPointSpriteBugPresent() { return false; }
274
285
292 int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB);
293
299 std::string GetOpenGLSupportMessage() { return this->OpenGLSupportMessage; }
300
304 int SupportsOpenGL() override;
305
309 const char* ReportCapabilities() override;
310
317 void Initialize() override {}
318
319 std::set<vtkGenericOpenGLResourceFreeCallback*> Resources;
320
322 {
323 std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
324 if (it == this->Resources.end())
325 {
326 this->Resources.insert(cb);
327 }
328 }
329
331 {
332 std::set<vtkGenericOpenGLResourceFreeCallback*>::iterator it = this->Resources.find(cb);
333 if (it != this->Resources.end())
334 {
335 this->Resources.erase(it);
336 }
337 }
338
348 virtual void PushContext() { this->MakeCurrent(); }
349 virtual void PopContext() {}
350
356
366 virtual bool SetSwapControl(int) { return false; }
367
368 // Get the state object used to keep track of
369 // OpenGL state
370 virtual vtkOpenGLState* GetState() { return this->State; }
371
372 // Get a VBO that can be shared by many
373 // It consists of normalized display
374 // coordinates for a quad and tcoords
376
377 // Activate and return thje texture unit for a generic 2d 64x64
378 // float greyscale noise texture ranging from 0 to 1. The texture is
379 // a hard-coded blue noise texture. This texture unit will automatically
380 // be deactivated at the end of the render process.
382
386 void End() override;
387
391 void Render() override;
392
397 void StereoMidpoint() override;
398
399 // does VTKs framebuffer require resolving for reading pixels
401
407
413
419
423 void BlitDisplayFramebuffer(int right, int srcX, int srcY, int srcWidth, int srcHeight, int destX,
424 int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
425
427
431 void BlitToRenderFramebuffer(bool includeDepth);
432 void BlitToRenderFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int destX,
433 int destY, int destWidth, int destHeight, int bufferMode, int interpolation);
435
441 {
442 BlitToHardware, // hardware buffers
443 BlitToCurrent, // currently bound draw framebuffer, without depth buffer
444 BlitToCurrentWithDepth, // currently bound draw framebuffer, including depth buffer
445 NoBlit // no blit, GUI or external code will handle the blit
446 };
447
449
484
486
489 vtkSetMacro(FramebufferFlipY, bool);
490 vtkGetMacro(FramebufferFlipY, bool);
491 vtkBooleanMacro(FramebufferFlipY, bool);
493
495
501
503 // copy depth values from a source framebuffer to a destination framebuffer
504 // using texture maps to do the copy. The source framebufferobject must be texture
505 // backed. This method is designed to work around issues with trying to blit depth
506 // values between framebuffers that have different depth formats.
507
508 // blit entire source texture to active viewport
510
511 // blit specified source texels to active viewport
512 virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2);
513
514 // blit specified source texels to specified viewport
515 virtual void TextureDepthBlit(vtkTextureObject* source, int srcX, int srcY, int srcX2, int srcY2,
516 int destX, int destY, int destX2, int destY2);
518
519 typedef void (*VTKOpenGLAPIProc)();
520 typedef VTKOpenGLAPIProc (*VTKOpenGLLoaderFunction)(void* userptr, const char* name);
531 void SetOpenGLSymbolLoader(VTKOpenGLLoaderFunction loader, void* userData);
532
548 void SetOpenGLSymbolLoader2(long long toolGetProcAddressFunc, long long glLibHandle);
549
550protected:
553
554 // blits the display buffers to the appropriate hardware buffers
556
557 // when frame is called, at the end blit to the hardware buffers
559
560 // a FSQ we use to resolve MSAA that handles gamma
562
563 // a FSQ we use to blit depth values
565
566 // a FSQ we use to flip framebuffer texture
568
569 // a FSQ we use to read depth component on platforms with OpenGL ES implementations
570 // because `glReadPixels` cannot be used to read GL_DEPTH_COMPONENT
572
573 // flip quad helpers Y tcoord
575
576 // resolve and flip renderframebuffer as needed
577 // when copying to displayframebuffer. Returns
578 // true if the color buffer was copied.
580
581 // On GLES, the depth attachment buffer cannot be downloaded from
582 // the GPU with `glReadPixels`.
583 // This method reads the depth buffer bits.
584 // The depth attachment size can be 8,16,24 or 32. The values are split into 4 8-bit numbers.
585 // These are stored in the form of an RGBA color attachment in DepthFrameBuffer.
586 // `glReadPixels` can read that RGBA format and reconstruct full 8,16,24 or 32-bit integer
587 // followed by scaling down to 0-1.
588 bool ReadDepthComponent(int depthSize);
589
590 // used in testing for opengl support
591 // in the SupportsOpenGL() method
595
596 virtual int ReadPixels(
597 const vtkRecti& rect, int front, int glFormat, int glType, void* data, int right = 0);
598
607 int CreateFramebuffers(int width, int height);
610
611 // used when we need to resolve a multisampled
612 // framebuffer
614
615 // used when we need to read depth component
616 // with OpenGL ES 3
618
622 virtual void CreateAWindow() = 0;
623
627 virtual void DestroyWindow() = 0;
628
633
638
639 std::map<std::string, int> GLStateIntegers;
640
645
647
649
651
653
654 // used for fast quad rendering
656
657 // noise texture
659
661
662 // keep track of in case we need to recreate the framebuffer
664
665 // how much bits to use for depth of created Framebuffers
667
669
670 struct
671 {
673 void* UserData = nullptr;
674 } SymbolLoader;
675
676 typedef VTKOpenGLAPIProc (*VTKOpenGLGetProcAddress)(const char* name);
678 {
680 void* libHandle = nullptr;
681 } FuncResolverState;
682
683private:
685 void operator=(const vtkOpenGLRenderWindow&) = delete;
686
687 // Keeping `State` private so the only way to access it is through
688 // `this->GetState()`.
689 vtkOpenGLState* State;
690};
691#if !(defined(__APPLE__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__))
692#define vtkOpenGLRenderWindow_OVERRIDE_ATTRIBUTES vtkOpenGLRenderWindow::CreateOverrideAttributes()
693#endif
694VTK_ABI_NAMESPACE_END
695#endif
dynamic, self-adjusting array of float
list of point or cell ids
Definition vtkIdList.h:133
a simple class to control print indentation
Definition vtkIndent.h:108
OpenGL buffer object.
Internal class which encapsulates OpenGL FramebufferObject.
Class to make rendering a full screen quad easier.
OpenGL rendering window.
void Start() override
Begin the rendering process.
void SetOpenGLSymbolLoader2(long long toolGetProcAddressFunc, long long glLibHandle)
Provide an indirect function pointer which can load OpenGL core/extension functions.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of NULL means the context may alre...
int GetColorBufferInternalFormat(int attachmentPoint)
Get the internal format of current attached texture or render buffer.
int SetRGBACharPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
virtual void DrawPixels(int dstXmin, int dstYmin, int dstXmax, int dstYmax, int srcXmin, int srcYmin, int srcXmax, int srcYmax, int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function, but it allows for scaling the data and using only part...
vtkOpenGLFramebufferObject * DisplayFramebuffer
std::map< std::string, int > GLStateIntegers
std::string GetOpenGLSupportMessage()
Return a message profiding additional details about the results of calling SupportsOpenGL() This can ...
int GetRGBAPixelData(int x, int y, int x2, int y2, int front, vtkFloatArray *data, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkTextureUnitManager * GetTextureUnitManager()
Returns its texture unit manager object.
bool ReadDepthComponent(int depthSize)
vtkOpenGLQuadHelper * DepthReadQuad
virtual void DrawPixels(int x1, int y1, int x2, int y2, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function.
void Initialize() override
Initialize the rendering window.
int SetRGBAPixelData(int x, int y, int x2, int y2, float *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void SetOpenGLSymbolLoader(VTKOpenGLLoaderFunction loader, void *userData)
Provide a function pointer which can load OpenGL core/extension functions.
int GetTextureUnitForTexture(vtkTextureObject *)
Get the texture unit for a given texture object.
VTKOpenGLAPIProc(* VTKOpenGLGetProcAddress)(const char *name)
const char * GetRenderingBackend() override
What rendering backend has the user requested.
void RegisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
virtual void DestroyWindow()=0
Destroy a not-off-screen window.
FrameBlitModes
Define how the resulting image should be blitted when at the end of the Frame() call if SwapBuffers i...
float * GetZbufferData(int x1, int y1, int x2, int y2) override
Set/Get the zbuffer data from an image.
virtual void TextureDepthBlit(vtkTextureObject *source)
vtkTypeBool OwnContext
Flag telling if the context has been created here or was inherited.
int GetZbufferData(int x1, int y1, int x2, int y2, float *z) override
Set/Get the zbuffer data from an image.
virtual void TextureDepthBlit(vtkTextureObject *source, int srcX, int srcY, int srcX2, int srcY2, int destX, int destY, int destX2, int destY2)
void StereoMidpoint() override
Intermediate method performs operations required between the rendering of the left and right eye.
vtkTextureObject * NoiseTextureObject
vtkOpenGLFramebufferObject * ResolveFramebuffer
int GetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
void End() override
Update the system, if needed, at end of render process.
unsigned char * GetPixelData(int x, int y, int x2, int y2, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB... front in this context indicates that the...
VTKOpenGLAPIProc(* VTKOpenGLLoaderFunction)(void *userptr, const char *name)
void BlitToRenderFramebuffer(bool includeDepth)
Blit the currently bound read buffer to the renderbuffer.
static void SetGlobalMaximumNumberOfMultiSamples(int val)
Set/Get the maximum number of multisamples.
virtual float GetMaximumHardwareLineWidth()
Return the largest line width supported by the hardware.
int GetDefaultTextureInternalFormat(int vtktype, int numComponents, bool needInteger, bool needFloat, bool needSRGB)
Get a mapping of vtk data types to native texture formats for this window we put this on the RenderWi...
void ActivateTexture(vtkTextureObject *)
Activate a texture unit for this texture.
vtkTextureObject * DrawPixelsTextureObject
vtkOpenGLFramebufferObject * DepthFramebuffer
bool GetUsingSRGBColorSpace()
Is this window/fo in sRGB colorspace.
int GetColorBufferSizes(int *rgba) override
Get the size of the color buffer.
int SetPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB... front in this context indicates that the...
static vtkOpenGLRenderWindow * New()
int SetRGBACharPixelData(int x, int y, int x2, int y2, unsigned char *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkOpenGLBufferObject * GetTQuad2DVBO()
void Render() override
Handle opengl specific code and calls superclass.
void UnregisterGraphicsResources(vtkGenericOpenGLResourceFreeCallback *cb)
void BlitDisplayFramebuffer(int right, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int bufferMode, int interpolation)
Blit a display buffer into a currently bound draw destination.
void Frame() override
A termination method performed at the end of the rendering process to do things like swapping buffers...
virtual bool IsPointSpriteBugPresent()
Returns true if driver has an EGL/OpenGL bug that makes vtkChartsCoreCxx-TestChartDoubleColors and ot...
void ReleaseRGBAPixelData(float *data) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
std::set< vtkGenericOpenGLResourceFreeCallback * > Resources
virtual void OpenGLInitContext()
vtkOpenGLQuadHelper * DepthBlitQuad
VTKOpenGLLoaderFunction LoadFunction
virtual void TextureDepthBlit(vtkTextureObject *source, int srcX, int srcY, int srcX2, int srcY2)
void WaitForCompletion() override
Block the thread until the actual rendering is finished().
virtual bool ResolveFlipRenderFramebuffer()
virtual void PushContext()
Ability to push and pop this window's context as the current context.
unsigned char * GetRGBACharPixelData(int x, int y, int x2, int y2, int front, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
vtkOpenGLQuadHelper * FlipQuad
virtual void OpenGLInitState()
vtkOpenGLFramebufferObject * RenderFramebuffer
static int GetGlobalMaximumNumberOfMultiSamples()
Set/Get the maximum number of multisamples.
virtual vtkOpenGLState * GetState()
virtual void CreateAWindow()=0
Create a not-off-screen window.
float * GetRGBAPixelData(int x, int y, int x2, int y2, int front, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void BlitToRenderFramebuffer(int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int bufferMode, int interpolation)
Blit the currently bound read buffer to the renderbuffer.
virtual int ReadPixels(const vtkRecti &rect, int front, int glFormat, int glType, void *data, int right=0)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void SetFrameBlitMode(FrameBlitModes)
SetGet how to handle blits at the end of a Frame() call.
int SupportsOpenGL() override
Does this render window support OpenGL?
int SetZbufferData(int x1, int y1, int x2, int y2, vtkFloatArray *buffer) override
Set/Get the zbuffer data from an image.
virtual vtkMTimeType GetContextCreationTime()
Get the time when the OpenGL context was created.
int SetPixelData(int x, int y, int x2, int y2, vtkUnsignedCharArray *data, int front, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB... front in this context indicates that the...
int GetDepthBufferSize() override
Get the size of the depth buffer.
void SetFrameBlitModeToBlitToCurrent()
SetGet how to handle blits at the end of a Frame() call.
bool InitializeFromCurrentContext() override
Initialize the render window from the information associated with the currently activated OpenGL cont...
static vtkOverrideAttribute * CreateOverrideAttributes()
virtual bool SetSwapControl(int)
Set the number of vertical syncs required between frames.
vtkOpenGLBufferObject * TQuad2DVBO
~vtkOpenGLRenderWindow() override
void BlitDisplayFramebufferColorAndDepth()
Blit a display framebuffer into a currently bound draw destination, color and depth.
const char * ReportCapabilities() override
Get report of capabilities for the render window.
void SetFrameBlitModeToNoBlit()
SetGet how to handle blits at the end of a Frame() call.
vtkOpenGLShaderCache * GetShaderCache()
Returns an Shader Cache object.
vtkOpenGLVertexBufferObjectCache * GetVBOCache()
Returns the VBO Cache.
int CreateFramebuffers(int width, int height)
Create the offScreen framebuffers or resize them if they are already created.
bool IsPrimIDBugPresent()
On gl_PrimitiveID, the spec says it is a counter that is incremented after every individual point,...
virtual void OpenGLInit()
Initialize OpenGL for this window.
int SetZbufferData(int x1, int y1, int x2, int y2, float *buffer) override
Set/Get the zbuffer data from an image.
void BlitDisplayFramebuffer()
Blit a display framebuffer into a currently bound draw destination, color only.
virtual void BlitDisplayFramebuffersToHardware()
void DeactivateTexture(vtkTextureObject *)
Deactivate a previously activated texture.
void RestoreGLState()
Restore OpenGL state at end of the rendering.
void GetOpenGLVersion(int &major, int &minor)
Get the major and minor version numbers of the OpenGL context we are using ala 3.2,...
void SaveGLState()
Query and save OpenGL state.
int SetRGBAPixelData(int x, int y, int x2, int y2, vtkFloatArray *data, int front, int blend=0, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void SetFrameBlitModeToBlitToCurrentWithDepth()
SetGet how to handle blits at the end of a Frame() call.
int GetRGBACharPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right=0) override
Set/Get the pixel data of an image, transmitted as RGBARGBA...
void SetFrameBlitModeToBlitToHardware()
SetGet how to handle blits at the end of a Frame() call.
int GetPixelData(int x, int y, int x2, int y2, int front, vtkUnsignedCharArray *data, int right) override
Set/Get the pixel data of an image, transmitted as RGBRGB... front in this context indicates that the...
virtual void DrawPixels(int srcWidth, int srcHeight, int numComponents, int dataType, void *data)
Replacement for the old glDrawPixels function.
vtkOpenGLQuadHelper * ResolveQuad
manage Shader Programs within a context
OpenGL state storage.
The VertexArrayObject class uses, or emulates, vertex array objects.
manage vertex buffer objects shared within a context
Attribute for vtkObjectFactory overrides.
The ShaderProgram uses one or more Shader objects.
abstracts an OpenGL texture object.
allocate/free texture units.
handles properties associated with a texture map
Definition vtkTexture.h:168
record modification and/or execution time
dynamic, self-adjusting array of unsigned char
virtual void MakeCurrent()
Make the window current.
Definition vtkWindow.h:274
int vtkTypeBool
Definition vtkABI.h:64
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:309
#define VTK_MARSHALAUTO
#define VTK_NEWINSTANCE