2018-02-28 01:16:23 +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.
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2018-02-28 01:16:23 +01:00
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup draw
|
2018-02-28 01:16:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "draw_manager.h"
|
|
|
|
|
2018-05-02 10:32:01 +02:00
|
|
|
#ifndef NDEBUG
|
2018-04-30 16:02:24 +02:00
|
|
|
/* Maybe gpu_texture.c is a better place for this. */
|
2019-01-23 14:15:43 +11:00
|
|
|
static bool drw_texture_format_supports_framebuffer(eGPUTextureFormat format)
|
2018-02-28 01:16:23 +01:00
|
|
|
{
|
|
|
|
/* Some formats do not work with framebuffers. */
|
|
|
|
switch (format) {
|
2018-04-30 16:02:24 +02:00
|
|
|
/* Only add formats that are COMPATIBLE with FB.
|
|
|
|
* Generally they are multiple of 16bit. */
|
2018-12-03 00:36:54 +01:00
|
|
|
case GPU_R8:
|
|
|
|
case GPU_R8UI:
|
2018-04-30 16:02:24 +02:00
|
|
|
case GPU_R16F:
|
|
|
|
case GPU_R16I:
|
|
|
|
case GPU_R16UI:
|
2018-11-30 01:42:51 +01:00
|
|
|
case GPU_R16:
|
2018-04-30 16:02:24 +02:00
|
|
|
case GPU_R32F:
|
|
|
|
case GPU_R32UI:
|
|
|
|
case GPU_RG8:
|
2018-04-30 16:15:01 +02:00
|
|
|
case GPU_RG16:
|
2018-04-30 16:02:24 +02:00
|
|
|
case GPU_RG16F:
|
|
|
|
case GPU_RG16I:
|
|
|
|
case GPU_RG32F:
|
|
|
|
case GPU_R11F_G11F_B10F:
|
|
|
|
case GPU_RGBA8:
|
|
|
|
case GPU_RGBA16F:
|
|
|
|
case GPU_RGBA32F:
|
|
|
|
case GPU_DEPTH_COMPONENT16:
|
|
|
|
case GPU_DEPTH_COMPONENT24:
|
|
|
|
case GPU_DEPTH24_STENCIL8:
|
|
|
|
case GPU_DEPTH_COMPONENT32F:
|
|
|
|
return true;
|
2018-02-28 01:16:23 +01:00
|
|
|
default:
|
2018-04-30 16:02:24 +02:00
|
|
|
return false;
|
2018-02-28 01:16:23 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-03 14:37:53 +02:00
|
|
|
#endif
|
2018-02-28 01:16:23 +01:00
|
|
|
|
|
|
|
void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
|
|
|
|
{
|
|
|
|
GPU_texture_bind(tex, 0);
|
|
|
|
if (flags & DRW_TEX_MIPMAP) {
|
|
|
|
GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
|
2018-03-24 20:27:39 +01:00
|
|
|
GPU_texture_generate_mipmap(tex);
|
2018-02-28 01:16:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
GPU_texture_filter_mode(tex, flags & DRW_TEX_FILTER);
|
|
|
|
}
|
|
|
|
GPU_texture_wrap_mode(tex, flags & DRW_TEX_WRAP);
|
|
|
|
GPU_texture_compare_mode(tex, flags & DRW_TEX_COMPARE);
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *DRW_texture_create_1d(int w, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
|
2018-02-28 01:16:23 +01:00
|
|
|
{
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *tex = GPU_texture_create_1d(w, format, fpixels, NULL);
|
2018-02-28 01:16:23 +01:00
|
|
|
drw_texture_set_parameters(tex, flags);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *DRW_texture_create_2d(int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
|
2018-02-28 01:16:23 +01:00
|
|
|
{
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *tex = GPU_texture_create_2d(w, h, format, fpixels, NULL);
|
2018-02-28 01:16:23 +01:00
|
|
|
drw_texture_set_parameters(tex, flags);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *DRW_texture_create_2d_array(
|
2019-01-23 14:15:43 +11:00
|
|
|
int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
|
2018-02-28 01:16:23 +01:00
|
|
|
{
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *tex = GPU_texture_create_2d_array(w, h, d, format, fpixels, NULL);
|
2018-02-28 01:16:23 +01:00
|
|
|
drw_texture_set_parameters(tex, flags);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *DRW_texture_create_3d(
|
2019-01-23 14:15:43 +11:00
|
|
|
int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
|
2018-02-28 01:16:23 +01:00
|
|
|
{
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *tex = GPU_texture_create_3d(w, h, d, format, fpixels, NULL);
|
2018-02-28 01:16:23 +01:00
|
|
|
drw_texture_set_parameters(tex, flags);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:15:43 +11:00
|
|
|
GPUTexture *DRW_texture_create_cube(int w, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
|
2018-02-28 01:16:23 +01:00
|
|
|
{
|
2018-04-30 16:02:24 +02:00
|
|
|
GPUTexture *tex = GPU_texture_create_cube(w, format, fpixels, NULL);
|
2018-02-28 01:16:23 +01:00
|
|
|
drw_texture_set_parameters(tex, flags);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
GPUTexture *DRW_texture_pool_query_2d(int w, int h, eGPUTextureFormat format, DrawEngineType *engine_type)
|
2018-03-25 17:46:48 +02:00
|
|
|
{
|
2018-04-30 16:02:24 +02:00
|
|
|
BLI_assert(drw_texture_format_supports_framebuffer(format));
|
|
|
|
GPUTexture *tex = GPU_viewport_texture_pool_query(DST.viewport, engine_type, w, h, format);
|
2018-03-25 17:46:48 +02:00
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
void DRW_texture_ensure_fullscreen_2d(GPUTexture **tex, eGPUTextureFormat format, DRWTextureFlag flags)
|
2018-03-25 17:46:48 +02:00
|
|
|
{
|
|
|
|
if (*(tex) == NULL) {
|
|
|
|
const float *size = DRW_viewport_size_get();
|
2019-03-20 18:17:16 +11:00
|
|
|
*(tex) = DRW_texture_create_2d((int)size[0], (int)size[1], format, flags, NULL);
|
2018-03-25 17:46:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:17:16 +11:00
|
|
|
void DRW_texture_ensure_2d(GPUTexture **tex, int w, int h, eGPUTextureFormat format, DRWTextureFlag flags)
|
2018-03-25 17:46:48 +02:00
|
|
|
{
|
|
|
|
if (*(tex) == NULL) {
|
2019-03-20 18:17:16 +11:00
|
|
|
*(tex) = DRW_texture_create_2d(w, h, format, flags, NULL);
|
2018-03-25 17:46:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 01:16:23 +01:00
|
|
|
void DRW_texture_generate_mipmaps(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
GPU_texture_bind(tex, 0);
|
|
|
|
GPU_texture_generate_mipmap(tex);
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DRW_texture_free(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
GPU_texture_free(tex);
|
|
|
|
}
|