| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_assert.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:33:56 +02:00
										 |  |  | #include "GPU_vertex_buffer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | #include "gpu_framebuffer_private.hh"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | namespace blender { | 
					
						
							|  |  |  | namespace gpu { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | typedef enum eGPUTextureFormatFlag { | 
					
						
							|  |  |  |   GPU_FORMAT_DEPTH = (1 << 0), | 
					
						
							|  |  |  |   GPU_FORMAT_STENCIL = (1 << 1), | 
					
						
							|  |  |  |   GPU_FORMAT_INTEGER = (1 << 2), | 
					
						
							|  |  |  |   GPU_FORMAT_FLOAT = (1 << 3), | 
					
						
							|  |  |  |   GPU_FORMAT_COMPRESSED = (1 << 4), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_FORMAT_DEPTH_STENCIL = (GPU_FORMAT_DEPTH | GPU_FORMAT_STENCIL), | 
					
						
							|  |  |  | } eGPUTextureFormatFlag; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 23:51:01 +05:30
										 |  |  | ENUM_OPERATORS(eGPUTextureFormatFlag, GPU_FORMAT_DEPTH_STENCIL) | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef enum eGPUTextureType { | 
					
						
							|  |  |  |   GPU_TEXTURE_1D = (1 << 0), | 
					
						
							|  |  |  |   GPU_TEXTURE_2D = (1 << 1), | 
					
						
							|  |  |  |   GPU_TEXTURE_3D = (1 << 2), | 
					
						
							|  |  |  |   GPU_TEXTURE_CUBE = (1 << 3), | 
					
						
							|  |  |  |   GPU_TEXTURE_ARRAY = (1 << 4), | 
					
						
							|  |  |  |   GPU_TEXTURE_BUFFER = (1 << 5), | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   GPU_TEXTURE_1D_ARRAY = (GPU_TEXTURE_1D | GPU_TEXTURE_ARRAY), | 
					
						
							|  |  |  |   GPU_TEXTURE_2D_ARRAY = (GPU_TEXTURE_2D | GPU_TEXTURE_ARRAY), | 
					
						
							|  |  |  |   GPU_TEXTURE_CUBE_ARRAY = (GPU_TEXTURE_CUBE | GPU_TEXTURE_ARRAY), | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | } eGPUTextureType; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 23:51:01 +05:30
										 |  |  | ENUM_OPERATORS(eGPUTextureType, GPU_TEXTURE_CUBE_ARRAY) | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  | #  define DEBUG_NAME_LEN 64
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #  define DEBUG_NAME_LEN 8
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Maximum number of FBOs a texture can be attached to. */ | 
					
						
							| 
									
										
										
										
											2021-10-14 18:16:22 +02:00
										 |  |  | #define GPU_TEX_MAX_FBO_ATTACHED 32
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Implementation of Textures. | 
					
						
							|  |  |  |  * Base class which is then specialized for each implementation (GL, VK, ...). | 
					
						
							| 
									
										
										
										
											2021-01-04 12:00:18 +11:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | class Texture { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   /** Internal Sampler state. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   eGPUSamplerState sampler_state = GPU_SAMPLER_DEFAULT; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   /** Reference counter. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   int refcount = 1; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   /** Width & Height (of source data), optional. */ | 
					
						
							|  |  |  |   int src_w = 0, src_h = 0; | 
					
						
							| 
									
										
										
										
											2021-04-30 11:20:39 -03:00
										 |  |  | #ifndef GPU_NO_USE_PY_REFERENCES
 | 
					
						
							| 
									
										
										
										
											2021-04-29 14:48:59 -03:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Reference of a pointer that needs to be cleaned when deallocating the texture. | 
					
						
							|  |  |  |    * Points to #BPyGPUTexture.tex | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void **py_ref = nullptr; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   /* ---- Texture format (immutable after init). ---- */ | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |   /** Width & Height & Depth. For cube-map arrays, d is number of face-layers. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   int w_, h_, d_; | 
					
						
							|  |  |  |   /** Internal data format. */ | 
					
						
							|  |  |  |   eGPUTextureFormat format_; | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |   /** Format characteristics. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   eGPUTextureFormatFlag format_flag_; | 
					
						
							|  |  |  |   /** Texture type. */ | 
					
						
							|  |  |  |   eGPUTextureType type_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Number of mipmaps this texture has (Max miplvl). */ | 
					
						
							| 
									
										
										
										
											2020-09-19 14:32:41 +10:00
										 |  |  |   /* TODO(fclem): Should become immutable and the need for mipmaps should be specified upfront. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   int mipmaps_ = -1; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:36:13 +02:00
										 |  |  |   /** For error checking */ | 
					
						
							|  |  |  |   int mip_min_ = 0, mip_max_ = 0; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   /** For debugging */ | 
					
						
							|  |  |  |   char name_[DEBUG_NAME_LEN]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |   /** Frame-buffer references to update on deletion. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:37:01 +02:00
										 |  |  |   GPUAttachmentType fb_attachment_[GPU_TEX_MAX_FBO_ATTACHED]; | 
					
						
							|  |  |  |   FrameBuffer *fb_[GPU_TEX_MAX_FBO_ATTACHED]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |  public: | 
					
						
							|  |  |  |   Texture(const char *name); | 
					
						
							|  |  |  |   virtual ~Texture(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   /* Return true on success. */ | 
					
						
							|  |  |  |   bool init_1D(int w, int layers, eGPUTextureFormat format); | 
					
						
							|  |  |  |   bool init_2D(int w, int h, int layers, eGPUTextureFormat format); | 
					
						
							|  |  |  |   bool init_3D(int w, int h, int d, eGPUTextureFormat format); | 
					
						
							|  |  |  |   bool init_cubemap(int w, int layers, eGPUTextureFormat format); | 
					
						
							|  |  |  |   bool init_buffer(GPUVertBuf *vbo, eGPUTextureFormat format); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   virtual void generate_mipmap() = 0; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   virtual void copy_to(Texture *tex) = 0; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   virtual void clear(eGPUDataFormat format, const void *data) = 0; | 
					
						
							|  |  |  |   virtual void swizzle_set(const char swizzle_mask[4]) = 0; | 
					
						
							|  |  |  |   virtual void mip_range_set(int min, int max) = 0; | 
					
						
							|  |  |  |   virtual void *read(int mip, eGPUDataFormat format) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:37:01 +02:00
										 |  |  |   void attach_to(FrameBuffer *fb, GPUAttachmentType type); | 
					
						
							|  |  |  |   void detach_from(FrameBuffer *fb); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   void update(eGPUDataFormat format, const void *data); | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   virtual void update_sub( | 
					
						
							|  |  |  |       int mip, int offset[3], int extent[3], eGPUDataFormat format, const void *data) = 0; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +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
										 |  |  |   virtual uint gl_bindcode_get() const = 0; | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   int width_get() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     return w_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   int height_get() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     return h_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   int depth_get() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     return d_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   void mip_size_get(int mip, int r_size[3]) const | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |     /* TODO: assert if lvl is below the limit of 1px in each dimension. */ | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     int div = 1 << mip; | 
					
						
							|  |  |  |     r_size[0] = max_ii(1, w_ / div); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type_ == GPU_TEXTURE_1D_ARRAY) { | 
					
						
							|  |  |  |       r_size[1] = h_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (h_ > 0) { | 
					
						
							|  |  |  |       r_size[1] = max_ii(1, h_ / div); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type_ & (GPU_TEXTURE_ARRAY | GPU_TEXTURE_CUBE)) { | 
					
						
							|  |  |  |       r_size[2] = d_; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (d_ > 0) { | 
					
						
							|  |  |  |       r_size[2] = max_ii(1, d_ / div); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   int mip_width_get(int mip) const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return max_ii(1, w_ / (1 << mip)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   int mip_height_get(int mip) const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return (type_ == GPU_TEXTURE_1D_ARRAY) ? h_ : max_ii(1, h_ / (1 << mip)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   int mip_depth_get(int mip) const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return (type_ & (GPU_TEXTURE_ARRAY | GPU_TEXTURE_CUBE)) ? d_ : max_ii(1, d_ / (1 << mip)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Return number of dimension taking the array type into account. */ | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   int dimensions_count() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     const int array = (type_ & GPU_TEXTURE_ARRAY) ? 1 : 0; | 
					
						
							|  |  |  |     switch (type_ & ~GPU_TEXTURE_ARRAY) { | 
					
						
							|  |  |  |       case GPU_TEXTURE_BUFFER: | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |       case GPU_TEXTURE_1D: | 
					
						
							|  |  |  |         return 1 + array; | 
					
						
							|  |  |  |       case GPU_TEXTURE_2D: | 
					
						
							|  |  |  |         return 2 + array; | 
					
						
							|  |  |  |       case GPU_TEXTURE_CUBE: | 
					
						
							|  |  |  |       case GPU_TEXTURE_3D: | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         return 3; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-04 02:36:56 +02:00
										 |  |  |   /* Return number of array layer (or face layer) for texture array or 1 for the others. */ | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   int layer_count() const | 
					
						
							| 
									
										
										
										
											2020-09-04 02:36:56 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     switch (type_) { | 
					
						
							|  |  |  |       case GPU_TEXTURE_1D_ARRAY: | 
					
						
							|  |  |  |         return h_; | 
					
						
							|  |  |  |       case GPU_TEXTURE_2D_ARRAY: | 
					
						
							|  |  |  |       case GPU_TEXTURE_CUBE_ARRAY: | 
					
						
							|  |  |  |         return d_; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   eGPUTextureFormat format_get() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     return format_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   eGPUTextureFormatFlag format_flag_get() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     return format_flag_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   eGPUTextureType type_get() const | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     return type_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |   GPUAttachmentType attachment_type(int slot) const | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     switch (format_) { | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |       case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |       case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |         BLI_assert(slot == 0); | 
					
						
							|  |  |  |         return GPU_FB_DEPTH_ATTACHMENT; | 
					
						
							|  |  |  |       case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |       case GPU_DEPTH32F_STENCIL8: | 
					
						
							|  |  |  |         BLI_assert(slot == 0); | 
					
						
							|  |  |  |         return GPU_FB_DEPTH_STENCIL_ATTACHMENT; | 
					
						
							|  |  |  |       default: | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  |         return GPU_FB_COLOR_ATTACHMENT0 + slot; | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2022-01-05 21:44:03 -05:00
										 |  |  |   virtual bool init_internal() = 0; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |   virtual bool init_internal(GPUVertBuf *vbo) = 0; | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  | /* Syntactic sugar. */ | 
					
						
							| 
									
										
										
										
											2020-09-08 03:22:35 +02:00
										 |  |  | static inline GPUTexture *wrap(Texture *vert) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return reinterpret_cast<GPUTexture *>(vert); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | static inline Texture *unwrap(GPUTexture *vert) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return reinterpret_cast<Texture *>(vert); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | static inline const Texture *unwrap(const GPUTexture *vert) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return reinterpret_cast<const Texture *>(vert); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 01:25:32 +02:00
										 |  |  | #undef DEBUG_NAME_LEN
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | inline size_t to_bytesize(eGPUTextureFormat format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (format) { | 
					
						
							|  |  |  |     case GPU_RGBA32F: | 
					
						
							|  |  |  |       return 32; | 
					
						
							|  |  |  |     case GPU_RG32F: | 
					
						
							|  |  |  |     case GPU_RGBA16F: | 
					
						
							|  |  |  |     case GPU_RGBA16: | 
					
						
							|  |  |  |       return 16; | 
					
						
							|  |  |  |     case GPU_RGB16F: | 
					
						
							|  |  |  |       return 12; | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: /* 32-bit depth, 8 bits stencil, and 24 unused bits. */ | 
					
						
							|  |  |  |       return 8; | 
					
						
							|  |  |  |     case GPU_RG16F: | 
					
						
							|  |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |     case GPU_RG16: | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |     case GPU_RGBA8UI: | 
					
						
							|  |  |  |     case GPU_RGBA8: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8: | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_RGB10_A2: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_R11F_G11F_B10F: | 
					
						
							|  |  |  |     case GPU_R32F: | 
					
						
							|  |  |  |     case GPU_R32UI: | 
					
						
							|  |  |  |     case GPU_R32I: | 
					
						
							|  |  |  |       return 4; | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |       return 3; | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |     case GPU_R16F: | 
					
						
							|  |  |  |     case GPU_R16UI: | 
					
						
							|  |  |  |     case GPU_R16I: | 
					
						
							|  |  |  |     case GPU_RG8: | 
					
						
							|  |  |  |     case GPU_R16: | 
					
						
							|  |  |  |       return 2; | 
					
						
							|  |  |  |     case GPU_R8: | 
					
						
							|  |  |  |     case GPU_R8UI: | 
					
						
							|  |  |  |       return 1; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT1: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT3: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT5: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT1: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT3: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT5: | 
					
						
							|  |  |  |       return 1; /* Incorrect but actual size is fractional. */ | 
					
						
							|  |  |  |     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 size_t to_block_size(eGPUTextureFormat data_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (data_type) { | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT1: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT1: | 
					
						
							|  |  |  |       return 8; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT3: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT5: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT3: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT5: | 
					
						
							|  |  |  |       return 16; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |       BLI_assert_msg(0, "Texture format is not a compressed format"); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline eGPUTextureFormatFlag to_format_flag(eGPUTextureFormat format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (format) { | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       return GPU_FORMAT_DEPTH; | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: | 
					
						
							|  |  |  |       return GPU_FORMAT_DEPTH_STENCIL; | 
					
						
							|  |  |  |     case GPU_R8UI: | 
					
						
							|  |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |     case GPU_R16I: | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |     case GPU_R16UI: | 
					
						
							|  |  |  |     case GPU_R32UI: | 
					
						
							|  |  |  |       return GPU_FORMAT_INTEGER; | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT1: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT3: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8_DXT5: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT1: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT3: | 
					
						
							|  |  |  |     case GPU_RGBA8_DXT5: | 
					
						
							|  |  |  |       return GPU_FORMAT_COMPRESSED; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return GPU_FORMAT_FLOAT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline int to_component_len(eGPUTextureFormat format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (format) { | 
					
						
							|  |  |  |     case GPU_RGBA8: | 
					
						
							|  |  |  |     case GPU_RGBA8UI: | 
					
						
							|  |  |  |     case GPU_RGBA16F: | 
					
						
							|  |  |  |     case GPU_RGBA16: | 
					
						
							|  |  |  |     case GPU_RGBA32F: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8: | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_RGB10_A2: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return 4; | 
					
						
							|  |  |  |     case GPU_RGB16F: | 
					
						
							|  |  |  |     case GPU_R11F_G11F_B10F: | 
					
						
							|  |  |  |       return 3; | 
					
						
							|  |  |  |     case GPU_RG8: | 
					
						
							|  |  |  |     case GPU_RG16: | 
					
						
							|  |  |  |     case GPU_RG16F: | 
					
						
							|  |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |     case GPU_RG32F: | 
					
						
							|  |  |  |       return 2; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return 1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | inline size_t to_bytesize(eGPUDataFormat data_format) | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   switch (data_format) { | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |     case GPU_DATA_UBYTE: | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |       return 1; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_DATA_FLOAT: | 
					
						
							|  |  |  |     case GPU_DATA_INT: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |     case GPU_DATA_UINT: | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |       return 4; | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |     case GPU_DATA_UINT_24_8: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_DATA_10_11_11_REV: | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_DATA_2_10_10_10_REV: | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return 4; | 
					
						
							|  |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |       BLI_assert_msg(0, "Data format incorrect or unsupported"); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |       return 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | inline size_t to_bytesize(eGPUTextureFormat tex_format, eGPUDataFormat data_format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return to_component_len(tex_format) * to_bytesize(data_format); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  | /* Definitely not complete, edit according to the gl specification. */ | 
					
						
							|  |  |  | inline bool validate_data_format(eGPUTextureFormat tex_format, eGPUDataFormat data_format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (tex_format) { | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       return data_format == GPU_DATA_FLOAT; | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |       return data_format == GPU_DATA_UINT_24_8; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_R8UI: | 
					
						
							|  |  |  |     case GPU_R16UI: | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |     case GPU_R32UI: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |       return data_format == GPU_DATA_UINT; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |     case GPU_R16I: | 
					
						
							|  |  |  |       return data_format == GPU_DATA_INT; | 
					
						
							|  |  |  |     case GPU_R8: | 
					
						
							|  |  |  |     case GPU_RG8: | 
					
						
							|  |  |  |     case GPU_RGBA8: | 
					
						
							|  |  |  |     case GPU_RGBA8UI: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |       return ELEM(data_format, GPU_DATA_UBYTE, GPU_DATA_FLOAT); | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_RGB10_A2: | 
					
						
							|  |  |  |       return ELEM(data_format, GPU_DATA_2_10_10_10_REV, GPU_DATA_FLOAT); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_R11F_G11F_B10F: | 
					
						
							|  |  |  |       return ELEM(data_format, GPU_DATA_10_11_11_REV, GPU_DATA_FLOAT); | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return data_format == GPU_DATA_FLOAT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Definitely not complete, edit according to the gl specification. */ | 
					
						
							|  |  |  | inline eGPUDataFormat to_data_format(eGPUTextureFormat tex_format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (tex_format) { | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       return GPU_DATA_FLOAT; | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |       return GPU_DATA_UINT_24_8; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_R8UI: | 
					
						
							|  |  |  |     case GPU_R16UI: | 
					
						
							|  |  |  |     case GPU_RG16UI: | 
					
						
							|  |  |  |     case GPU_R32UI: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |       return GPU_DATA_UINT; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_RG16I: | 
					
						
							|  |  |  |     case GPU_R16I: | 
					
						
							|  |  |  |       return GPU_DATA_INT; | 
					
						
							|  |  |  |     case GPU_R8: | 
					
						
							|  |  |  |     case GPU_RG8: | 
					
						
							|  |  |  |     case GPU_RGBA8: | 
					
						
							|  |  |  |     case GPU_RGBA8UI: | 
					
						
							|  |  |  |     case GPU_SRGB8_A8: | 
					
						
							| 
									
										
										
										
											2021-02-17 12:38:21 -03:00
										 |  |  |       return GPU_DATA_UBYTE; | 
					
						
							| 
									
										
										
										
											2021-02-20 17:01:28 +01:00
										 |  |  |     case GPU_RGB10_A2: | 
					
						
							|  |  |  |       return GPU_DATA_2_10_10_10_REV; | 
					
						
							| 
									
										
										
										
											2020-09-05 17:29:51 +02:00
										 |  |  |     case GPU_R11F_G11F_B10F: | 
					
						
							|  |  |  |       return GPU_DATA_10_11_11_REV; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return GPU_DATA_FLOAT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline eGPUFrameBufferBits to_framebuffer_bits(eGPUTextureFormat tex_format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   switch (tex_format) { | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT24: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT16: | 
					
						
							|  |  |  |     case GPU_DEPTH_COMPONENT32F: | 
					
						
							|  |  |  |       return GPU_DEPTH_BIT; | 
					
						
							|  |  |  |     case GPU_DEPTH24_STENCIL8: | 
					
						
							|  |  |  |     case GPU_DEPTH32F_STENCIL8: | 
					
						
							|  |  |  |       return GPU_DEPTH_BIT | GPU_STENCIL_BIT; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return GPU_COLOR_BIT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 17:33:56 +02:00
										 |  |  | static inline eGPUTextureFormat to_texture_format(const GPUVertFormat *format) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (format->attr_len > 1 || format->attr_len == 0) { | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |     BLI_assert_msg(0, "Incorrect vertex format for buffer texture"); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:33:56 +02:00
										 |  |  |     return GPU_DEPTH_COMPONENT24; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   switch (format->attrs[0].comp_len) { | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |       switch (format->attrs[0].comp_type) { | 
					
						
							|  |  |  |         case GPU_COMP_I8: | 
					
						
							|  |  |  |           return GPU_R8I; | 
					
						
							|  |  |  |         case GPU_COMP_U8: | 
					
						
							|  |  |  |           return GPU_R8UI; | 
					
						
							|  |  |  |         case GPU_COMP_I16: | 
					
						
							|  |  |  |           return GPU_R16I; | 
					
						
							|  |  |  |         case GPU_COMP_U16: | 
					
						
							|  |  |  |           return GPU_R16UI; | 
					
						
							|  |  |  |         case GPU_COMP_I32: | 
					
						
							|  |  |  |           return GPU_R32I; | 
					
						
							|  |  |  |         case GPU_COMP_U32: | 
					
						
							|  |  |  |           return GPU_R32UI; | 
					
						
							|  |  |  |         case GPU_COMP_F32: | 
					
						
							|  |  |  |           return GPU_R32F; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 2: | 
					
						
							|  |  |  |       switch (format->attrs[0].comp_type) { | 
					
						
							|  |  |  |         case GPU_COMP_I8: | 
					
						
							|  |  |  |           return GPU_RG8I; | 
					
						
							|  |  |  |         case GPU_COMP_U8: | 
					
						
							|  |  |  |           return GPU_RG8UI; | 
					
						
							|  |  |  |         case GPU_COMP_I16: | 
					
						
							|  |  |  |           return GPU_RG16I; | 
					
						
							|  |  |  |         case GPU_COMP_U16: | 
					
						
							|  |  |  |           return GPU_RG16UI; | 
					
						
							|  |  |  |         case GPU_COMP_I32: | 
					
						
							|  |  |  |           return GPU_RG32I; | 
					
						
							|  |  |  |         case GPU_COMP_U32: | 
					
						
							|  |  |  |           return GPU_RG32UI; | 
					
						
							|  |  |  |         case GPU_COMP_F32: | 
					
						
							|  |  |  |           return GPU_RG32F; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 3: | 
					
						
							|  |  |  |       /* Not supported until GL 4.0 */ | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 4: | 
					
						
							|  |  |  |       switch (format->attrs[0].comp_type) { | 
					
						
							|  |  |  |         case GPU_COMP_I8: | 
					
						
							|  |  |  |           return GPU_RGBA8I; | 
					
						
							|  |  |  |         case GPU_COMP_U8: | 
					
						
							|  |  |  |           return GPU_RGBA8UI; | 
					
						
							|  |  |  |         case GPU_COMP_I16: | 
					
						
							|  |  |  |           return GPU_RGBA16I; | 
					
						
							|  |  |  |         case GPU_COMP_U16: | 
					
						
							| 
									
										
										
										
											2021-07-03 23:08:40 +10:00
										 |  |  |           /* NOTE: Checking the fetch mode to select the right GPU texture format. This can be
 | 
					
						
							| 
									
										
										
										
											2021-01-04 15:05:37 +01:00
										 |  |  |            * added to other formats as well. */ | 
					
						
							|  |  |  |           switch (format->attrs[0].fetch_mode) { | 
					
						
							|  |  |  |             case GPU_FETCH_INT: | 
					
						
							|  |  |  |               return GPU_RGBA16UI; | 
					
						
							|  |  |  |             case GPU_FETCH_INT_TO_FLOAT_UNIT: | 
					
						
							|  |  |  |               return GPU_RGBA16; | 
					
						
							|  |  |  |             case GPU_FETCH_INT_TO_FLOAT: | 
					
						
							|  |  |  |               return GPU_RGBA16F; | 
					
						
							|  |  |  |             case GPU_FETCH_FLOAT: | 
					
						
							|  |  |  |               return GPU_RGBA16F; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2020-09-05 17:33:56 +02:00
										 |  |  |         case GPU_COMP_I32: | 
					
						
							|  |  |  |           return GPU_RGBA32I; | 
					
						
							|  |  |  |         case GPU_COMP_U32: | 
					
						
							|  |  |  |           return GPU_RGBA32UI; | 
					
						
							|  |  |  |         case GPU_COMP_F32: | 
					
						
							|  |  |  |           return GPU_RGBA32F; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-21 20:59:19 +10:00
										 |  |  |   BLI_assert_msg(0, "Unsupported vertex format for buffer texture"); | 
					
						
							| 
									
										
										
										
											2020-09-05 17:33:56 +02:00
										 |  |  |   return GPU_DEPTH_COMPONENT24; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-29 01:13:54 +02:00
										 |  |  | }  // namespace gpu
 | 
					
						
							|  |  |  | }  // namespace blender
 |