| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2020 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | #include "BLI_assert.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | #include "gpu_texture_private.hh"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | #include "glew-mx.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | struct GPUFrameBuffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | namespace blender { | 
					
						
							|  |  |  | namespace gpu { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | class GLTexture : public Texture { | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   friend class GLStateManager; | 
					
						
							| 
									
										
										
										
											2020-09-08 03:22:35 +02:00
										 |  |  |   friend class GLFrameBuffer; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:31:53 +02:00
										 |  |  |   /** All samplers states. */ | 
					
						
							|  |  |  |   static GLuint samplers_[GPU_SAMPLER_MAX]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-26 21:35:18 +10:00
										 |  |  |   /** Target to bind the texture to (#GL_TEXTURE_1D, #GL_TEXTURE_2D, etc...). */ | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   GLenum target_ = -1; | 
					
						
							|  |  |  |   /** opengl identifier for texture. */ | 
					
						
							|  |  |  |   GLuint tex_id_ = 0; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   /** Legacy workaround for texture copy. Created when using framebuffer_get(). */ | 
					
						
							|  |  |  |   struct GPUFrameBuffer *framebuffer_ = NULL; | 
					
						
							|  |  |  |   /** True if this texture is bound to at least one texture unit. */ | 
					
						
							| 
									
										
										
										
											2020-09-19 14:32:41 +10:00
										 |  |  |   /* TODO(fclem): How do we ensure thread safety here? */ | 
					
						
							| 
									
										
										
										
											2020-09-05 18:13:33 +02:00
										 |  |  |   bool is_bound_ = false; | 
					
						
							| 
									
										
										
										
											2021-11-20 15:09:01 +01:00
										 |  |  |   /** True if pixels in the texture have been initialized. */ | 
					
						
							|  |  |  |   bool has_pixels_ = false; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   GLTexture(const char *name); | 
					
						
							|  |  |  |   ~GLTexture(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   void update_sub( | 
					
						
							| 
									
										
										
										
											2020-09-07 13:59:22 +02:00
										 |  |  |       int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) override; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * This will create the mipmap images and populate them with filtered data from base level. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * \warning Depth textures are not populated but they have their mips correctly defined. | 
					
						
							|  |  |  |    * \warning This resets the mipmap range. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   void generate_mipmap() override; | 
					
						
							| 
									
										
										
										
											2020-09-07 13:59:22 +02:00
										 |  |  |   void copy_to(Texture *dst) override; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   void clear(eGPUDataFormat format, const void *data) override; | 
					
						
							|  |  |  |   void swizzle_set(const char swizzle_mask[4]) override; | 
					
						
							|  |  |  |   void mip_range_set(int min, int max) override; | 
					
						
							| 
									
										
										
										
											2020-09-07 13:59:22 +02:00
										 |  |  |   void *read(int mip, eGPUDataFormat type) override; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   void check_feedback_loop(); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:36:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 14:32:41 +10:00
										 |  |  |   /* TODO(fclem): Legacy. Should be removed at some point. */ | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   uint gl_bindcode_get() const override; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   static void samplers_init(); | 
					
						
							|  |  |  |   static void samplers_free(); | 
					
						
							|  |  |  |   static void samplers_update(); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:31:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  |   /** Return true on success. */ | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   bool init_internal() override; | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  |   /** Return true on success. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   bool init_internal(GPUVertBuf *vbo) override; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2020-09-04 02:36:56 +02:00
										 |  |  |   bool proxy_check(int mip); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  |   /** Will create enough mipmaps up to get to the given level. */ | 
					
						
							| 
									
										
										
										
											2020-09-04 02:36:56 +02:00
										 |  |  |   void ensure_mipmaps(int mip); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:36:00 +02:00
										 |  |  |   void update_sub_direct_state_access( | 
					
						
							|  |  |  |       int mip, int offset[3], int extent[3], GLenum gl_format, GLenum gl_type, const void *data); | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   GPUFrameBuffer *framebuffer_get(); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   MEM_CXX_CLASS_ALLOC_FUNCS("GLTexture") | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | inline GLenum to_gl_internal_format(eGPUTextureFormat format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* You can add any of the available type to this list
 | 
					
						
							|  |  |  |    * For available types see GPU_texture.h */ | 
					
						
							|  |  |  |   switch (format) { | 
					
						
							|  |  |  |     /* Formats texture & renderbuffer */ | 
					
						
							|  |  |  |     case GPU_RGBA8UI: | 
					
						
							|  |  |  |       return GL_RGBA8UI; | 
					
						
							|  |  |  |     case GPU_RGBA8I: | 
					
						
							|  |  |  |       return GL_RGBA8I; | 
					
						
							|  |  |  |     case GPU_RGBA8: | 
					
						
							|  |  |  |       return GL_RGBA8; | 
					
						
							|  |  |  |     case GPU_RGBA32UI: | 
					
						
							|  |  |  |       return GL_RGBA32UI; | 
					
						
							|  |  |  |     case GPU_RGBA32I: | 
					
						
							|  |  |  |       return GL_RGBA32I; | 
					
						
							|  |  |  |     case GPU_RGBA32F: | 
					
						
							|  |  |  |       return GL_RGBA32F; | 
					
						
							|  |  |  |     case GPU_RGBA16UI: | 
					
						
							|  |  |  |       return GL_RGBA16UI; | 
					
						
							|  |  |  |     case GPU_RGBA16I: | 
					
						
							|  |  |  |       return GL_RGBA16I; | 
					
						
							|  |  |  |     case GPU_RGBA16F: | 
					
						
							|  |  |  |       return GL_RGBA16F; | 
					
						
							|  |  |  |     case GPU_RGBA16: | 
					
						
							|  |  |  |       return GL_RGBA16; | 
					
						
							|  |  |  |     case GPU_RG8UI: | 
					
						
							|  |  |  |       return GL_RG8UI; | 
					
						
							|  |  |  |     case GPU_RG8I: | 
					
						
							|  |  |  |       return GL_RG8I; | 
					
						
							|  |  |  |     case GPU_RG8: | 
					
						
							|  |  |  |       return GL_RG8; | 
					
						
							|  |  |  |     case GPU_RG32UI: | 
					
						
							|  |  |  |       return GL_RG32UI; | 
					
						
							|  |  |  |     case GPU_RG32I: | 
					
						
							|  |  |  |       return GL_RG32I; | 
					
						
							|  |  |  |     case GPU_RG32F: | 
					
						
							|  |  |  |       return GL_RG32F; | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |       return GL_RG16UI; | 
					
						
							|  |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |       return GL_RG16I; | 
					
						
							|  |  |  |     case GPU_RG16F: | 
					
						
							|  |  |  |       return GL_RG16F; | 
					
						
							|  |  |  |     case GPU_RG16: | 
					
						
							|  |  |  |       return GL_RG16; | 
					
						
							|  |  |  |     case GPU_R8UI: | 
					
						
							|  |  |  |       return GL_R8UI; | 
					
						
							|  |  |  |     case GPU_R8I: | 
					
						
							|  |  |  |       return GL_R8I; | 
					
						
							|  |  |  |     case GPU_R8: | 
					
						
							|  |  |  |       return GL_R8; | 
					
						
							|  |  |  |     case GPU_R32UI: | 
					
						
							|  |  |  |       return GL_R32UI; | 
					
						
							|  |  |  |     case GPU_R32I: | 
					
						
							|  |  |  |       return GL_R32I; | 
					
						
							|  |  |  |     case GPU_R32F: | 
					
						
							|  |  |  |       return GL_R32F; | 
					
						
							|  |  |  |     case GPU_R16UI: | 
					
						
							|  |  |  |       return GL_R16UI; | 
					
						
							|  |  |  |     case GPU_R16I: | 
					
						
							|  |  |  |       return GL_R16I; | 
					
						
							|  |  |  |     case GPU_R16F: | 
					
						
							|  |  |  |       return GL_R16F; | 
					
						
							|  |  |  |     case GPU_R16: | 
					
						
							|  |  |  |       return GL_R16; | 
					
						
							|  |  |  |     /* Special formats texture & renderbuffer */ | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_RGB10_A2: | 
					
						
							|  |  |  |       return GL_RGB10_A2; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_R11F_G11F_B10F: | 
					
						
							|  |  |  |       return GL_R11F_G11F_B10F; | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: | 
					
						
							|  |  |  |       return GL_DEPTH32F_STENCIL8; | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |       return GL_DEPTH24_STENCIL8; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8: | 
					
						
							|  |  |  |       return GL_SRGB8_ALPHA8; | 
					
						
							|  |  |  |     /* Texture only format */ | 
					
						
							|  |  |  |     case GPU_RGB16F: | 
					
						
							|  |  |  |       return GL_RGB16F; | 
					
						
							|  |  |  |     /* Special formats texture only */ | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT1: | 
					
						
							|  |  |  |       return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT3: | 
					
						
							|  |  |  |       return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT5: | 
					
						
							|  |  |  |       return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT1: | 
					
						
							|  |  |  |       return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT3: | 
					
						
							|  |  |  |       return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT5: | 
					
						
							|  |  |  |       return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 
					
						
							|  |  |  |     /* Depth Formats */ | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       return GL_DEPTH_COMPONENT32F; | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |       return GL_DEPTH_COMPONENT24; | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |       return GL_DEPTH_COMPONENT16; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |       BLI_assert_msg(0, "Texture format incorrect or unsupported"); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline GLenum to_gl_target(eGPUTextureType type) | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   switch (type) { | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |     case GPU_TEXTURE_1D: | 
					
						
							|  |  |  |       return GL_TEXTURE_1D; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_TEXTURE_1D_ARRAY: | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |       return GL_TEXTURE_1D_ARRAY; | 
					
						
							|  |  |  |     case GPU_TEXTURE_2D: | 
					
						
							|  |  |  |       return GL_TEXTURE_2D; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_TEXTURE_2D_ARRAY: | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |       return GL_TEXTURE_2D_ARRAY; | 
					
						
							|  |  |  |     case GPU_TEXTURE_3D: | 
					
						
							|  |  |  |       return GL_TEXTURE_3D; | 
					
						
							|  |  |  |     case GPU_TEXTURE_CUBE: | 
					
						
							|  |  |  |       return GL_TEXTURE_CUBE_MAP; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_TEXTURE_CUBE_ARRAY: | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |       return GL_TEXTURE_CUBE_MAP_ARRAY_ARB; | 
					
						
							|  |  |  |     case GPU_TEXTURE_BUFFER: | 
					
						
							|  |  |  |       return GL_TEXTURE_BUFFER; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       BLI_assert(0); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return GL_TEXTURE_1D; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 02:36:56 +02:00
										 |  |  | inline GLenum to_gl_proxy(eGPUTextureType type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (type) { | 
					
						
							|  |  |  |     case GPU_TEXTURE_1D: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_1D; | 
					
						
							|  |  |  |     case GPU_TEXTURE_1D_ARRAY: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_1D_ARRAY; | 
					
						
							|  |  |  |     case GPU_TEXTURE_2D: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_2D; | 
					
						
							|  |  |  |     case GPU_TEXTURE_2D_ARRAY: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_2D_ARRAY; | 
					
						
							|  |  |  |     case GPU_TEXTURE_3D: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_3D; | 
					
						
							|  |  |  |     case GPU_TEXTURE_CUBE: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_CUBE_MAP; | 
					
						
							|  |  |  |     case GPU_TEXTURE_CUBE_ARRAY: | 
					
						
							|  |  |  |       return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY_ARB; | 
					
						
							|  |  |  |     case GPU_TEXTURE_BUFFER: | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       BLI_assert(0); | 
					
						
							|  |  |  |       return GL_TEXTURE_1D; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | inline GLenum swizzle_to_gl(const char swizzle) | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   switch (swizzle) { | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |     case 'x': | 
					
						
							|  |  |  |     case 'r': | 
					
						
							|  |  |  |       return GL_RED; | 
					
						
							|  |  |  |     case 'y': | 
					
						
							|  |  |  |     case 'g': | 
					
						
							|  |  |  |       return GL_GREEN; | 
					
						
							|  |  |  |     case 'z': | 
					
						
							|  |  |  |     case 'b': | 
					
						
							|  |  |  |       return GL_BLUE; | 
					
						
							|  |  |  |     case 'w': | 
					
						
							|  |  |  |     case 'a': | 
					
						
							|  |  |  |       return GL_ALPHA; | 
					
						
							|  |  |  |     case '0': | 
					
						
							|  |  |  |       return GL_ZERO; | 
					
						
							|  |  |  |     case '1': | 
					
						
							|  |  |  |       return GL_ONE; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | inline GLenum to_gl(eGPUDataFormat format) | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   switch (format) { | 
					
						
							|  |  |  |     case GPU_DATA_FLOAT: | 
					
						
							|  |  |  |       return GL_FLOAT; | 
					
						
							|  |  |  |     case GPU_DATA_INT: | 
					
						
							|  |  |  |       return GL_INT; | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |     case GPU_DATA_UINT: | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |       return GL_UNSIGNED_INT; | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |     case GPU_DATA_UBYTE: | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |       return GL_UNSIGNED_BYTE; | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |     case GPU_DATA_UINT_24_8: | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |       return GL_UNSIGNED_INT_24_8; | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_DATA_2_10_10_10_REV: | 
					
						
							|  |  |  |       return GL_UNSIGNED_INT_2_10_10_10_REV; | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |     case GPU_DATA_10_11_11_REV: | 
					
						
							|  |  |  |       return GL_UNSIGNED_INT_10F_11F_11F_REV; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |       BLI_assert_msg(0, "Unhandled data format"); | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |       return GL_FLOAT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Definitely not complete, edit according to the OpenGL specification. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | inline GLenum to_gl_data_format(eGPUTextureFormat format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   /* You can add any of the available type to this list
 | 
					
						
							|  |  |  |    * For available types see GPU_texture.h */ | 
					
						
							|  |  |  |   switch (format) { | 
					
						
							|  |  |  |     case GPU_R8I: | 
					
						
							|  |  |  |     case GPU_R8UI: | 
					
						
							|  |  |  |     case GPU_R16I: | 
					
						
							|  |  |  |     case GPU_R16UI: | 
					
						
							|  |  |  |     case GPU_R32I: | 
					
						
							|  |  |  |     case GPU_R32UI: | 
					
						
							|  |  |  |       return GL_RED_INTEGER; | 
					
						
							|  |  |  |     case GPU_RG8I: | 
					
						
							|  |  |  |     case GPU_RG8UI: | 
					
						
							|  |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |     case GPU_RG32I: | 
					
						
							|  |  |  |     case GPU_RG32UI: | 
					
						
							|  |  |  |       return GL_RG_INTEGER; | 
					
						
							|  |  |  |     case GPU_RGBA8I: | 
					
						
							|  |  |  |     case GPU_RGBA8UI: | 
					
						
							|  |  |  |     case GPU_RGBA16I: | 
					
						
							|  |  |  |     case GPU_RGBA16UI: | 
					
						
							|  |  |  |     case GPU_RGBA32I: | 
					
						
							|  |  |  |     case GPU_RGBA32UI: | 
					
						
							|  |  |  |       return GL_RGBA_INTEGER; | 
					
						
							|  |  |  |     case GPU_R8: | 
					
						
							|  |  |  |     case GPU_R16: | 
					
						
							|  |  |  |     case GPU_R16F: | 
					
						
							|  |  |  |     case GPU_R32F: | 
					
						
							|  |  |  |       return GL_RED; | 
					
						
							|  |  |  |     case GPU_RG8: | 
					
						
							|  |  |  |     case GPU_RG16: | 
					
						
							|  |  |  |     case GPU_RG16F: | 
					
						
							|  |  |  |     case GPU_RG32F: | 
					
						
							|  |  |  |       return GL_RG; | 
					
						
							|  |  |  |     case GPU_R11F_G11F_B10F: | 
					
						
							|  |  |  |     case GPU_RGB16F: | 
					
						
							|  |  |  |       return GL_RGB; | 
					
						
							|  |  |  |     case GPU_RGBA8: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8: | 
					
						
							|  |  |  |     case GPU_RGBA16: | 
					
						
							|  |  |  |     case GPU_RGBA16F: | 
					
						
							|  |  |  |     case GPU_RGBA32F: | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_RGB10_A2: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return GL_RGBA; | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: | 
					
						
							|  |  |  |       return GL_DEPTH_STENCIL; | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       return GL_DEPTH_COMPONENT; | 
					
						
							| 
									
										
										
										
											2020-09-25 13:10:06 +02:00
										 |  |  |     case GPU_SRGB8_A8_DXT1: | 
					
						
							|  |  |  |       return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT3: | 
					
						
							|  |  |  |       return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT5: | 
					
						
							|  |  |  |       return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT1: | 
					
						
							|  |  |  |       return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT3: | 
					
						
							|  |  |  |       return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT5: | 
					
						
							|  |  |  |       return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |       BLI_assert_msg(0, "Texture format incorrect or unsupported\n"); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Assume Unorm / Float target. Used with #glReadPixels. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | inline GLenum channel_len_to_gl(int channel_len) | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   switch (channel_len) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |       return GL_RED; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |       return GL_RG; | 
					
						
							|  |  |  |     case 3: | 
					
						
							|  |  |  |       return GL_RGB; | 
					
						
							|  |  |  |     case 4: | 
					
						
							|  |  |  |       return GL_RGBA; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |       BLI_assert_msg(0, "Wrong number of texture channels"); | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |       return GL_RED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace gpu
 | 
					
						
							|  |  |  | }  // namespace blender
 |