Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_texture_private.hh « intern « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5eeb3d9e0f0fc765c97f24343ec2e8c59e918198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * 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"

#include "gpu_framebuffer_private.hh"

namespace blender {
namespace gpu {

typedef enum eGPUTextureFlag {
  GPU_TEXFORMAT_DEPTH = (1 << 0),
  GPU_TEXFORMAT_STENCIL = (1 << 1),
  GPU_TEXFORMAT_INTEGER = (1 << 2),
  GPU_TEXFORMAT_FLOAT = (1 << 3),

  GPU_TEXTURE_1D = (1 << 10),
  GPU_TEXTURE_2D = (1 << 11),
  GPU_TEXTURE_3D = (1 << 12),
  GPU_TEXTURE_CUBE = (1 << 13),
  GPU_TEXTURE_ARRAY = (1 << 14),
  GPU_TEXTURE_BUFFER = (1 << 15),

  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),

  GPU_TEXTURE_TARGET = (GPU_TEXTURE_1D | GPU_TEXTURE_2D | GPU_TEXTURE_3D | GPU_TEXTURE_CUBE |
                        GPU_TEXTURE_ARRAY),
} eGPUTextureFlag;

ENUM_OPERATORS(eGPUTextureFlag)

#ifdef DEBUG
#  define DEBUG_NAME_LEN 64
#else
#  define DEBUG_NAME_LEN 8
#endif

/* Maximum number of FBOs a texture can be attached to. */
#define GPU_TEX_MAX_FBO_ATTACHED 12

class Texture {
 public:
  /** Width & Height & Depth. */
  int w = 0, h = 0, d = 0;
  /** Number of color/alpha channels. */
  int components = 0;
  /** Internal data format and it's characteristics. */
  eGPUTextureFormat format;
  eGPUTextureFlag flag;
  /** Internal Sampler state. */
  eGPUSamplerState sampler_state;
  /** Number of mipmaps this texture has. */
  int mipmaps = 0;
  /** Reference counter. */
  int refcount = 0;
  /** Width & Height (of source data), optional. */
  int src_w = 0, src_h = 0;
  /** Framebuffer references to update on deletion. */
  GPUAttachmentType fb_attachment[GPU_TEX_MAX_FBO_ATTACHED];
  FrameBuffer *fb[GPU_TEX_MAX_FBO_ATTACHED];

 protected:
  /** For debugging */
  char name_[DEBUG_NAME_LEN];

 public:
  Texture(const char *name);
  virtual ~Texture();

  virtual void bind(int slot) = 0;
  virtual void update(void *data) = 0;
  virtual void update_sub(void *data, int offset[3], int size[3]) = 0;
  virtual void generate_mipmap(void) = 0;
  virtual void copy_to(Texture *tex) = 0;

  virtual void swizzle_set(char swizzle_mask[4]) = 0;

  /* TODO(fclem) Legacy. Should be removed at some point. */
  virtual uint gl_bindcode_get(void) = 0;

  void attach_to(FrameBuffer *fb);

  GPUAttachmentType attachment_type(int slot) const
  {
    switch (format) {
      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:
        return GPU_FB_COLOR_ATTACHMENT0 + slot;
    }
  }
};

#undef DEBUG_NAME_LEN

}  // namespace gpu
}  // namespace blender