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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/*
* 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.
*
* Copyright 2016, Blender Foundation.
*/
/** \file
* \ingroup draw
*/
#include "draw_manager.h"
#ifndef NDEBUG
/* Maybe gpu_texture.c is a better place for this. */
static bool drw_texture_format_supports_framebuffer(eGPUTextureFormat format)
{
/* Some formats do not work with framebuffers. */
switch (format) {
/* Only add formats that are COMPATIBLE with FB.
* Generally they are multiple of 16bit. */
case GPU_R8:
case GPU_R8UI:
case GPU_R16F:
case GPU_R16I:
case GPU_R16UI:
case GPU_R16:
case GPU_R32F:
case GPU_R32UI:
case GPU_RG8:
case GPU_RG16:
case GPU_RG16F:
case GPU_RG16I:
case GPU_RG32F:
case GPU_R11F_G11F_B10F:
case GPU_RGBA8:
case GPU_RGBA16:
case GPU_RGBA16F:
case GPU_RGBA32F:
case GPU_DEPTH_COMPONENT16:
case GPU_DEPTH_COMPONENT24:
case GPU_DEPTH24_STENCIL8:
case GPU_DEPTH_COMPONENT32F:
return true;
default:
return false;
}
}
#endif
void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
{
if (tex == NULL) {
return;
}
if (flags & DRW_TEX_MIPMAP) {
GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
GPU_texture_generate_mipmap(tex);
}
else {
GPU_texture_filter_mode(tex, flags & DRW_TEX_FILTER);
}
GPU_texture_wrap_mode(tex, flags & DRW_TEX_WRAP, true);
GPU_texture_compare_mode(tex, flags & DRW_TEX_COMPARE);
}
GPUTexture *DRW_texture_create_1d(int w,
eGPUTextureFormat format,
DRWTextureFlag flags,
const float *fpixels)
{
int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_1d(__func__, w, mips, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
GPUTexture *DRW_texture_create_2d(
int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_2d(__func__, w, h, mips, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
GPUTexture *DRW_texture_create_2d_array(
int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_2d_array(__func__, w, h, d, mips, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
GPUTexture *DRW_texture_create_3d(
int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_3d(
__func__, w, h, d, mips, format, GPU_DATA_FLOAT, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
GPUTexture *DRW_texture_create_cube(int w,
eGPUTextureFormat format,
DRWTextureFlag flags,
const float *fpixels)
{
int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_cube(__func__, w, mips, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
GPUTexture *DRW_texture_create_cube_array(
int w, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
{
int mips = (flags & DRW_TEX_MIPMAP) ? 9999 : 1;
GPUTexture *tex = GPU_texture_create_cube_array(__func__, w, d, mips, format, fpixels);
drw_texture_set_parameters(tex, flags);
return tex;
}
GPUTexture *DRW_texture_pool_query_2d(int w,
int h,
eGPUTextureFormat format,
DrawEngineType *engine_type)
{
BLI_assert(drw_texture_format_supports_framebuffer(format));
GPUTexture *tex = GPU_viewport_texture_pool_query(DST.viewport, engine_type, w, h, format);
return tex;
}
GPUTexture *DRW_texture_pool_query_fullscreen(eGPUTextureFormat format,
DrawEngineType *engine_type)
{
const float *size = DRW_viewport_size_get();
return DRW_texture_pool_query_2d((int)size[0], (int)size[1], format, engine_type);
}
void DRW_texture_ensure_fullscreen_2d(GPUTexture **tex,
eGPUTextureFormat format,
DRWTextureFlag flags)
{
if (*(tex) == NULL) {
const float *size = DRW_viewport_size_get();
*(tex) = DRW_texture_create_2d((int)size[0], (int)size[1], format, flags, NULL);
}
}
void DRW_texture_ensure_2d(
GPUTexture **tex, int w, int h, eGPUTextureFormat format, DRWTextureFlag flags)
{
if (*(tex) == NULL) {
*(tex) = DRW_texture_create_2d(w, h, format, flags, NULL);
}
}
void DRW_texture_generate_mipmaps(GPUTexture *tex)
{
GPU_texture_generate_mipmap(tex);
}
void DRW_texture_free(GPUTexture *tex)
{
GPU_texture_free(tex);
}
|