2015-12-06 21:20:19 +01: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) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup gpu
|
2015-12-06 21:20:19 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-07-28 16:32:30 +02:00
|
|
|
#include "BLI_utildefines.h"
|
2020-07-29 15:50:46 +02:00
|
|
|
|
2018-06-26 15:17:31 -06:00
|
|
|
#include "GPU_state.h"
|
|
|
|
|
2019-01-28 21:08:24 +11:00
|
|
|
struct GPUVertBuf;
|
2020-09-08 03:34:47 +02:00
|
|
|
|
|
|
|
/** Opaque type hiding blender::gpu::Texture. */
|
2015-12-06 21:20:19 +01:00
|
|
|
typedef struct GPUTexture GPUTexture;
|
|
|
|
|
2020-06-02 10:47:45 +02:00
|
|
|
/* GPU Samplers state
|
|
|
|
* - Specify the sampler state to bind a texture with.
|
|
|
|
* - Internally used by textures.
|
|
|
|
* - All states are created at startup to avoid runtime costs.
|
|
|
|
*/
|
|
|
|
typedef enum eGPUSamplerState {
|
2020-09-05 17:29:51 +02:00
|
|
|
GPU_SAMPLER_DEFAULT = 0,
|
2020-06-02 10:47:45 +02:00
|
|
|
GPU_SAMPLER_FILTER = (1 << 0),
|
|
|
|
GPU_SAMPLER_MIPMAP = (1 << 1),
|
|
|
|
GPU_SAMPLER_REPEAT_S = (1 << 2),
|
|
|
|
GPU_SAMPLER_REPEAT_T = (1 << 3),
|
|
|
|
GPU_SAMPLER_REPEAT_R = (1 << 4),
|
|
|
|
GPU_SAMPLER_CLAMP_BORDER = (1 << 5), /* Clamp to border color instead of border texel. */
|
|
|
|
GPU_SAMPLER_COMPARE = (1 << 6),
|
|
|
|
GPU_SAMPLER_ANISO = (1 << 7),
|
2020-09-05 17:29:51 +02:00
|
|
|
GPU_SAMPLER_ICON = (1 << 8),
|
|
|
|
|
|
|
|
GPU_SAMPLER_REPEAT = (GPU_SAMPLER_REPEAT_S | GPU_SAMPLER_REPEAT_T | GPU_SAMPLER_REPEAT_R),
|
2020-06-02 10:47:45 +02:00
|
|
|
} eGPUSamplerState;
|
|
|
|
|
2020-10-09 16:27:39 +05:30
|
|
|
/* `GPU_SAMPLER_MAX` is not a valid enum value, but only a limit.
|
|
|
|
* It also creates a bad mask for the `NOT` operator in `ENUM_OPERATORS`.
|
|
|
|
*/
|
|
|
|
static const int GPU_SAMPLER_MAX = (GPU_SAMPLER_ICON + 1);
|
|
|
|
ENUM_OPERATORS(eGPUSamplerState, GPU_SAMPLER_ICON)
|
2020-07-29 14:50:20 +02:00
|
|
|
|
2020-07-28 16:32:30 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-09-05 17:31:53 +02:00
|
|
|
void GPU_samplers_update(void);
|
2020-06-02 10:47:45 +02:00
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
/* GPU Texture
|
|
|
|
* - always returns unsigned char RGBA textures
|
|
|
|
* - if texture with non square dimensions is created, depending on the
|
|
|
|
* graphics card capabilities the texture may actually be stored in a
|
|
|
|
* larger texture with power of two dimensions.
|
|
|
|
* - can use reference counting:
|
2018-11-14 12:53:15 +11:00
|
|
|
* - reference counter after GPU_texture_create is 1
|
|
|
|
* - GPU_texture_ref increases by one
|
|
|
|
* - GPU_texture_free decreases by one, and frees if 0
|
|
|
|
* - if created with from_blender, will not free the texture
|
2015-12-06 21:20:19 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* Wrapper to supported OpenGL/Vulkan texture internal storage
|
2021-02-05 16:23:34 +11:00
|
|
|
* If you need a type just un-comment it. Be aware that some formats
|
|
|
|
* are not supported by render-buffers. All of the following formats
|
2017-02-03 16:01:32 +01:00
|
|
|
* are part of the OpenGL 3.3 core
|
|
|
|
* specification. */
|
2019-01-23 14:15:43 +11:00
|
|
|
typedef enum eGPUTextureFormat {
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Formats texture & render-buffer. */
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_RGBA8UI,
|
|
|
|
GPU_RGBA8I,
|
|
|
|
GPU_RGBA8,
|
|
|
|
GPU_RGBA32UI,
|
|
|
|
GPU_RGBA32I,
|
2017-05-09 21:49:30 +02:00
|
|
|
GPU_RGBA32F,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_RGBA16UI,
|
|
|
|
GPU_RGBA16I,
|
2017-02-03 16:01:32 +01:00
|
|
|
GPU_RGBA16F,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_RGBA16,
|
|
|
|
GPU_RG8UI,
|
|
|
|
GPU_RG8I,
|
|
|
|
GPU_RG8,
|
|
|
|
GPU_RG32UI,
|
|
|
|
GPU_RG32I,
|
2017-02-03 16:01:32 +01:00
|
|
|
GPU_RG32F,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_RG16UI,
|
2018-01-13 17:14:01 +01:00
|
|
|
GPU_RG16I,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_RG16F,
|
2018-04-30 16:15:01 +02:00
|
|
|
GPU_RG16,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_R8UI,
|
|
|
|
GPU_R8I,
|
2017-02-03 16:01:32 +01:00
|
|
|
GPU_R8,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_R32UI,
|
2017-02-03 16:01:32 +01:00
|
|
|
GPU_R32I,
|
2018-05-13 22:12:32 +02:00
|
|
|
GPU_R32F,
|
|
|
|
GPU_R16UI,
|
|
|
|
GPU_R16I,
|
|
|
|
GPU_R16F,
|
|
|
|
GPU_R16, /* Max texture buffer format. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-20 17:01:28 +01:00
|
|
|
/* Special formats texture & renderbuffer */
|
2017-02-03 16:01:32 +01:00
|
|
|
GPU_RGB10_A2,
|
2017-05-16 20:18:57 +02:00
|
|
|
GPU_R11F_G11F_B10F,
|
2018-10-25 19:08:35 +02:00
|
|
|
GPU_DEPTH32F_STENCIL8,
|
2017-03-18 01:26:08 +01:00
|
|
|
GPU_DEPTH24_STENCIL8,
|
2020-02-11 15:18:55 +01:00
|
|
|
GPU_SRGB8_A8,
|
2021-02-20 17:01:28 +01:00
|
|
|
#if 0
|
|
|
|
GPU_RGB10_A2UI,
|
|
|
|
#endif
|
2017-02-03 16:01:32 +01:00
|
|
|
|
|
|
|
/* Texture only format */
|
2017-04-18 12:50:09 +02:00
|
|
|
GPU_RGB16F,
|
2017-02-03 16:01:32 +01:00
|
|
|
#if 0
|
|
|
|
GPU_RGBA16_SNORM,
|
|
|
|
GPU_RGBA8_SNORM,
|
|
|
|
GPU_RGB32F,
|
|
|
|
GPU_RGB32I,
|
|
|
|
GPU_RGB32UI,
|
|
|
|
GPU_RGB16_SNORM,
|
|
|
|
GPU_RGB16I,
|
|
|
|
GPU_RGB16UI,
|
|
|
|
GPU_RGB16,
|
|
|
|
GPU_RGB8_SNORM,
|
|
|
|
GPU_RGB8,
|
|
|
|
GPU_RGB8I,
|
|
|
|
GPU_RGB8UI,
|
|
|
|
GPU_RG16_SNORM,
|
|
|
|
GPU_RG8_SNORM,
|
|
|
|
GPU_R16_SNORM,
|
|
|
|
GPU_R8_SNORM,
|
|
|
|
#endif
|
|
|
|
|
2020-07-29 04:55:21 +02:00
|
|
|
/* Special formats texture only */
|
|
|
|
GPU_SRGB8_A8_DXT1,
|
|
|
|
GPU_SRGB8_A8_DXT3,
|
|
|
|
GPU_SRGB8_A8_DXT5,
|
|
|
|
GPU_RGBA8_DXT1,
|
|
|
|
GPU_RGBA8_DXT3,
|
|
|
|
GPU_RGBA8_DXT5,
|
2017-02-03 16:01:32 +01:00
|
|
|
#if 0
|
|
|
|
GPU_SRGB8,
|
|
|
|
GPU_RGB9_E5,
|
|
|
|
GPU_COMPRESSED_RG_RGTC2,
|
|
|
|
GPU_COMPRESSED_SIGNED_RG_RGTC2,
|
|
|
|
GPU_COMPRESSED_RED_RGTC1,
|
|
|
|
GPU_COMPRESSED_SIGNED_RED_RGTC1,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Depth Formats */
|
|
|
|
GPU_DEPTH_COMPONENT32F,
|
|
|
|
GPU_DEPTH_COMPONENT24,
|
|
|
|
GPU_DEPTH_COMPONENT16,
|
2019-01-23 14:15:43 +11:00
|
|
|
} eGPUTextureFormat;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2019-01-23 14:15:43 +11:00
|
|
|
typedef enum eGPUDataFormat {
|
2018-07-10 13:17:32 +02:00
|
|
|
GPU_DATA_FLOAT,
|
|
|
|
GPU_DATA_INT,
|
2021-02-17 12:38:21 -03:00
|
|
|
GPU_DATA_UINT,
|
|
|
|
GPU_DATA_UBYTE,
|
|
|
|
GPU_DATA_UINT_24_8,
|
2018-07-10 13:17:32 +02:00
|
|
|
GPU_DATA_10_11_11_REV,
|
2021-02-20 17:01:28 +01:00
|
|
|
GPU_DATA_2_10_10_10_REV,
|
2019-01-23 14:15:43 +11:00
|
|
|
} eGPUDataFormat;
|
2018-07-10 13:17:32 +02:00
|
|
|
|
2017-05-04 21:22:41 +02:00
|
|
|
unsigned int GPU_texture_memory_usage_get(void);
|
|
|
|
|
2020-09-05 17:33:56 +02:00
|
|
|
/**
|
|
|
|
* \note \a data is expected to be float. If the \a format is not compatible with float data or if
|
|
|
|
* the data is not in float format, use GPU_texture_update to upload the data with the right data
|
|
|
|
* format.
|
|
|
|
* \a mips is the number of mip level to allocate. It must be >= 1.
|
|
|
|
*/
|
|
|
|
GPUTexture *GPU_texture_create_1d(
|
|
|
|
const char *name, int w, int mips, eGPUTextureFormat format, const float *data);
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *GPU_texture_create_1d_array(
|
2020-09-05 17:33:56 +02:00
|
|
|
const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data);
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *GPU_texture_create_2d(
|
2020-09-05 17:33:56 +02:00
|
|
|
const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data);
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *GPU_texture_create_2d_array(
|
2020-09-05 17:33:56 +02:00
|
|
|
const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data);
|
2020-09-15 21:21:14 +05:30
|
|
|
GPUTexture *GPU_texture_create_3d(const char *name,
|
|
|
|
int w,
|
|
|
|
int h,
|
|
|
|
int d,
|
|
|
|
int mips,
|
|
|
|
eGPUTextureFormat texture_format,
|
|
|
|
eGPUDataFormat data_format,
|
|
|
|
const void *data);
|
2020-09-05 17:33:56 +02:00
|
|
|
GPUTexture *GPU_texture_create_cube(
|
|
|
|
const char *name, int w, int mips, eGPUTextureFormat format, const float *data);
|
2020-03-11 17:12:01 +01:00
|
|
|
GPUTexture *GPU_texture_create_cube_array(
|
2020-09-05 17:33:56 +02:00
|
|
|
const char *name, int w, int d, int mips, eGPUTextureFormat format, const float *data);
|
2020-07-29 04:55:21 +02:00
|
|
|
|
2020-09-05 17:33:56 +02:00
|
|
|
/* Special textures. */
|
|
|
|
GPUTexture *GPU_texture_create_from_vertbuf(const char *name, struct GPUVertBuf *vert);
|
|
|
|
/**
|
|
|
|
* \a data should hold all the data for all mipmaps.
|
|
|
|
*/
|
|
|
|
GPUTexture *GPU_texture_create_compressed_2d(
|
|
|
|
const char *name, int w, int h, int miplen, eGPUTextureFormat format, const void *data);
|
2020-07-29 18:13:19 +02:00
|
|
|
GPUTexture *GPU_texture_create_error(int dimension, bool array);
|
|
|
|
|
2020-09-05 17:33:56 +02:00
|
|
|
void GPU_texture_update_mipmap(GPUTexture *tex,
|
|
|
|
int miplvl,
|
|
|
|
eGPUDataFormat gpu_data_format,
|
|
|
|
const void *pixels);
|
2018-07-10 13:17:32 +02:00
|
|
|
|
2020-09-07 13:59:22 +02:00
|
|
|
void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *data);
|
2018-06-22 08:18:02 +02:00
|
|
|
void GPU_texture_update_sub(GPUTexture *tex,
|
2020-09-07 13:59:22 +02:00
|
|
|
eGPUDataFormat data_format,
|
2019-01-23 14:15:43 +11:00
|
|
|
const void *pixels,
|
2018-06-22 08:18:02 +02:00
|
|
|
int offset_x,
|
|
|
|
int offset_y,
|
|
|
|
int offset_z,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth);
|
2020-09-08 00:30:38 +02:00
|
|
|
void GPU_unpack_row_length_set(uint len);
|
2017-08-22 10:22:11 +02:00
|
|
|
|
2020-09-07 13:59:22 +02:00
|
|
|
void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl);
|
|
|
|
void GPU_texture_clear(GPUTexture *tex, eGPUDataFormat data_format, const void *data);
|
2018-07-10 13:17:32 +02:00
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
void GPU_texture_free(GPUTexture *tex);
|
|
|
|
|
|
|
|
void GPU_texture_ref(GPUTexture *tex);
|
2020-09-04 20:59:13 +02:00
|
|
|
void GPU_texture_bind(GPUTexture *tex, int unit);
|
2020-06-03 13:03:36 +02:00
|
|
|
void GPU_texture_bind_ex(GPUTexture *tex, eGPUSamplerState state, int unit, const bool set_number);
|
2015-12-06 21:20:19 +01:00
|
|
|
void GPU_texture_unbind(GPUTexture *tex);
|
2020-06-02 18:14:28 +02:00
|
|
|
void GPU_texture_unbind_all(void);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2020-09-12 06:10:11 +02:00
|
|
|
void GPU_texture_image_bind(GPUTexture *tex, int unit);
|
|
|
|
void GPU_texture_image_unbind(GPUTexture *tex);
|
|
|
|
void GPU_texture_image_unbind_all(void);
|
|
|
|
|
2020-04-22 21:22:07 +02:00
|
|
|
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src);
|
|
|
|
|
2017-04-18 11:21:17 +02:00
|
|
|
void GPU_texture_generate_mipmap(GPUTexture *tex);
|
2020-07-29 04:55:21 +02:00
|
|
|
void GPU_texture_anisotropic_filter(GPUTexture *tex, bool use_aniso);
|
2017-02-03 16:01:32 +01:00
|
|
|
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare);
|
|
|
|
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter);
|
2017-06-22 01:53:51 +02:00
|
|
|
void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter);
|
2020-05-07 22:01:26 +02:00
|
|
|
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp);
|
2020-07-17 02:15:41 +02:00
|
|
|
void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4]);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
int GPU_texture_width(const GPUTexture *tex);
|
|
|
|
int GPU_texture_height(const GPUTexture *tex);
|
2019-06-24 22:09:04 +10:00
|
|
|
int GPU_texture_orig_width(const GPUTexture *tex);
|
|
|
|
int GPU_texture_orig_height(const GPUTexture *tex);
|
|
|
|
void GPU_texture_orig_size_set(GPUTexture *tex, int w, int h);
|
2019-01-23 14:15:43 +11:00
|
|
|
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex);
|
2020-03-11 17:12:01 +01:00
|
|
|
bool GPU_texture_array(const GPUTexture *tex);
|
2018-03-24 20:27:39 +01:00
|
|
|
bool GPU_texture_cube(const GPUTexture *tex);
|
2017-03-18 01:26:08 +01:00
|
|
|
bool GPU_texture_depth(const GPUTexture *tex);
|
|
|
|
bool GPU_texture_stencil(const GPUTexture *tex);
|
2018-03-24 20:27:39 +01:00
|
|
|
bool GPU_texture_integer(const GPUTexture *tex);
|
2015-12-06 21:20:19 +01:00
|
|
|
int GPU_texture_opengl_bindcode(const GPUTexture *tex);
|
|
|
|
|
2018-07-10 13:17:32 +02:00
|
|
|
void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size);
|
|
|
|
|
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
|
|
|
/* utilities */
|
|
|
|
size_t GPU_texture_component_len(eGPUTextureFormat format);
|
|
|
|
size_t GPU_texture_dataformat_size(eGPUDataFormat data_format);
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|