2015-12-06 21:20:19 +01:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Brecht Van Lommel.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_image_types.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BLI_math_base.h"
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
|
|
|
#include "GPU_debug.h"
|
|
|
|
#include "GPU_draw.h"
|
|
|
|
#include "GPU_extensions.h"
|
|
|
|
#include "GPU_framebuffer.h"
|
|
|
|
#include "GPU_glew.h"
|
|
|
|
#include "GPU_texture.h"
|
|
|
|
|
|
|
|
static struct GPUTextureGlobal {
|
|
|
|
GPUTexture *invalid_tex_1D; /* texture used in place of invalid textures (not loaded correctly, missing) */
|
|
|
|
GPUTexture *invalid_tex_2D;
|
|
|
|
GPUTexture *invalid_tex_3D;
|
|
|
|
} GG = {NULL, NULL, NULL};
|
|
|
|
|
|
|
|
/* GPUTexture */
|
|
|
|
struct GPUTexture {
|
2017-02-03 16:01:32 +01:00
|
|
|
int w, h, d; /* width/height/depth */
|
2015-12-06 21:20:19 +01:00
|
|
|
int number; /* number for multitexture binding */
|
|
|
|
int refcount; /* reference count */
|
|
|
|
GLenum target; /* GL_TEXTURE_* */
|
2016-08-09 12:29:14 +03:00
|
|
|
GLenum target_base; /* same as target, (but no multisample)
|
|
|
|
* use it for unbinding */
|
2015-12-06 21:20:19 +01:00
|
|
|
GLuint bindcode; /* opengl identifier for texture */
|
|
|
|
int fromblender; /* we got the texture from Blender */
|
|
|
|
|
|
|
|
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
|
|
|
|
int fb_attachment; /* slot the texture is attached to */
|
2017-02-03 16:01:32 +01:00
|
|
|
bool depth; /* is a depth texture? */
|
2015-12-06 21:20:19 +01:00
|
|
|
};
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
static GLenum GPU_texture_get_format(int components, GPUTextureFormat data_type, GLenum *format, bool *is_depth)
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
if (data_type == GPU_DEPTH_COMPONENT24 ||
|
|
|
|
data_type == GPU_DEPTH_COMPONENT16 ||
|
|
|
|
data_type == GPU_DEPTH_COMPONENT32F)
|
|
|
|
{
|
|
|
|
*is_depth = true;
|
|
|
|
*format = GL_DEPTH_COMPONENT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*is_depth = false;
|
|
|
|
|
|
|
|
switch (components) {
|
|
|
|
case 1: *format = GL_RED; break;
|
|
|
|
case 2: *format = GL_RG; break;
|
|
|
|
case 3: *format = GL_RGB; break;
|
|
|
|
case 4: *format = GL_RGBA; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* You can add any of the available type to this list
|
|
|
|
* For available types see GPU_texture.h */
|
|
|
|
switch (data_type) {
|
|
|
|
/* Formats texture & renderbuffer */
|
|
|
|
case GPU_RGBA16F: return GL_RGBA16F;
|
|
|
|
case GPU_RG32F: return GL_RG32F;
|
2017-02-07 11:20:15 +01:00
|
|
|
case GPU_RG16F: return GL_RG16F;
|
2017-02-03 16:01:32 +01:00
|
|
|
case GPU_RGBA8: return GL_RGBA8;
|
|
|
|
case GPU_R8: return GL_R8;
|
|
|
|
/* Special formats texture & renderbuffer */
|
|
|
|
/* ** Add Format here **/
|
|
|
|
/* Texture only format */
|
|
|
|
/* ** Add Format here **/
|
|
|
|
/* Special formats texture only */
|
|
|
|
/* ** Add Format here **/
|
|
|
|
/* Depth Formats */
|
|
|
|
case GPU_DEPTH_COMPONENT32F: return GL_DEPTH_COMPONENT32F;
|
|
|
|
case GPU_DEPTH_COMPONENT24: return GL_DEPTH_COMPONENT24;
|
|
|
|
case GPU_DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT16;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Texture format incorrect or unsupported\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
static float *GPU_texture_3D_rescale(GPUTexture *tex, int w, int h, int d, int channels, const float *fpixels)
|
|
|
|
{
|
|
|
|
const unsigned int xf = w / tex->w, yf = h / tex->h, zf = d / tex->d;
|
|
|
|
float *nfpixels = MEM_mallocN(channels * sizeof(float) * tex->w * tex->h * tex->d, "GPUTexture Rescaled 3Dtex");
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
if (nfpixels) {
|
|
|
|
GPU_print_error_debug("You need to scale a 3D texture, feel the pain!");
|
|
|
|
|
|
|
|
for (unsigned k = 0; k < tex->d; k++) {
|
|
|
|
for (unsigned j = 0; j < tex->h; j++) {
|
|
|
|
for (unsigned i = 0; i < tex->w; i++) {
|
|
|
|
/* obviously doing nearest filtering here,
|
|
|
|
* it's going to be slow in any case, let's not make it worse */
|
|
|
|
float xb = i * xf;
|
|
|
|
float yb = j * yf;
|
|
|
|
float zb = k * zf;
|
|
|
|
unsigned int offset = k * (tex->w * tex->h) + i * tex->h + j;
|
|
|
|
unsigned int offset_orig = (zb) * (w * h) + (xb) * h + (yb);
|
|
|
|
|
|
|
|
if (channels == 4) {
|
|
|
|
nfpixels[offset * 4] = fpixels[offset_orig * 4];
|
|
|
|
nfpixels[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
|
|
|
|
nfpixels[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
|
|
|
|
nfpixels[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nfpixels[offset] = fpixels[offset_orig];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nfpixels;
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* This tries to allocate video memory for a given texture
|
|
|
|
* If alloc fails, lower the resolution until it fits. */
|
|
|
|
static bool GPU_texture_try_alloc(
|
|
|
|
GPUTexture *tex, GLenum proxy, GLenum internalformat, GLenum format, int channels,
|
|
|
|
bool try_rescale, const float *fpixels, float **rescaled_fpixels)
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
int r_width;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
switch (proxy) {
|
|
|
|
case GL_PROXY_TEXTURE_1D:
|
|
|
|
glTexImage1D(proxy, 0, internalformat, tex->w, 0, format, GL_FLOAT, NULL);
|
|
|
|
break;
|
|
|
|
case GL_PROXY_TEXTURE_2D:
|
|
|
|
glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, format, GL_FLOAT, NULL);
|
|
|
|
break;
|
|
|
|
case GL_PROXY_TEXTURE_3D:
|
|
|
|
glTexImage3D(proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, format, GL_FLOAT, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &r_width);
|
|
|
|
|
|
|
|
if (r_width == 0 && try_rescale) {
|
|
|
|
const int w = tex->w, h = tex->h, d = tex->d;
|
|
|
|
|
|
|
|
/* Find largest texture possible */
|
|
|
|
while (r_width == 0) {
|
|
|
|
tex->w /= 2;
|
|
|
|
tex->h /= 2;
|
|
|
|
tex->d /= 2;
|
|
|
|
|
|
|
|
/* really unlikely to happen but keep this just in case */
|
|
|
|
if (tex->w == 0) break;
|
|
|
|
if (tex->h == 0 && proxy != GL_PROXY_TEXTURE_1D) break;
|
|
|
|
if (tex->d == 0 && proxy == GL_PROXY_TEXTURE_3D) break;
|
|
|
|
|
|
|
|
if (proxy == GL_PROXY_TEXTURE_1D)
|
|
|
|
glTexImage1D(proxy, 0, internalformat, tex->w, 0, format, GL_FLOAT, NULL);
|
|
|
|
else if (proxy == GL_PROXY_TEXTURE_2D)
|
|
|
|
glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, format, GL_FLOAT, NULL);
|
|
|
|
else if (proxy == GL_PROXY_TEXTURE_3D)
|
|
|
|
glTexImage3D(proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, format, GL_FLOAT, NULL);
|
|
|
|
|
|
|
|
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rescale */
|
|
|
|
if (r_width > 0) {
|
|
|
|
switch (proxy) {
|
|
|
|
case GL_PROXY_TEXTURE_1D:
|
|
|
|
case GL_PROXY_TEXTURE_2D:
|
|
|
|
/* Do nothing for now */
|
|
|
|
return false;
|
|
|
|
case GL_PROXY_TEXTURE_3D:
|
|
|
|
*rescaled_fpixels = GPU_texture_3D_rescale(tex, w, h, d, channels, fpixels);
|
|
|
|
return (bool)*rescaled_fpixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (r_width > 0);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static GPUTexture *GPU_texture_create_nD(
|
2017-02-03 16:01:32 +01:00
|
|
|
int w, int h, int d, int n, const float *fpixels,
|
|
|
|
GPUTextureFormat data_type, int components, int samples,
|
|
|
|
const bool can_rescale, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
GLenum format, internalformat, proxy;
|
|
|
|
float *rescaled_fpixels = NULL;
|
|
|
|
const float *pix;
|
|
|
|
bool valid;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
if (samples) {
|
|
|
|
CLAMP_MAX(samples, GPU_max_color_texture_samples());
|
|
|
|
}
|
|
|
|
|
2016-01-07 16:32:02 -05:00
|
|
|
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
2015-12-06 21:20:19 +01:00
|
|
|
tex->w = w;
|
|
|
|
tex->h = h;
|
2017-02-03 16:01:32 +01:00
|
|
|
tex->d = d;
|
2015-12-06 21:20:19 +01:00
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
2017-02-03 16:01:32 +01:00
|
|
|
|
|
|
|
if (n == 1) {
|
|
|
|
if (h == 0)
|
|
|
|
tex->target_base = tex->target = GL_TEXTURE_1D;
|
|
|
|
else
|
|
|
|
tex->target_base = tex->target = GL_TEXTURE_1D_ARRAY;
|
|
|
|
}
|
|
|
|
else if (n == 2) {
|
|
|
|
if (d == 0)
|
|
|
|
tex->target_base = tex->target = GL_TEXTURE_2D;
|
|
|
|
else
|
|
|
|
tex->target_base = tex->target = GL_TEXTURE_2D_ARRAY;
|
|
|
|
}
|
|
|
|
else if (n == 3) {
|
|
|
|
tex->target_base = tex->target = GL_TEXTURE_3D;
|
|
|
|
}
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
tex->fb_attachment = -1;
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
if (samples && n == 2 && d == 0)
|
|
|
|
tex->target = GL_TEXTURE_2D_MULTISAMPLE;
|
|
|
|
|
|
|
|
internalformat = GPU_texture_get_format(components, data_type, &format, &tex->depth);
|
|
|
|
|
|
|
|
/* Generate Texture object */
|
2015-12-06 21:20:19 +01:00
|
|
|
glGenTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
if (!tex->bindcode) {
|
2017-02-03 16:01:32 +01:00
|
|
|
if (err_out)
|
2016-08-19 00:52:52 -04:00
|
|
|
BLI_snprintf(err_out, 256, "GPUTexture: texture create failed");
|
2017-02-03 16:01:32 +01:00
|
|
|
else
|
2016-08-19 00:52:52 -04:00
|
|
|
fprintf(stderr, "GPUTexture: texture create failed");
|
2015-12-06 21:20:19 +01:00
|
|
|
GPU_texture_free(tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex->number = 0;
|
|
|
|
glBindTexture(tex->target, tex->bindcode);
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* Check if texture fit in VRAM */
|
|
|
|
if (d > 0) {
|
|
|
|
proxy = GL_PROXY_TEXTURE_3D;
|
|
|
|
}
|
|
|
|
else if (h > 0) {
|
|
|
|
proxy = GL_PROXY_TEXTURE_2D;
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-02-03 16:01:32 +01:00
|
|
|
proxy = GL_PROXY_TEXTURE_1D;
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
valid = GPU_texture_try_alloc(tex, proxy, internalformat, format, components, can_rescale, fpixels,
|
|
|
|
&rescaled_fpixels);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
if (!valid) {
|
|
|
|
if (err_out)
|
|
|
|
BLI_snprintf(err_out, 256, "GPUTexture: texture alloc failed");
|
|
|
|
else
|
|
|
|
fprintf(stderr, "GPUTexture: texture alloc failed. Not enough Video Memory.");
|
|
|
|
GPU_texture_free(tex);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* Upload Texture */
|
|
|
|
pix = (rescaled_fpixels) ? rescaled_fpixels : fpixels;
|
|
|
|
|
|
|
|
if (tex->target == GL_TEXTURE_1D) {
|
|
|
|
glTexImage1D(tex->target, 0, internalformat, tex->w, 0, format, GL_FLOAT, pix);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
2017-02-03 16:01:32 +01:00
|
|
|
else if (tex->target == GL_TEXTURE_1D_ARRAY ||
|
|
|
|
tex->target == GL_TEXTURE_2D ||
|
|
|
|
tex->target == GL_TEXTURE_2D_MULTISAMPLE)
|
|
|
|
{
|
2015-12-06 21:20:19 +01:00
|
|
|
if (samples) {
|
|
|
|
glTexImage2DMultisample(tex->target, samples, internalformat, tex->w, tex->h, true);
|
2017-02-03 16:01:32 +01:00
|
|
|
if (pix)
|
|
|
|
glTexSubImage2D(tex->target, 0, 0, 0, tex->w, tex->h, format, GL_FLOAT, pix);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-02-03 16:01:32 +01:00
|
|
|
glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0, format, GL_FLOAT, pix);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-03 16:01:32 +01:00
|
|
|
else {
|
|
|
|
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->d, 0, format, GL_FLOAT, pix);
|
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
if (rescaled_fpixels)
|
|
|
|
MEM_freeN(rescaled_fpixels);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* Texture Parameters */
|
|
|
|
if (tex->depth) {
|
2015-12-06 21:20:19 +01:00
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
|
|
|
glTexParameteri(tex->target_base, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
if (n > 1) {
|
2015-12-06 21:20:19 +01:00
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2017-02-03 16:01:32 +01:00
|
|
|
if (n > 2) {
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GPU_texture_unbind(tex);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget, bool is_data, double time, int mipmap)
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
int gputt;
|
2015-12-06 21:20:19 +01:00
|
|
|
/* this binds a texture, so that's why to restore it to 0 */
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
GLint bindcode = GPU_verify_image(ima, iuser, textarget, 0, 0, mipmap, is_data);
|
|
|
|
GPU_update_image_time(ima, time);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2016-08-09 12:29:14 +03:00
|
|
|
/* see GPUInput::textarget: it can take two values - GL_TEXTURE_2D and GL_TEXTURE_CUBE_MAP
|
|
|
|
* these values are correct for glDisable, so textarget can be safely used in
|
|
|
|
* GPU_texture_bind/GPU_texture_unbind through tex->target_base */
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
if (textarget == GL_TEXTURE_2D)
|
|
|
|
gputt = TEXTARGET_TEXTURE_2D;
|
|
|
|
else
|
|
|
|
gputt = TEXTARGET_TEXTURE_CUBE_MAP;
|
|
|
|
|
|
|
|
if (ima->gputexture[gputt]) {
|
|
|
|
ima->gputexture[gputt]->bindcode = bindcode;
|
|
|
|
glBindTexture(textarget, 0);
|
|
|
|
return ima->gputexture[gputt];
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2016-01-07 16:32:02 -05:00
|
|
|
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
2015-12-06 21:20:19 +01:00
|
|
|
tex->bindcode = bindcode;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
tex->target = textarget;
|
2016-08-09 12:29:14 +03:00
|
|
|
tex->target_base = textarget;
|
2015-12-06 21:20:19 +01:00
|
|
|
tex->fromblender = 1;
|
|
|
|
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
ima->gputexture[gputt] = tex;
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
if (!glIsTexture(tex->bindcode)) {
|
2016-08-19 00:52:52 -04:00
|
|
|
GPU_print_error_debug("Blender Texture Not Loaded");
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-01-07 16:32:02 -05:00
|
|
|
GLint w, h, border;
|
|
|
|
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
GLenum gettarget;
|
|
|
|
|
|
|
|
if (textarget == GL_TEXTURE_2D)
|
|
|
|
gettarget = GL_TEXTURE_2D;
|
|
|
|
else
|
|
|
|
gettarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
|
|
|
|
|
|
|
|
glBindTexture(textarget, tex->bindcode);
|
|
|
|
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_BORDER, &border);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
tex->w = w - border;
|
|
|
|
tex->h = h - border;
|
|
|
|
}
|
|
|
|
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
glBindTexture(textarget, 0);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
|
|
|
|
{
|
|
|
|
GPUTexture *tex = prv->gputexture[0];
|
|
|
|
GLuint bindcode = 0;
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
bindcode = tex->bindcode;
|
|
|
|
|
|
|
|
/* this binds a texture, so that's why we restore it to 0 */
|
|
|
|
if (bindcode == 0) {
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
GPU_create_gl_tex(&bindcode, prv->rect[0], NULL, prv->w[0], prv->h[0], GL_TEXTURE_2D, mipmap, 0, NULL);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
if (tex) {
|
|
|
|
tex->bindcode = bindcode;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
|
|
|
tex->bindcode = bindcode;
|
|
|
|
tex->number = -1;
|
|
|
|
tex->refcount = 1;
|
|
|
|
tex->target = GL_TEXTURE_2D;
|
|
|
|
tex->target_base = GL_TEXTURE_2D;
|
|
|
|
|
|
|
|
prv->gputexture[0] = tex;
|
|
|
|
|
|
|
|
if (!glIsTexture(tex->bindcode)) {
|
2016-08-19 00:52:52 -04:00
|
|
|
GPU_print_error_debug("Blender Texture Not Loaded");
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-01-07 16:32:02 -05:00
|
|
|
GLint w, h;
|
|
|
|
|
2015-12-06 21:20:19 +01:00
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->bindcode);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
|
|
|
|
tex->w = w;
|
|
|
|
tex->h = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_1D(int w, const float *pixels, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
return GPU_texture_create_nD(w, 0, 0, 1, pixels, GPU_RGBA8, 4, 0, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_1D_custom(
|
|
|
|
int w, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
return GPU_texture_create_nD(w, 0, 0, 1, pixels, data_type, channels, 0, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, char err_out[256])
|
|
|
|
{
|
|
|
|
return GPU_texture_create_nD(w, h, 0, 2, pixels, GPU_RGBA8, 4, 0, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_2D_custom(
|
|
|
|
int w, int h, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
return GPU_texture_create_nD(w, h, 0, 2, pixels, data_type, channels, 0, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_2D_multisample(int w, int h, const float *pixels, int samples, char err_out[256])
|
|
|
|
{
|
|
|
|
return GPU_texture_create_nD(w, h, 0, 2, pixels, GPU_RGBA8, 4, samples, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_2D_array(int w, int h, int d, const float *pixels, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
return GPU_texture_create_nD(w, h, d, 2, pixels, GPU_RGBA8, 4, 0, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_3D(int w, int h, int d, const float *pixels, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
return GPU_texture_create_nD(w, h, d, 3, pixels, GPU_RGBA8, 4, 0, true, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_3D_custom(int w, int h, int d, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256])
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
2017-02-03 16:01:32 +01:00
|
|
|
return GPU_texture_create_nD(w, h, d, 3, pixels, data_type, channels, 0, true, err_out);
|
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256])
|
|
|
|
{
|
|
|
|
return GPU_texture_create_nD(w, h, 0, 2, NULL, GPU_DEPTH_COMPONENT24, 1, 0, false, err_out);
|
|
|
|
}
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
GPUTexture *GPU_texture_create_depth_multisample(int w, int h, int samples, char err_out[256])
|
|
|
|
{
|
|
|
|
return GPU_texture_create_nD(w, h, 0, 2, NULL, GPU_DEPTH_COMPONENT24, 1, samples, false, err_out);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_invalid_tex_init(void)
|
|
|
|
{
|
|
|
|
const float color[4] = {1.0f, 0.0f, 1.0f, 1.0f};
|
|
|
|
GG.invalid_tex_1D = GPU_texture_create_1D(1, color, NULL);
|
2017-02-03 16:01:32 +01:00
|
|
|
GG.invalid_tex_2D = GPU_texture_create_2D(1, 1, color, NULL);
|
|
|
|
GG.invalid_tex_3D = GPU_texture_create_3D(1, 1, 1, color, NULL);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_invalid_tex_bind(int mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case GL_TEXTURE_1D:
|
|
|
|
glBindTexture(GL_TEXTURE_1D, GG.invalid_tex_1D->bindcode);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_2D:
|
|
|
|
glBindTexture(GL_TEXTURE_2D, GG.invalid_tex_2D->bindcode);
|
|
|
|
break;
|
|
|
|
case GL_TEXTURE_3D:
|
|
|
|
glBindTexture(GL_TEXTURE_3D, GG.invalid_tex_3D->bindcode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_invalid_tex_free(void)
|
|
|
|
{
|
|
|
|
if (GG.invalid_tex_1D)
|
|
|
|
GPU_texture_free(GG.invalid_tex_1D);
|
|
|
|
if (GG.invalid_tex_2D)
|
|
|
|
GPU_texture_free(GG.invalid_tex_2D);
|
|
|
|
if (GG.invalid_tex_3D)
|
|
|
|
GPU_texture_free(GG.invalid_tex_3D);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GPU_texture_bind(GPUTexture *tex, int number)
|
|
|
|
{
|
|
|
|
if (number >= GPU_max_textures()) {
|
|
|
|
fprintf(stderr, "Not enough texture slots.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((G.debug & G_DEBUG)) {
|
|
|
|
if (tex->fb && GPU_framebuffer_bound(tex->fb)) {
|
|
|
|
fprintf(stderr, "Feedback loop warning!: Attempting to bind texture attached to current framebuffer!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (number < 0)
|
|
|
|
return;
|
|
|
|
|
2016-10-25 01:02:41 -04:00
|
|
|
if (number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0 + number);
|
|
|
|
|
|
|
|
if (tex->bindcode != 0)
|
2016-08-09 12:29:14 +03:00
|
|
|
glBindTexture(tex->target_base, tex->bindcode);
|
2015-12-06 21:20:19 +01:00
|
|
|
else
|
2016-08-09 12:29:14 +03:00
|
|
|
GPU_invalid_tex_bind(tex->target_base);
|
2016-10-25 01:02:41 -04:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* TODO: remove this lines once we're using GLSL everywhere */
|
|
|
|
GLenum target = tex->target_base;
|
|
|
|
if (tex->target_base == GL_TEXTURE_1D_ARRAY)
|
|
|
|
target = GL_TEXTURE_2D;
|
|
|
|
if (tex->target_base == GL_TEXTURE_2D_ARRAY)
|
|
|
|
target = GL_TEXTURE_3D;
|
|
|
|
glEnable(target);
|
2016-10-25 01:02:41 -04:00
|
|
|
|
|
|
|
if (number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
tex->number = number;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_unbind(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
if (tex->number >= GPU_max_textures()) {
|
|
|
|
fprintf(stderr, "Not enough texture slots.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
2016-10-25 01:02:41 -04:00
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
|
|
|
World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
- "View", "AngMap" and "Equirectangular" types of mapping.
- Different types of texture blending (according to BI world render).
- Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
2016-01-27 12:06:57 +03:00
|
|
|
glBindTexture(tex->target_base, 0);
|
2017-02-03 16:01:32 +01:00
|
|
|
|
|
|
|
/* TODO: remove this lines */
|
|
|
|
GLenum target = tex->target_base;
|
|
|
|
if (tex->target_base == GL_TEXTURE_1D_ARRAY)
|
|
|
|
target = GL_TEXTURE_2D;
|
|
|
|
if (tex->target_base == GL_TEXTURE_2D_ARRAY)
|
|
|
|
target = GL_TEXTURE_3D;
|
|
|
|
glDisable(target);
|
2016-10-25 01:02:41 -04:00
|
|
|
|
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
|
|
|
tex->number = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_bound_number(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->number;
|
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
|
2015-12-06 21:20:19 +01:00
|
|
|
{
|
|
|
|
if (tex->number >= GPU_max_textures()) {
|
|
|
|
fprintf(stderr, "Not enough texture slots.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
2016-10-25 01:02:41 -04:00
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0 + tex->number);
|
2015-12-06 21:20:19 +01:00
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
/* TODO viewport: use GL_COMPARE_REF_TO_TEXTURE after we switch to core profile */
|
|
|
|
if (tex->depth)
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, use_compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE);
|
|
|
|
|
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
|
|
|
|
{
|
|
|
|
if (tex->number >= GPU_max_textures()) {
|
|
|
|
fprintf(stderr, "Not enough texture slots.\n");
|
|
|
|
return;
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 16:01:32 +01:00
|
|
|
if (tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
|
|
|
2016-10-25 01:02:41 -04:00
|
|
|
GLenum filter = use_filter ? GL_LINEAR : GL_NEAREST;
|
2017-02-03 16:01:32 +01:00
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, filter);
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, filter);
|
|
|
|
|
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat)
|
|
|
|
{
|
|
|
|
if (tex->number >= GPU_max_textures()) {
|
|
|
|
fprintf(stderr, "Not enough texture slots.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex->number == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
|
|
|
|
|
|
GLenum repeat = use_repeat ? GL_REPEAT : GL_CLAMP_TO_EDGE;
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, repeat);
|
|
|
|
if (tex->target_base != GL_TEXTURE_1D)
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, repeat);
|
|
|
|
if (tex->target_base == GL_TEXTURE_3D)
|
|
|
|
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, repeat);
|
2016-10-25 01:02:41 -04:00
|
|
|
|
|
|
|
if (tex->number != 0)
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2015-12-06 21:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_free(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
tex->refcount--;
|
|
|
|
|
|
|
|
if (tex->refcount < 0)
|
|
|
|
fprintf(stderr, "GPUTexture: negative refcount\n");
|
|
|
|
|
|
|
|
if (tex->refcount == 0) {
|
|
|
|
if (tex->fb)
|
|
|
|
GPU_framebuffer_texture_detach(tex);
|
|
|
|
if (tex->bindcode && !tex->fromblender)
|
|
|
|
glDeleteTextures(1, &tex->bindcode);
|
|
|
|
|
|
|
|
MEM_freeN(tex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_ref(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
tex->refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_target(const GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_width(const GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->w;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_height(const GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->h;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_depth(const GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_opengl_bindcode(const GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->bindcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPU_texture_framebuffer_attachment(GPUTexture *tex)
|
|
|
|
{
|
|
|
|
return tex->fb_attachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPU_texture_framebuffer_set(GPUTexture *tex, GPUFrameBuffer *fb, int attachment)
|
|
|
|
{
|
|
|
|
tex->fb = fb;
|
|
|
|
tex->fb_attachment = attachment;
|
|
|
|
}
|
|
|
|
|