Compare commits
7 Commits
geometry-n
...
tmp-textur
Author | SHA1 | Date | |
---|---|---|---|
4145527975 | |||
4b12997fee | |||
decaf3c521 | |||
438923aabe | |||
0449d2f427 | |||
3246edc8b4 | |||
0e1938e6db |
@@ -503,10 +503,8 @@ static void studiolight_create_equirect_radiance_gputexture(StudioLight *sl)
|
|||||||
sl->equirect_radiance_gputexture = GPU_texture_create_2d(
|
sl->equirect_radiance_gputexture = GPU_texture_create_2d(
|
||||||
ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, NULL);
|
ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, NULL);
|
||||||
GPUTexture *tex = sl->equirect_radiance_gputexture;
|
GPUTexture *tex = sl->equirect_radiance_gputexture;
|
||||||
GPU_texture_bind(tex, 0);
|
|
||||||
GPU_texture_filter_mode(tex, true);
|
GPU_texture_filter_mode(tex, true);
|
||||||
GPU_texture_wrap_mode(tex, true, true);
|
GPU_texture_wrap_mode(tex, true, true);
|
||||||
GPU_texture_unbind(tex);
|
|
||||||
}
|
}
|
||||||
sl->flag |= STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE;
|
sl->flag |= STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE;
|
||||||
}
|
}
|
||||||
@@ -567,10 +565,8 @@ static void studiolight_create_equirect_irradiance_gputexture(StudioLight *sl)
|
|||||||
sl->equirect_irradiance_gputexture = GPU_texture_create_2d(
|
sl->equirect_irradiance_gputexture = GPU_texture_create_2d(
|
||||||
ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, NULL);
|
ibuf->x, ibuf->y, GPU_RGBA16F, ibuf->rect_float, NULL);
|
||||||
GPUTexture *tex = sl->equirect_irradiance_gputexture;
|
GPUTexture *tex = sl->equirect_irradiance_gputexture;
|
||||||
GPU_texture_bind(tex, 0);
|
|
||||||
GPU_texture_filter_mode(tex, true);
|
GPU_texture_filter_mode(tex, true);
|
||||||
GPU_texture_wrap_mode(tex, true, true);
|
GPU_texture_wrap_mode(tex, true, true);
|
||||||
GPU_texture_unbind(tex);
|
|
||||||
}
|
}
|
||||||
sl->flag |= STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE;
|
sl->flag |= STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE;
|
||||||
}
|
}
|
||||||
|
@@ -379,9 +379,7 @@ static bool eevee_lightcache_static_load(LightCache *lcache)
|
|||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
NULL);
|
NULL);
|
||||||
GPU_texture_bind(lcache->grid_tx.tex, 0);
|
|
||||||
GPU_texture_filter_mode(lcache->grid_tx.tex, true);
|
GPU_texture_filter_mode(lcache->grid_tx.tex, true);
|
||||||
GPU_texture_unbind(lcache->grid_tx.tex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lcache->cube_tx.tex == NULL) {
|
if (lcache->cube_tx.tex == NULL) {
|
||||||
@@ -406,13 +404,11 @@ static bool eevee_lightcache_static_load(LightCache *lcache)
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
GPU_texture_bind(lcache->cube_tx.tex, 0);
|
|
||||||
GPU_texture_mipmap_mode(lcache->cube_tx.tex, true, true);
|
|
||||||
for (int mip = 0; mip < lcache->mips_len; mip++) {
|
for (int mip = 0; mip < lcache->mips_len; mip++) {
|
||||||
GPU_texture_add_mipmap(
|
GPU_texture_add_mipmap(
|
||||||
lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, mip + 1, lcache->cube_mips[mip].data);
|
lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, mip + 1, lcache->cube_mips[mip].data);
|
||||||
}
|
}
|
||||||
GPU_texture_unbind(lcache->cube_tx.tex);
|
GPU_texture_mipmap_mode(lcache->cube_tx.tex, true, true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -266,13 +266,8 @@ void workbench_antialiasing_engine_init(WORKBENCH_Data *vedata)
|
|||||||
false,
|
false,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
GPU_texture_bind(txl->smaa_search_tx, 0);
|
|
||||||
GPU_texture_filter_mode(txl->smaa_search_tx, true);
|
GPU_texture_filter_mode(txl->smaa_search_tx, true);
|
||||||
GPU_texture_unbind(txl->smaa_search_tx);
|
|
||||||
|
|
||||||
GPU_texture_bind(txl->smaa_area_tx, 0);
|
|
||||||
GPU_texture_filter_mode(txl->smaa_area_tx, true);
|
GPU_texture_filter_mode(txl->smaa_area_tx, true);
|
||||||
GPU_texture_unbind(txl->smaa_area_tx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -61,7 +61,6 @@ static bool drw_texture_format_supports_framebuffer(eGPUTextureFormat format)
|
|||||||
|
|
||||||
void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
|
void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
|
||||||
{
|
{
|
||||||
GPU_texture_bind(tex, 0);
|
|
||||||
if (flags & DRW_TEX_MIPMAP) {
|
if (flags & DRW_TEX_MIPMAP) {
|
||||||
GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
|
GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
|
||||||
GPU_texture_generate_mipmap(tex);
|
GPU_texture_generate_mipmap(tex);
|
||||||
@@ -71,7 +70,6 @@ void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
|
|||||||
}
|
}
|
||||||
GPU_texture_wrap_mode(tex, flags & DRW_TEX_WRAP, true);
|
GPU_texture_wrap_mode(tex, flags & DRW_TEX_WRAP, true);
|
||||||
GPU_texture_compare_mode(tex, flags & DRW_TEX_COMPARE);
|
GPU_texture_compare_mode(tex, flags & DRW_TEX_COMPARE);
|
||||||
GPU_texture_unbind(tex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUTexture *DRW_texture_create_1d(int w,
|
GPUTexture *DRW_texture_create_1d(int w,
|
||||||
|
@@ -41,6 +41,31 @@ struct PreviewImage;
|
|||||||
struct GPUFrameBuffer;
|
struct GPUFrameBuffer;
|
||||||
typedef struct GPUTexture GPUTexture;
|
typedef struct GPUTexture GPUTexture;
|
||||||
|
|
||||||
|
/* 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 {
|
||||||
|
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),
|
||||||
|
/* Don't use that. */
|
||||||
|
GPU_SAMPLER_MAX = (1 << 8),
|
||||||
|
} eGPUSamplerState;
|
||||||
|
|
||||||
|
#define GPU_SAMPLER_DEFAULT GPU_SAMPLER_FILTER
|
||||||
|
#define GPU_SAMPLER_REPEAT (GPU_SAMPLER_REPEAT_S | GPU_SAMPLER_REPEAT_T | GPU_SAMPLER_REPEAT_R)
|
||||||
|
|
||||||
|
void GPU_samplers_init(void);
|
||||||
|
void GPU_samplers_free(void);
|
||||||
|
|
||||||
/* GPU Texture
|
/* GPU Texture
|
||||||
* - always returns unsigned char RGBA textures
|
* - always returns unsigned char RGBA textures
|
||||||
* - if texture with non square dimensions is created, depending on the
|
* - if texture with non square dimensions is created, depending on the
|
||||||
|
@@ -161,7 +161,7 @@ static GLenum gpu_get_mipmap_filter(bool mag)
|
|||||||
void GPU_set_anisotropic(Main *bmain, float value)
|
void GPU_set_anisotropic(Main *bmain, float value)
|
||||||
{
|
{
|
||||||
if (GTS.anisotropic != value) {
|
if (GTS.anisotropic != value) {
|
||||||
GPU_free_images(bmain);
|
GPU_samplers_free();
|
||||||
|
|
||||||
/* Clamp value to the maximum value the graphics card supports */
|
/* Clamp value to the maximum value the graphics card supports */
|
||||||
const float max = GPU_max_texture_anisotropy();
|
const float max = GPU_max_texture_anisotropy();
|
||||||
@@ -170,6 +170,8 @@ void GPU_set_anisotropic(Main *bmain, float value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GTS.anisotropic = value;
|
GTS.anisotropic = value;
|
||||||
|
|
||||||
|
GPU_samplers_init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,22 +451,12 @@ static uint gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
|
|||||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
||||||
|
|
||||||
if (GPU_get_mipmap()) {
|
if (GPU_get_mipmap()) {
|
||||||
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
||||||
if (ima) {
|
if (ima) {
|
||||||
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GLEW_EXT_texture_filter_anisotropic) {
|
|
||||||
glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
|
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
|
||||||
|
|
||||||
@@ -1098,18 +1090,12 @@ void GPU_create_gl_tex(uint *bind,
|
|||||||
GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
GL_TEXTURE_2D, 0, internal_format, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
||||||
|
|
||||||
if (GPU_get_mipmap() && mipmap) {
|
if (GPU_get_mipmap() && mipmap) {
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
||||||
if (ima) {
|
if (ima) {
|
||||||
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (textarget == GL_TEXTURE_CUBE_MAP) {
|
else if (textarget == GL_TEXTURE_CUBE_MAP) {
|
||||||
int w = rectw / 3, h = recth / 2;
|
int w = rectw / 3, h = recth / 2;
|
||||||
@@ -1132,22 +1118,13 @@ void GPU_create_gl_tex(uint *bind,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
|
||||||
|
|
||||||
if (GPU_get_mipmap() && mipmap) {
|
if (GPU_get_mipmap() && mipmap) {
|
||||||
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
|
||||||
|
|
||||||
if (ima) {
|
if (ima) {
|
||||||
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
ima->gpuflag |= IMA_GPU_MIPMAP_COMPLETE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
}
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
gpu_del_cube_map(cube_map);
|
gpu_del_cube_map(cube_map);
|
||||||
}
|
}
|
||||||
@@ -1156,10 +1133,6 @@ void GPU_create_gl_tex(uint *bind,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GLEW_EXT_texture_filter_anisotropic) {
|
|
||||||
glTexParameterf(textarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(textarget, 0);
|
glBindTexture(textarget, 0);
|
||||||
|
|
||||||
if (ibuf) {
|
if (ibuf) {
|
||||||
@@ -1211,10 +1184,6 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf, bool use_srgb)
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
|
||||||
|
|
||||||
if (GLEW_EXT_texture_filter_anisotropic) {
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
|
|
||||||
}
|
|
||||||
|
|
||||||
blocksize = (ibuf->dds_data.fourcc == FOURCC_DXT1) ? 8 : 16;
|
blocksize = (ibuf->dds_data.fourcc == FOURCC_DXT1) ? 8 : 16;
|
||||||
for (i = 0; i < ibuf->dds_data.nummipmaps && (width || height); i++) {
|
for (i = 0; i < ibuf->dds_data.nummipmaps && (width || height); i++) {
|
||||||
if (width == 0) {
|
if (width == 0) {
|
||||||
|
@@ -355,11 +355,13 @@ void gpu_extensions_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GPU_invalid_tex_init();
|
GPU_invalid_tex_init();
|
||||||
|
GPU_samplers_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpu_extensions_exit(void)
|
void gpu_extensions_exit(void)
|
||||||
{
|
{
|
||||||
GPU_invalid_tex_free();
|
GPU_invalid_tex_free();
|
||||||
|
GPU_samplers_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GPU_mem_stats_supported(void)
|
bool GPU_mem_stats_supported(void)
|
||||||
|
@@ -50,10 +50,14 @@ static struct GPUTextureGlobal {
|
|||||||
GPUTexture *invalid_tex_1D;
|
GPUTexture *invalid_tex_1D;
|
||||||
GPUTexture *invalid_tex_2D;
|
GPUTexture *invalid_tex_2D;
|
||||||
GPUTexture *invalid_tex_3D;
|
GPUTexture *invalid_tex_3D;
|
||||||
} GG = {NULL, NULL, NULL};
|
/** Sampler objects used to replace internal texture parameters. */
|
||||||
|
GLuint samplers[GPU_SAMPLER_MAX];
|
||||||
|
} GG = {NULL};
|
||||||
|
|
||||||
/* Maximum number of FBOs a texture can be attached to. */
|
/* Maximum number of FBOs a texture can be attached to. */
|
||||||
#define GPU_TEX_MAX_FBO_ATTACHED 12
|
#define GPU_TEX_MAX_FBO_ATTACHED 12
|
||||||
|
/* Maximum number of texture unit a texture can be attached to. */
|
||||||
|
#define GPU_TEX_MAX_BIND 4
|
||||||
|
|
||||||
typedef enum eGPUTextureFormatFlag {
|
typedef enum eGPUTextureFormatFlag {
|
||||||
GPU_FORMAT_DEPTH = (1 << 0),
|
GPU_FORMAT_DEPTH = (1 << 0),
|
||||||
@@ -70,17 +74,18 @@ typedef enum eGPUTextureFormatFlag {
|
|||||||
|
|
||||||
/* GPUTexture */
|
/* GPUTexture */
|
||||||
struct GPUTexture {
|
struct GPUTexture {
|
||||||
int w, h, d; /* width/height/depth */
|
int w, h, d; /* width/height/depth */
|
||||||
int orig_w, orig_h; /* width/height (of source data), optional. */
|
int orig_w, orig_h; /* width/height (of source data), optional. */
|
||||||
int number; /* number for multitexture binding */
|
int number[GPU_TEX_MAX_BIND]; /* Texture unit(s) to which this texture is bound. */
|
||||||
int refcount; /* reference count */
|
int refcount; /* reference count */
|
||||||
GLenum target; /* GL_TEXTURE_* */
|
GLenum target; /* GL_TEXTURE_* */
|
||||||
GLenum target_base; /* same as target, (but no multisample)
|
GLenum target_base; /* same as target, (but no multisample)
|
||||||
* use it for unbinding */
|
* use it for unbinding */
|
||||||
GLuint bindcode; /* opengl identifier for texture */
|
GLuint bindcode; /* opengl identifier for texture */
|
||||||
|
|
||||||
eGPUTextureFormat format;
|
eGPUTextureFormat format;
|
||||||
eGPUTextureFormatFlag format_flag;
|
eGPUTextureFormatFlag format_flag;
|
||||||
|
eGPUSamplerState sampler_state; /* Internal Sampler state. */
|
||||||
|
|
||||||
int mipmaps; /* number of mipmaps */
|
int mipmaps; /* number of mipmaps */
|
||||||
int components; /* number of color/alpha channels */
|
int components; /* number of color/alpha channels */
|
||||||
@@ -826,12 +831,14 @@ GPUTexture *GPU_texture_create_nD(int w,
|
|||||||
tex->h = h;
|
tex->h = h;
|
||||||
tex->d = d;
|
tex->d = d;
|
||||||
tex->samples = samples;
|
tex->samples = samples;
|
||||||
tex->number = -1;
|
|
||||||
tex->refcount = 1;
|
tex->refcount = 1;
|
||||||
tex->format = tex_format;
|
tex->format = tex_format;
|
||||||
tex->components = gpu_get_component_count(tex_format);
|
tex->components = gpu_get_component_count(tex_format);
|
||||||
tex->mipmaps = 0;
|
tex->mipmaps = 0;
|
||||||
tex->format_flag = 0;
|
tex->format_flag = 0;
|
||||||
|
for (int i = 0; i < GPU_TEX_MAX_BIND; i++) {
|
||||||
|
tex->number[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (n == 2) {
|
if (n == 2) {
|
||||||
if (d == 0) {
|
if (d == 0) {
|
||||||
@@ -975,26 +982,13 @@ GPUTexture *GPU_texture_create_nD(int w,
|
|||||||
if (GPU_texture_stencil(tex) || /* Does not support filtering */
|
if (GPU_texture_stencil(tex) || /* Does not support filtering */
|
||||||
GPU_texture_integer(tex) || /* Does not support filtering */
|
GPU_texture_integer(tex) || /* Does not support filtering */
|
||||||
GPU_texture_depth(tex)) {
|
GPU_texture_depth(tex)) {
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
tex->sampler_state = GPU_SAMPLER_DEFAULT & ~GPU_SAMPLER_FILTER;
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
tex->sampler_state = GPU_SAMPLER_DEFAULT;
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GPU_texture_depth(tex)) {
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
if (n > 1) {
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
}
|
|
||||||
if (n > 2) {
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
||||||
}
|
}
|
||||||
|
/* Avoid issue with incomplete textures. */
|
||||||
|
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
|
||||||
glBindTexture(tex->target, 0);
|
glBindTexture(tex->target, 0);
|
||||||
|
|
||||||
@@ -1013,12 +1007,14 @@ GPUTexture *GPU_texture_cube_create(int w,
|
|||||||
tex->h = w;
|
tex->h = w;
|
||||||
tex->d = d;
|
tex->d = d;
|
||||||
tex->samples = 0;
|
tex->samples = 0;
|
||||||
tex->number = -1;
|
|
||||||
tex->refcount = 1;
|
tex->refcount = 1;
|
||||||
tex->format = tex_format;
|
tex->format = tex_format;
|
||||||
tex->components = gpu_get_component_count(tex_format);
|
tex->components = gpu_get_component_count(tex_format);
|
||||||
tex->mipmaps = 0;
|
tex->mipmaps = 0;
|
||||||
tex->format_flag = GPU_FORMAT_CUBE;
|
tex->format_flag = GPU_FORMAT_CUBE;
|
||||||
|
for (int i = 0; i < GPU_TEX_MAX_BIND; i++) {
|
||||||
|
tex->number[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (d == 0) {
|
if (d == 0) {
|
||||||
tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP;
|
tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP;
|
||||||
@@ -1116,22 +1112,13 @@ GPUTexture *GPU_texture_cube_create(int w,
|
|||||||
if (GPU_texture_stencil(tex) || /* Does not support filtering */
|
if (GPU_texture_stencil(tex) || /* Does not support filtering */
|
||||||
GPU_texture_integer(tex) || /* Does not support filtering */
|
GPU_texture_integer(tex) || /* Does not support filtering */
|
||||||
GPU_texture_depth(tex)) {
|
GPU_texture_depth(tex)) {
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
tex->sampler_state = GPU_SAMPLER_DEFAULT & ~GPU_SAMPLER_FILTER;
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
tex->sampler_state = GPU_SAMPLER_DEFAULT;
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
}
|
}
|
||||||
|
/* Avoid issue with incomplete textures. */
|
||||||
if (GPU_texture_depth(tex)) {
|
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
glBindTexture(tex->target, 0);
|
glBindTexture(tex->target, 0);
|
||||||
|
|
||||||
@@ -1142,7 +1129,6 @@ GPUTexture *GPU_texture_cube_create(int w,
|
|||||||
GPUTexture *GPU_texture_create_buffer(eGPUTextureFormat tex_format, const GLuint buffer)
|
GPUTexture *GPU_texture_create_buffer(eGPUTextureFormat tex_format, const GLuint buffer)
|
||||||
{
|
{
|
||||||
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
||||||
tex->number = -1;
|
|
||||||
tex->refcount = 1;
|
tex->refcount = 1;
|
||||||
tex->format = tex_format;
|
tex->format = tex_format;
|
||||||
tex->components = gpu_get_component_count(tex_format);
|
tex->components = gpu_get_component_count(tex_format);
|
||||||
@@ -1150,6 +1136,10 @@ GPUTexture *GPU_texture_create_buffer(eGPUTextureFormat tex_format, const GLuint
|
|||||||
tex->target_base = tex->target = GL_TEXTURE_BUFFER;
|
tex->target_base = tex->target = GL_TEXTURE_BUFFER;
|
||||||
tex->mipmaps = 0;
|
tex->mipmaps = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < GPU_TEX_MAX_BIND; i++) {
|
||||||
|
tex->number[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
GLenum internalformat = gpu_format_to_gl_internalformat(tex_format);
|
GLenum internalformat = gpu_format_to_gl_internalformat(tex_format);
|
||||||
|
|
||||||
gpu_get_gl_dataformat(tex_format, &tex->format_flag);
|
gpu_get_gl_dataformat(tex_format, &tex->format_flag);
|
||||||
@@ -1195,11 +1185,17 @@ GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode)
|
|||||||
{
|
{
|
||||||
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
||||||
tex->bindcode = bindcode;
|
tex->bindcode = bindcode;
|
||||||
tex->number = -1;
|
|
||||||
tex->refcount = 1;
|
tex->refcount = 1;
|
||||||
tex->target = textarget;
|
tex->target = textarget;
|
||||||
tex->target_base = textarget;
|
tex->target_base = textarget;
|
||||||
tex->samples = 0;
|
tex->samples = 0;
|
||||||
|
tex->sampler_state = GPU_SAMPLER_REPEAT | GPU_SAMPLER_ANISO;
|
||||||
|
if (GPU_get_mipmap()) {
|
||||||
|
tex->sampler_state |= (GPU_SAMPLER_MIPMAP | GPU_SAMPLER_FILTER);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < GPU_TEX_MAX_BIND; i++) {
|
||||||
|
tex->number[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!glIsTexture(tex->bindcode)) {
|
if (!glIsTexture(tex->bindcode)) {
|
||||||
GPU_print_error_debug("Blender Texture Not Loaded");
|
GPU_print_error_debug("Blender Texture Not Loaded");
|
||||||
@@ -1634,11 +1630,11 @@ void GPU_invalid_tex_free(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_texture_bind(GPUTexture *tex, int number)
|
void GPU_texture_bind(GPUTexture *tex, int unit)
|
||||||
{
|
{
|
||||||
BLI_assert(number >= 0);
|
BLI_assert(unit >= 0);
|
||||||
|
|
||||||
if (number >= GPU_max_textures()) {
|
if (unit >= GPU_max_textures()) {
|
||||||
fprintf(stderr, "Not enough texture slots.\n");
|
fprintf(stderr, "Not enough texture slots.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1655,38 +1651,49 @@ void GPU_texture_bind(GPUTexture *tex, int number)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + number);
|
glActiveTexture(GL_TEXTURE0 + unit);
|
||||||
|
|
||||||
if (tex->bindcode != 0) {
|
if (tex->bindcode != 0) {
|
||||||
glBindTexture(tex->target, tex->bindcode);
|
glBindTexture(tex->target, tex->bindcode);
|
||||||
|
glBindSampler(unit, GG.samplers[tex->sampler_state]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GPU_invalid_tex_bind(tex->target_base);
|
GPU_invalid_tex_bind(tex->target_base);
|
||||||
|
glBindSampler(unit, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
tex->number = number;
|
for (int i = 0; i < GPU_TEX_MAX_BIND; i++) {
|
||||||
|
if (tex->number[i] == -1) {
|
||||||
|
tex->number[i] = unit;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_texture_unbind(GPUTexture *tex)
|
void GPU_texture_unbind(GPUTexture *tex)
|
||||||
{
|
{
|
||||||
if (tex->number == -1) {
|
if (tex->number[0] == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
for (int i = 0; i < GPU_TEX_MAX_BIND; i++) {
|
||||||
glBindTexture(tex->target, 0);
|
if (tex->number[i] != -1) {
|
||||||
|
glActiveTexture(GL_TEXTURE0 + tex->number[i]);
|
||||||
tex->number = -1;
|
glBindTexture(tex->target, 0);
|
||||||
|
glBindSampler(tex->number[i], 0);
|
||||||
|
tex->number[i] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int GPU_texture_bound_number(GPUTexture *tex)
|
int GPU_texture_bound_number(GPUTexture *tex)
|
||||||
{
|
{
|
||||||
return tex->number;
|
/* TODO remove. Makes no sense now. */
|
||||||
|
return tex->number[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WARN_NOT_BOUND(_tex) \
|
#define WARN_NOT_BOUND(_tex) \
|
||||||
{ \
|
{ \
|
||||||
if (_tex->number == -1) { \
|
if (_tex->number[0] == -1) { \
|
||||||
fprintf(stderr, "Warning : Trying to set parameter on a texture not bound.\n"); \
|
fprintf(stderr, "Warning : Trying to set parameter on a texture not bound.\n"); \
|
||||||
BLI_assert(0); \
|
BLI_assert(0); \
|
||||||
return; \
|
return; \
|
||||||
@@ -1701,7 +1708,7 @@ void GPU_texture_generate_mipmap(GPUTexture *tex)
|
|||||||
gpu_texture_memory_footprint_remove(tex);
|
gpu_texture_memory_footprint_remove(tex);
|
||||||
int levels = 1 + floor(log2(max_ii(tex->w, tex->h)));
|
int levels = 1 + floor(log2(max_ii(tex->w, tex->h)));
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
glActiveTexture(GL_TEXTURE0 + tex->number[0]);
|
||||||
|
|
||||||
if (GPU_texture_depth(tex)) {
|
if (GPU_texture_depth(tex)) {
|
||||||
/* Some drivers have bugs when using glGenerateMipmap with depth textures (see T56789).
|
/* Some drivers have bugs when using glGenerateMipmap with depth textures (see T56789).
|
||||||
@@ -1812,110 +1819,48 @@ void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
|
|||||||
|
|
||||||
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
|
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
|
||||||
{
|
{
|
||||||
WARN_NOT_BOUND(tex);
|
|
||||||
|
|
||||||
/* Could become an assertion ? (fclem) */
|
/* Could become an assertion ? (fclem) */
|
||||||
if (!GPU_texture_depth(tex)) {
|
if (!GPU_texture_depth(tex)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
SET_FLAG_FROM_TEST(tex->sampler_state, use_compare, GPU_SAMPLER_COMPARE);
|
||||||
GLenum mode = (use_compare) ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE;
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
|
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
|
||||||
{
|
{
|
||||||
WARN_NOT_BOUND(tex);
|
|
||||||
|
|
||||||
/* Stencil and integer format does not support filtering. */
|
/* Stencil and integer format does not support filtering. */
|
||||||
BLI_assert(!use_filter || !(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
|
BLI_assert(!use_filter || !(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
|
||||||
|
|
||||||
GLenum filter = (use_filter) ? GL_LINEAR : GL_NEAREST;
|
SET_FLAG_FROM_TEST(tex->sampler_state, use_filter, GPU_SAMPLER_FILTER);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, filter);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter)
|
void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter)
|
||||||
{
|
{
|
||||||
WARN_NOT_BOUND(tex);
|
|
||||||
|
|
||||||
/* Stencil and integer format does not support filtering. */
|
/* Stencil and integer format does not support filtering. */
|
||||||
BLI_assert((!use_filter && !use_mipmap) ||
|
BLI_assert(!(use_filter || use_mipmap) ||
|
||||||
!(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
|
!(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
|
||||||
|
|
||||||
GLenum filter = (use_filter) ? GL_LINEAR : GL_NEAREST;
|
SET_FLAG_FROM_TEST(tex->sampler_state, use_mipmap, GPU_SAMPLER_MIPMAP);
|
||||||
GLenum mipmap = ((use_filter) ? (use_mipmap) ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR :
|
SET_FLAG_FROM_TEST(tex->sampler_state, use_filter, GPU_SAMPLER_FILTER);
|
||||||
(use_mipmap) ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, mipmap);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp)
|
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp)
|
||||||
{
|
{
|
||||||
WARN_NOT_BOUND(tex);
|
SET_FLAG_FROM_TEST(tex->sampler_state, use_repeat, GPU_SAMPLER_REPEAT);
|
||||||
|
SET_FLAG_FROM_TEST(tex->sampler_state, !use_clamp, GPU_SAMPLER_CLAMP_BORDER);
|
||||||
GLenum repeat = (use_repeat) ? GL_REPEAT : (use_clamp) ? GL_CLAMP_TO_EDGE : GL_CLAMP_TO_BORDER;
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repeat == GL_CLAMP_TO_BORDER) {
|
|
||||||
const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
||||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, black);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_texture_swizzle_channel_auto(GPUTexture *tex, int channels)
|
void GPU_texture_swizzle_channel_auto(GPUTexture *tex, int channels)
|
||||||
{
|
{
|
||||||
WARN_NOT_BOUND(tex);
|
WARN_NOT_BOUND(tex);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
glActiveTexture(GL_TEXTURE0 + tex->number[0]);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, (channels >= 2) ? GL_GREEN : GL_RED);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, (channels >= 2) ? GL_GREEN : GL_RED);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, (channels >= 3) ? GL_BLUE : GL_RED);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, (channels >= 3) ? GL_BLUE : GL_RED);
|
||||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, (channels >= 4) ? GL_ALPHA : GL_ONE);
|
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, (channels >= 4) ? GL_ALPHA : GL_ONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLenum gpu_get_gl_filterfunction(eGPUFilterFunction filter)
|
|
||||||
{
|
|
||||||
switch (filter) {
|
|
||||||
case GPU_NEAREST:
|
|
||||||
return GL_NEAREST;
|
|
||||||
case GPU_LINEAR:
|
|
||||||
return GL_LINEAR;
|
|
||||||
default:
|
|
||||||
BLI_assert(!"Unhandled filter mode");
|
|
||||||
return GL_NEAREST;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_texture_filters(GPUTexture *tex,
|
|
||||||
eGPUFilterFunction min_filter,
|
|
||||||
eGPUFilterFunction mag_filter)
|
|
||||||
{
|
|
||||||
WARN_NOT_BOUND(tex);
|
|
||||||
|
|
||||||
/* Stencil and integer format does not support filtering. */
|
|
||||||
BLI_assert(!(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
|
|
||||||
BLI_assert(mag_filter == GPU_NEAREST || mag_filter == GPU_LINEAR);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, gpu_get_gl_filterfunction(min_filter));
|
|
||||||
glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, gpu_get_gl_filterfunction(mag_filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_texture_free(GPUTexture *tex)
|
void GPU_texture_free(GPUTexture *tex)
|
||||||
{
|
{
|
||||||
tex->refcount--;
|
tex->refcount--;
|
||||||
@@ -2076,3 +2021,55 @@ void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size)
|
|||||||
size[2] = max_ii(1, tex->d / div);
|
size[2] = max_ii(1, tex->d / div);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
/** \name GPU Sampler Objects
|
||||||
|
*
|
||||||
|
* Simple wrapper around opengl sampler objects.
|
||||||
|
* Override texture sampler state for one sampler unit only.
|
||||||
|
* \{ */
|
||||||
|
|
||||||
|
void GPU_samplers_init(void)
|
||||||
|
{
|
||||||
|
glGenSamplers(GPU_SAMPLER_MAX, GG.samplers);
|
||||||
|
for (int i = 0; i < GPU_SAMPLER_MAX; i++) {
|
||||||
|
eGPUSamplerState state = i;
|
||||||
|
GLenum clamp_type = (state & GPU_SAMPLER_CLAMP_BORDER) ? GL_CLAMP_TO_BORDER : GL_CLAMP_TO_EDGE;
|
||||||
|
GLenum wrap_s = (state & GPU_SAMPLER_REPEAT_R) ? GL_REPEAT : clamp_type;
|
||||||
|
GLenum wrap_t = (state & GPU_SAMPLER_REPEAT_S) ? GL_REPEAT : clamp_type;
|
||||||
|
GLenum wrap_r = (state & GPU_SAMPLER_REPEAT_T) ? GL_REPEAT : clamp_type;
|
||||||
|
GLenum mag_filter = (state & GPU_SAMPLER_FILTER) ? GL_LINEAR : GL_NEAREST;
|
||||||
|
GLenum min_filter = (state & GPU_SAMPLER_FILTER) ?
|
||||||
|
((state & GPU_SAMPLER_MIPMAP) ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR) :
|
||||||
|
((state & GPU_SAMPLER_MIPMAP) ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST);
|
||||||
|
GLenum compare_mode = (state & GPU_SAMPLER_COMPARE) ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE;
|
||||||
|
float aniso_filter = ((state & GPU_SAMPLER_MIPMAP) && (state & GPU_SAMPLER_ANISO)) ?
|
||||||
|
GPU_get_anisotropic() :
|
||||||
|
1.0f;
|
||||||
|
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_WRAP_S, wrap_s);
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_WRAP_T, wrap_t);
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_WRAP_R, wrap_r);
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_MIN_FILTER, min_filter);
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_MAG_FILTER, mag_filter);
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_COMPARE_MODE, compare_mode);
|
||||||
|
glSamplerParameteri(GG.samplers[i], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||||
|
if (GLEW_EXT_texture_filter_anisotropic) {
|
||||||
|
glSamplerParameterf(GG.samplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso_filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Other states are left to default:
|
||||||
|
* - GL_TEXTURE_BORDER_COLOR is {0, 0, 0, 0}.
|
||||||
|
* - GL_TEXTURE_MIN_LOD is -1000.
|
||||||
|
* - GL_TEXTURE_MAX_LOD is 1000.
|
||||||
|
* - GL_TEXTURE_LOD_BIAS is 0.0f.
|
||||||
|
**/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPU_samplers_free(void)
|
||||||
|
{
|
||||||
|
glDeleteSamplers(GPU_SAMPLER_MAX, GG.samplers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \} */
|
||||||
|
Reference in New Issue
Block a user