From 13956bf0d47391046e7bb08bb0b581d0850738a9 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Tue, 23 Jun 2020 14:31:15 -0400 Subject: [PATCH] clean up some old opengl es stuff No longer have the version option so remove Partially implement 1D textures as 2D --- Examples/Android/ReadMe.txt | 6 +- Rendering/OpenGL2/CMakeLists.txt | 6 +- Rendering/OpenGL2/vtkTextureObject.cxx | 95 +++++++++++++++++++++++++- ThirdParty/glew/vtk_glew.h.in | 45 ++++++------ 4 files changed, 118 insertions(+), 34 deletions(-) diff --git a/Examples/Android/ReadMe.txt b/Examples/Android/ReadMe.txt index 7b43476bdd..9c6f5a102d 100644 --- a/Examples/Android/ReadMe.txt +++ b/Examples/Android/ReadMe.txt @@ -41,10 +41,6 @@ To build VTK and these examples follow the steps below. * Run cmake on vtkandroid with -DVTK_ANDROID_BUILD=ON, if you use the gui add a * boolean entry with that name prior to configuring and set it on. -If you want OpenGL ES 3.0 support make sure to change the setting of -OPENGL_ES_VERSION to 3.0. Volume Rendering requires ES 3.0. Make sure to turn on -VTK_BUILD_EXAMPLES - * configure and generate as usual * Once done run ninja or make as appropriate @@ -60,4 +56,4 @@ cd into CMakeExternals/Build/vtk-android/Examples/Android/ExampleName/bin You should see some apk files in this directory. -You can adb install -r ExampleName-debug.apk and then run the example on your device \ No newline at end of file +You can adb install -r ExampleName-debug.apk and then run the example on your device diff --git a/Rendering/OpenGL2/CMakeLists.txt b/Rendering/OpenGL2/CMakeLists.txt index da43adb85f..0ea0ee3200 100644 --- a/Rendering/OpenGL2/CMakeLists.txt +++ b/Rendering/OpenGL2/CMakeLists.txt @@ -3,6 +3,7 @@ set(classes vtkClearRGBPass vtkClearZPass vtkCompositePolyDataMapper2 + vtkDataTransferHelper vtkDefaultPass vtkDepthImageProcessingPass vtkDepthOfFieldPass @@ -93,11 +94,6 @@ set(classes vtkValuePass vtkVolumetricPass) -if (NOT DEFINED OPENGL_ES_VERSION) - list(APPEND classes - vtkDataTransferHelper) -endif() - set(headers vtkCompositePolyDataMapper2Internal.h vtkOpenGL.h vtkStateStorage.h diff --git a/Rendering/OpenGL2/vtkTextureObject.cxx b/Rendering/OpenGL2/vtkTextureObject.cxx index 6afef26d97..b491c62e89 100644 --- a/Rendering/OpenGL2/vtkTextureObject.cxx +++ b/Rendering/OpenGL2/vtkTextureObject.cxx @@ -1030,6 +1030,99 @@ bool vtkTextureObject::CreateTextureBuffer( #else +// Emulate 1D textures as 2D. Note that the any shader code will likely +// have to be modified as well for this to work. + +//------------------------------------------------------------------------------ +bool vtkTextureObject::Create1D( + int numComps, vtkPixelBufferObject* pbo, bool shaderSupportsTextureInt) +{ + assert(this->Context); + assert(pbo->GetContext() == this->Context.GetPointer()); + + GLenum target = GL_TEXTURE_2D; + + // Now, determine texture parameters using the information from the pbo. + + // * internalFormat depends on number of components and the data type. + GLenum internalFormat = + this->GetInternalFormat(pbo->GetType(), numComps, shaderSupportsTextureInt); + + // * format depends on the number of components. + GLenum format = this->GetFormat(pbo->GetType(), numComps, shaderSupportsTextureInt); + + // * type if the data type in the pbo + GLenum type = this->GetDefaultDataType(pbo->GetType()); + + if (!internalFormat || !format || !type) + { + vtkErrorMacro("Failed to determine texture parameters."); + return false; + } + + this->Target = target; + this->Context->ActivateTexture(this); + this->CreateTexture(); + this->Bind(); + + pbo->Bind(vtkPixelBufferObject::UNPACKED_BUFFER); + + // Source texture data from the PBO. + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(target, 0, static_cast(internalFormat), + static_cast(pbo->GetSize() / static_cast(numComps)), 1, 0, format, type, + BUFFER_OFFSET(0)); + vtkOpenGLCheckErrorMacro("failed at glTexImage1D"); + pbo->UnBind(); + this->Deactivate(); + + this->Target = target; + this->Format = format; + this->Type = type; + this->Components = numComps; + this->Width = pbo->GetSize(); + this->Height = 1; + this->Depth = 1; + this->NumberOfDimensions = 1; + return true; +} + +//------------------------------------------------------------------------------ +bool vtkTextureObject::Create1DFromRaw(unsigned int width, int numComps, int dataType, void* data) +{ + assert(this->Context); + + // Now determine the texture parameters using the arguments. + this->GetDataType(dataType); + this->GetInternalFormat(dataType, numComps, false); + this->GetFormat(dataType, numComps, false); + + if (!this->InternalFormat || !this->Format || !this->Type) + { + vtkErrorMacro("Failed to determine texture parameters."); + return false; + } + + GLenum target = GL_TEXTURE_2D; + this->Target = target; + this->Components = numComps; + this->Width = width; + this->Height = 1; + this->Depth = 1; + this->NumberOfDimensions = 1; + this->Context->ActivateTexture(this); + this->CreateTexture(); + this->Bind(); + + glTexImage2D(this->Target, 0, this->InternalFormat, static_cast(this->Width), 1, 0, + this->Format, this->Type, static_cast(data)); + + vtkOpenGLCheckErrorMacro("failed at glTexImage1D"); + + this->Deactivate(); + return true; +} + // Description: // Create a texture buffer basically a 1D texture that can be // very large for passing data into the fragment shader @@ -1037,7 +1130,7 @@ bool vtkTextureObject::CreateTextureBuffer( unsigned int numValues, int numComps, int dataType, vtkOpenGLBufferObject* bo) { assert(this->Context); - vtkErrorMacro("TextureBuffers not supported in OPenGL ES"); + vtkErrorMacro("TextureBuffers not supported in OpenGL ES"); // TODO: implement 1D and Texture buffers using 2D textures return false; } diff --git a/ThirdParty/glew/vtk_glew.h.in b/ThirdParty/glew/vtk_glew.h.in index 6aa8c2ee9e..009f230b19 100644 --- a/ThirdParty/glew/vtk_glew.h.in +++ b/ThirdParty/glew/vtk_glew.h.in @@ -35,42 +35,41 @@ #endif #if VTK_MODULE_vtkglew_GLES3 -# include +#include #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR -# include +#include #elif VTK_MODULE_USE_EXTERNAL_vtkglew -# include -# ifdef _WIN32 -# include -# endif +#include +#ifdef _WIN32 +#include +#endif #else -# include -# ifdef _WIN32 -# include -# endif +#include +#ifdef _WIN32 +#include +#endif #endif /* some fixes for both ES 2 and 3 */ #ifdef GL_ES_VERSION_3_0 -# define glDrawBuffer(arg) -# define GL_BACK_LEFT 0 -# define GL_BACK_RIGHT 0 -# define GL_FRONT_LEFT 0 -# define GL_FRONT_RIGHT 0 +#define glDrawBuffer(arg) +#define GL_BACK_LEFT 0 +#define GL_BACK_RIGHT 0 +#define GL_FRONT_LEFT 0 +#define GL_FRONT_RIGHT 0 /* this sends all the data each time as opposed to allowing a subset */ -# define glMultiDrawElements(mode, counts, type, indicies, primcount) \ - for (size_t eCount = 0; eCount < primcount; ++eCount) \ - { \ - glDrawElements(mode, *(counts + eCount), \ - type, (GLvoid *)(indicies[eCount])); \ - } +#define glMultiDrawElements(mode, counts, type, indicies, primcount) \ + for (size_t eCount = 0; eCount < primcount; ++eCount) \ + { \ + glDrawElements(mode, *(counts + eCount), type, (GLvoid*)(indicies[eCount])); \ + } #endif /*** deal with some GLES 3.0 specific issues ***/ #ifdef GL_ES_VERSION_3_0 -# define GLEW_ARB_vertex_array_object 1 -# define GLEW_ARB_instanced_arrays 1 +#define GLEW_ARB_vertex_array_object 1 +#define GLEW_ARB_instanced_arrays 1 #endif #endif -- 2.27.0