Modifications to GPU_texture:
-Remove NPOT check as it should be supported by default with OGL 3.3 -All custom texture creation follow the same path now -Now explicit texture format is required when creating a custom texture (Non RGBA8) -Support for arrays of textures Reviewers: dfelinto, merwin Differential Revision: https://developer.blender.org/D2452
This commit is contained in:
parent
b1b5ded37f
commit
520ced4ad5
|
@ -160,7 +160,7 @@ static GPUTexture *create_field_texture(SmokeDomainSettings *sds)
|
|||
default: return NULL;
|
||||
}
|
||||
|
||||
return GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, field);
|
||||
return GPU_texture_create_3D_custom(sds->res[0], sds->res[1], sds->res[2], 1, GPU_R8, field, NULL);
|
||||
}
|
||||
|
||||
typedef struct VolumeSlicer {
|
||||
|
|
|
@ -55,25 +55,112 @@ typedef struct GPUTexture GPUTexture;
|
|||
* - if created with from_blender, will not free the texture
|
||||
*/
|
||||
|
||||
typedef enum GPUHDRType {
|
||||
GPU_HDR_NONE = 0,
|
||||
GPU_HDR_HALF_FLOAT = 1,
|
||||
GPU_HDR_FULL_FLOAT = (1 << 1),
|
||||
} GPUHDRType;
|
||||
/* Wrapper to supported OpenGL/Vulkan texture internal storage
|
||||
* If you need a type just uncomment it. Be aware that some formats
|
||||
* are not supported by renderbuffers. All of the following formats
|
||||
* are part of the OpenGL 3.3 core
|
||||
* specification. */
|
||||
typedef enum GPUTextureFormat {
|
||||
/* Formats texture & renderbuffer */
|
||||
GPU_RGBA16F,
|
||||
GPU_RGBA8,
|
||||
GPU_RG32F,
|
||||
GPU_RG16F,
|
||||
GPU_R8,
|
||||
#if 0
|
||||
GPU_RGBA32F,
|
||||
GPU_RGBA32I,
|
||||
GPU_RGBA32UI,
|
||||
GPU_RGBA16,
|
||||
GPU_RGBA16I,
|
||||
GPU_RGBA16UI,
|
||||
GPU_RGBA8I,
|
||||
GPU_RGBA8UI,
|
||||
GPU_RG32I,
|
||||
GPU_RG32UI,
|
||||
GPU_RG16,
|
||||
GPU_RG16I,
|
||||
GPU_RG16UI,
|
||||
GPU_RG8,
|
||||
GPU_RG8I,
|
||||
GPU_RG8UI,
|
||||
GPU_R32F,
|
||||
GPU_R32I,
|
||||
GPU_R32UI,
|
||||
GPU_R16F,
|
||||
GPU_R16I,
|
||||
GPU_R16UI,
|
||||
GPU_R16,
|
||||
GPU_R8I,
|
||||
GPU_R8UI,
|
||||
#endif
|
||||
|
||||
/* Special formats texture & renderbuffer */
|
||||
#if 0
|
||||
GPU_R11F_G11F_B10F,
|
||||
GPU_RGB10_A2,
|
||||
GPU_RGB10_A2UI,
|
||||
GPU_DEPTH32F_STENCIL8,
|
||||
GPU_DEPTH24_STENCIL8,
|
||||
#endif
|
||||
|
||||
/* Texture only format */
|
||||
#if 0
|
||||
GPU_RGBA16_SNORM,
|
||||
GPU_RGBA8_SNORM,
|
||||
GPU_RGB32F,
|
||||
GPU_RGB32I,
|
||||
GPU_RGB32UI,
|
||||
GPU_RGB16_SNORM,
|
||||
GPU_RGB16F,
|
||||
GPU_RGB16I,
|
||||
GPU_RGB16UI,
|
||||
GPU_RGB16,
|
||||
GPU_RGB8_SNORM,
|
||||
GPU_RGB8,
|
||||
GPU_RGB8I,
|
||||
GPU_RGB8UI,
|
||||
GPU_RG16_SNORM,
|
||||
GPU_RG8_SNORM,
|
||||
GPU_R16_SNORM,
|
||||
GPU_R8_SNORM,
|
||||
#endif
|
||||
|
||||
/* Special formats texture only */
|
||||
#if 0
|
||||
GPU_SRGB8_A8,
|
||||
GPU_SRGB8,
|
||||
GPU_RGB9_E5,
|
||||
GPU_COMPRESSED_RG_RGTC2,
|
||||
GPU_COMPRESSED_SIGNED_RG_RGTC2,
|
||||
GPU_COMPRESSED_RED_RGTC1,
|
||||
GPU_COMPRESSED_SIGNED_RED_RGTC1,
|
||||
#endif
|
||||
|
||||
/* Depth Formats */
|
||||
GPU_DEPTH_COMPONENT32F,
|
||||
GPU_DEPTH_COMPONENT24,
|
||||
GPU_DEPTH_COMPONENT16,
|
||||
} GPUTextureFormat;
|
||||
|
||||
GPUTexture *GPU_texture_create_1D(int w, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, GPUHDRType hdr, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels);
|
||||
GPUTexture *GPU_texture_create_1D_custom(
|
||||
int w, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D_custom(
|
||||
int w, int h, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D_multisample(int w, int h, const float *pixels, int samples, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D_array(int w, int h, int d, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_3D(int w, int h, int d, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_3D_custom(
|
||||
int w, int h, int d, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, bool repeat, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_1D_procedural(int w, const float *pixels, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_2D_multisample(
|
||||
int w, int h, const float *pixels, GPUHDRType hdr, int samples, char err_out[256]);
|
||||
GPUTexture *GPU_texture_create_depth_multisample(int w, int h, int samples, char err_out[256]);
|
||||
|
||||
GPUTexture *GPU_texture_from_blender(
|
||||
struct Image *ima, struct ImageUser *iuser, int textarget, bool is_data, double time, int mipmap);
|
||||
GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap);
|
||||
|
||||
void GPU_invalid_tex_init(void);
|
||||
void GPU_invalid_tex_bind(int mode);
|
||||
void GPU_invalid_tex_free(void);
|
||||
|
@ -81,12 +168,13 @@ void GPU_invalid_tex_free(void);
|
|||
void GPU_texture_free(GPUTexture *tex);
|
||||
|
||||
void GPU_texture_ref(GPUTexture *tex);
|
||||
|
||||
void GPU_texture_bind(GPUTexture *tex, int number);
|
||||
void GPU_texture_unbind(GPUTexture *tex);
|
||||
int GPU_texture_bound_number(GPUTexture *tex);
|
||||
|
||||
void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter);
|
||||
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare);
|
||||
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter);
|
||||
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat);
|
||||
|
||||
struct GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
|
||||
int GPU_texture_framebuffer_attachment(GPUTexture *tex);
|
||||
|
|
|
@ -1192,7 +1192,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
|
|||
#if 0
|
||||
input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL);
|
||||
#endif
|
||||
input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, GPU_HDR_NONE, NULL);
|
||||
input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, NULL);
|
||||
input->textarget = GL_TEXTURE_2D;
|
||||
|
||||
MEM_freeN(link->ptr1);
|
||||
|
|
|
@ -225,7 +225,13 @@ static GPUTexture * create_concentric_sample_texture(int side)
|
|||
}
|
||||
}
|
||||
|
||||
tex = GPU_texture_create_1D_procedural(side * side, texels, NULL);
|
||||
tex = GPU_texture_create_1D_custom(side * side, 2, GPU_RG16F, (float *)texels, NULL);
|
||||
|
||||
/* Set parameters */
|
||||
GPU_texture_bind(tex, 0);
|
||||
GPU_texture_filter_mode(tex, false);
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
MEM_freeN(texels);
|
||||
return tex;
|
||||
}
|
||||
|
@ -247,7 +253,13 @@ static GPUTexture *create_spiral_sample_texture(int numsaples)
|
|||
texels[i][1] = r * sinf(phi);
|
||||
}
|
||||
|
||||
tex = GPU_texture_create_1D_procedural(numsaples, (float *)texels, NULL);
|
||||
tex = GPU_texture_create_1D_custom(numsaples, 2, GPU_RG16F, (float *)texels, NULL);
|
||||
|
||||
/* Set parameters */
|
||||
GPU_texture_bind(tex, 0);
|
||||
GPU_texture_filter_mode(tex, false);
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
MEM_freeN(texels);
|
||||
return tex;
|
||||
}
|
||||
|
@ -358,6 +370,7 @@ void GPU_fx_compositor_destroy(GPUFX *fx)
|
|||
|
||||
static GPUTexture * create_jitter_texture(void)
|
||||
{
|
||||
GPUTexture *tex;
|
||||
float jitter[64 * 64][2];
|
||||
int i;
|
||||
|
||||
|
@ -367,7 +380,15 @@ static GPUTexture * create_jitter_texture(void)
|
|||
normalize_v2(jitter[i]);
|
||||
}
|
||||
|
||||
return GPU_texture_create_2D_procedural(64, 64, &jitter[0][0], true, NULL);
|
||||
tex = GPU_texture_create_2D_custom(64, 64, 2, GPU_RG16F, &jitter[0][0], NULL);
|
||||
|
||||
/* Set parameters */
|
||||
GPU_texture_bind(tex, 0);
|
||||
GPU_texture_filter_mode(tex, false);
|
||||
GPU_texture_wrap_mode(tex, true);
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
|
@ -433,7 +454,7 @@ bool GPU_fx_compositor_initialize_passes(
|
|||
if (!fx->color_buffer || !fx->depth_buffer || w != fx->gbuffer_dim[0] || h != fx->gbuffer_dim[1]) {
|
||||
cleanup_fx_gl_data(fx, false);
|
||||
|
||||
if (!(fx->color_buffer = GPU_texture_create_2D(w, h, NULL, GPU_HDR_NONE, err_out))) {
|
||||
if (!(fx->color_buffer = GPU_texture_create_2D(w, h, NULL, err_out))) {
|
||||
printf(".256%s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
|
@ -485,38 +506,42 @@ bool GPU_fx_compositor_initialize_passes(
|
|||
{
|
||||
|
||||
if (!(fx->dof_half_downsampled_near = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
if (!(fx->dof_half_downsampled_far = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
if (!(fx->dof_nearfar_coc = GPU_texture_create_2D_procedural(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, false, err_out)))
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(fx->dof_nearfar_coc = GPU_texture_create_2D_custom(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, 2, GPU_RG16F, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
GPU_texture_bind(fx->dof_nearfar_coc, 0);
|
||||
GPU_texture_filter_mode(fx->dof_nearfar_coc, false);
|
||||
GPU_texture_wrap_mode(fx->dof_nearfar_coc, false);
|
||||
GPU_texture_unbind(fx->dof_nearfar_coc);
|
||||
|
||||
if (!(fx->dof_near_blur = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_HALF_FLOAT, err_out)))
|
||||
if (!(fx->dof_near_blur = GPU_texture_create_2D_custom(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, 2, GPU_RGBA16F, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(fx->dof_far_blur = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_HALF_FLOAT, err_out)))
|
||||
if (!(fx->dof_far_blur = GPU_texture_create_2D_custom(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, 2, GPU_RGBA16F, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
|
@ -531,21 +556,21 @@ bool GPU_fx_compositor_initialize_passes(
|
|||
if (!fx->dof_near_coc_buffer || !fx->dof_near_coc_blurred_buffer || !fx->dof_near_coc_final_buffer) {
|
||||
|
||||
if (!(fx->dof_near_coc_buffer = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
if (!(fx->dof_near_coc_blurred_buffer = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
}
|
||||
if (!(fx->dof_near_coc_final_buffer = GPU_texture_create_2D(
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
|
||||
fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, err_out)))
|
||||
{
|
||||
printf("%.256s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
|
@ -564,7 +589,7 @@ bool GPU_fx_compositor_initialize_passes(
|
|||
/* we need to pass data between shader stages, allocate an extra color buffer */
|
||||
if (num_passes > 1) {
|
||||
if (!fx->color_buffer_sec) {
|
||||
if (!(fx->color_buffer_sec = GPU_texture_create_2D(w, h, NULL, GPU_HDR_NONE, err_out))) {
|
||||
if (!(fx->color_buffer_sec = GPU_texture_create_2D(w, h, NULL, err_out))) {
|
||||
printf(".256%s\n", err_out);
|
||||
cleanup_fx_gl_data(fx, true);
|
||||
return false;
|
||||
|
@ -692,14 +717,16 @@ void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
|
|||
GPU_shader_bind(depth_resolve_shader);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer_xray, 0);
|
||||
GPU_texture_filter_mode(fx->depth_buffer_xray, false, true);
|
||||
GPU_texture_compare_mode(fx->depth_buffer_xray, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer_xray, true);
|
||||
GPU_shader_uniform_texture(depth_resolve_shader, interface->depth_uniform, fx->depth_buffer_xray);
|
||||
|
||||
/* draw */
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
/* disable bindings */
|
||||
GPU_texture_filter_mode(fx->depth_buffer_xray, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer_xray, true);
|
||||
GPU_texture_filter_mode(fx->depth_buffer_xray, false);
|
||||
GPU_texture_unbind(fx->depth_buffer_xray);
|
||||
|
||||
GPU_shader_unbind();
|
||||
|
@ -814,7 +841,8 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_shader_uniform_texture(ssao_shader, interface->color_uniform, src);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer, numslots++);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false, true);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true);
|
||||
GPU_shader_uniform_texture(ssao_shader, interface->depth_uniform, fx->depth_buffer);
|
||||
|
||||
GPU_texture_bind(fx->jitter_buffer, numslots++);
|
||||
|
@ -830,7 +858,8 @@ bool GPU_fx_do_composite_pass(
|
|||
|
||||
/* disable bindings */
|
||||
GPU_texture_unbind(src);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, true);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_texture_unbind(fx->depth_buffer);
|
||||
GPU_texture_unbind(fx->jitter_buffer);
|
||||
GPU_texture_unbind(fx->ssao_spiral_samples_tex);
|
||||
|
@ -906,12 +935,13 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer, numslots++);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer);
|
||||
|
||||
GPU_texture_bind(src, numslots++);
|
||||
/* disable filtering for the texture so custom downsample can do the right thing */
|
||||
GPU_texture_filter_mode(src, false, false);
|
||||
GPU_texture_filter_mode(src, false);
|
||||
GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, src);
|
||||
|
||||
/* target is the downsampled coc buffer */
|
||||
|
@ -925,9 +955,10 @@ bool GPU_fx_do_composite_pass(
|
|||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
/* disable bindings */
|
||||
GPU_texture_filter_mode(src, false, true);
|
||||
GPU_texture_filter_mode(src, true);
|
||||
GPU_texture_unbind(src);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, true);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_texture_unbind(fx->depth_buffer);
|
||||
|
||||
GPU_framebuffer_texture_detach(fx->dof_half_downsampled_near);
|
||||
|
@ -958,7 +989,7 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_texture_bind(fx->dof_half_downsampled_far, numslots++);
|
||||
GPU_texture_bind(fx->dof_half_downsampled_near, numslots++);
|
||||
GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_far);
|
||||
GPU_texture_filter_mode(fx->dof_half_downsampled_far, false, false);
|
||||
GPU_texture_filter_mode(fx->dof_half_downsampled_far, false);
|
||||
|
||||
/* target is the downsampled coc buffer */
|
||||
GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_far_blur, 0);
|
||||
|
@ -978,7 +1009,7 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_framebuffer_texture_detach(fx->dof_far_blur);
|
||||
|
||||
GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_near);
|
||||
GPU_texture_filter_mode(fx->dof_half_downsampled_near, false, false);
|
||||
GPU_texture_filter_mode(fx->dof_half_downsampled_near, false);
|
||||
|
||||
selection[0] = 1.0f;
|
||||
selection[1] = 0.0f;
|
||||
|
@ -1018,14 +1049,15 @@ bool GPU_fx_do_composite_pass(
|
|||
|
||||
GPU_texture_bind(fx->dof_near_blur, numslots++);
|
||||
GPU_shader_uniform_texture(dof_shader_pass3, interface->near_uniform, fx->dof_near_blur);
|
||||
GPU_texture_filter_mode(fx->dof_near_blur, false, true);
|
||||
GPU_texture_filter_mode(fx->dof_near_blur, true);
|
||||
|
||||
GPU_texture_bind(fx->dof_far_blur, numslots++);
|
||||
GPU_shader_uniform_texture(dof_shader_pass3, interface->far_uniform, fx->dof_far_blur);
|
||||
GPU_texture_filter_mode(fx->dof_far_blur, false, true);
|
||||
GPU_texture_filter_mode(fx->dof_far_blur, true);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer, numslots++);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_shader_uniform_texture(dof_shader_pass3, interface->depth_uniform, fx->depth_buffer);
|
||||
|
||||
GPU_texture_bind(src, numslots++);
|
||||
|
@ -1040,7 +1072,7 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_texture_unbind(fx->dof_near_blur);
|
||||
GPU_texture_unbind(fx->dof_far_blur);
|
||||
GPU_texture_unbind(src);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, true);
|
||||
GPU_texture_unbind(fx->depth_buffer);
|
||||
|
||||
/* may not be attached, in that case this just returns */
|
||||
|
@ -1100,7 +1132,8 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_shader_uniform_texture(dof_shader_pass1, interface->color_uniform, src);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer, numslots++);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false, true);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true);
|
||||
GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer);
|
||||
|
||||
/* target is the downsampled coc buffer */
|
||||
|
@ -1111,7 +1144,8 @@ bool GPU_fx_do_composite_pass(
|
|||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
/* disable bindings */
|
||||
GPU_texture_unbind(src);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, true);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_texture_unbind(fx->depth_buffer);
|
||||
|
||||
GPU_framebuffer_texture_detach(fx->dof_near_coc_buffer);
|
||||
|
@ -1137,7 +1171,8 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_shader_uniform_vector(dof_shader_pass2, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer, numslots++);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false, true);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true);
|
||||
GPU_shader_uniform_texture(dof_shader_pass2, interface->depth_uniform, fx->depth_buffer);
|
||||
|
||||
GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
|
||||
|
@ -1165,7 +1200,8 @@ bool GPU_fx_do_composite_pass(
|
|||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
/* *unbind/detach */
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, true);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_texture_unbind(fx->depth_buffer);
|
||||
|
||||
GPU_texture_unbind(fx->dof_near_coc_final_buffer);
|
||||
|
@ -1249,7 +1285,8 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_shader_uniform_texture(dof_shader_pass5, interface->medium_blurred_uniform, fx->dof_near_coc_buffer);
|
||||
|
||||
GPU_texture_bind(fx->depth_buffer, numslots++);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false, true);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, false);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true);
|
||||
GPU_shader_uniform_texture(dof_shader_pass5, interface->depth_uniform, fx->depth_buffer);
|
||||
|
||||
/* if this is the last pass, prepare for rendering on the frambuffer */
|
||||
|
@ -1260,7 +1297,8 @@ bool GPU_fx_do_composite_pass(
|
|||
GPU_texture_unbind(fx->dof_near_coc_buffer);
|
||||
GPU_texture_unbind(fx->dof_near_coc_blurred_buffer);
|
||||
GPU_texture_unbind(src);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, true, false);
|
||||
GPU_texture_compare_mode(fx->depth_buffer, true);
|
||||
GPU_texture_filter_mode(fx->depth_buffer, false);
|
||||
GPU_texture_unbind(fx->depth_buffer);
|
||||
|
||||
/* may not be attached, in that case this just returns */
|
||||
|
|
|
@ -1404,31 +1404,40 @@ void GPU_create_smoke(SmokeModifierData *smd, int highres)
|
|||
if (smoke_has_colors(sds->fluid)) {
|
||||
float *data = MEM_callocN(sizeof(float) * sds->total_cells * 4, "smokeColorTexture");
|
||||
smoke_get_rgba(sds->fluid, data, 0);
|
||||
sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 4, data);
|
||||
sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], data, NULL);
|
||||
MEM_freeN(data);
|
||||
}
|
||||
/* density only */
|
||||
else {
|
||||
sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, smoke_get_density(sds->fluid));
|
||||
sds->tex = GPU_texture_create_3D_custom(sds->res[0], sds->res[1], sds->res[2], 1,
|
||||
GPU_R8, smoke_get_density(sds->fluid), NULL);
|
||||
}
|
||||
sds->tex_flame = (smoke_has_fuel(sds->fluid)) ? GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, smoke_get_flame(sds->fluid)) : NULL;
|
||||
sds->tex_flame = (smoke_has_fuel(sds->fluid)) ?
|
||||
GPU_texture_create_3D_custom(sds->res[0], sds->res[1], sds->res[2], 1,
|
||||
GPU_R8, smoke_get_flame(sds->fluid), NULL) :
|
||||
NULL;
|
||||
}
|
||||
else if (!sds->tex && highres) {
|
||||
/* rgba texture for color + density */
|
||||
if (smoke_turbulence_has_colors(sds->wt)) {
|
||||
float *data = MEM_callocN(sizeof(float) * smoke_turbulence_get_cells(sds->wt) * 4, "smokeColorTexture");
|
||||
smoke_turbulence_get_rgba(sds->wt, data, 0);
|
||||
sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 4, data);
|
||||
sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], data, NULL);
|
||||
MEM_freeN(data);
|
||||
}
|
||||
/* density only */
|
||||
else {
|
||||
sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 1, smoke_turbulence_get_density(sds->wt));
|
||||
sds->tex = GPU_texture_create_3D_custom(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 1,
|
||||
GPU_R8, smoke_turbulence_get_density(sds->wt), NULL);
|
||||
}
|
||||
sds->tex_flame = (smoke_turbulence_has_fuel(sds->wt)) ? GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 1, smoke_turbulence_get_flame(sds->wt)) : NULL;
|
||||
sds->tex_flame = (smoke_turbulence_has_fuel(sds->wt)) ?
|
||||
GPU_texture_create_3D_custom(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 1,
|
||||
GPU_R8, smoke_turbulence_get_flame(sds->wt), NULL):
|
||||
NULL;
|
||||
}
|
||||
|
||||
sds->tex_shadow = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, sds->shadow);
|
||||
sds->tex_shadow = GPU_texture_create_3D_custom(sds->res[0], sds->res[1], sds->res[2], 1,
|
||||
GPU_R8, sds->shadow, NULL);
|
||||
}
|
||||
#else // WITH_SMOKE
|
||||
(void)highres;
|
||||
|
|
|
@ -54,7 +54,7 @@ struct GPUFrameBuffer {
|
|||
|
||||
static void GPU_print_framebuffer_error(GLenum status, char err_out[256])
|
||||
{
|
||||
const char *format = "GPUFrameBuffer: framebuffer status %s";
|
||||
const char *format = "GPUFrameBuffer: framebuffer status %s\n";
|
||||
const char *err = "unknown";
|
||||
|
||||
#define format_status(X) \
|
||||
|
@ -453,7 +453,7 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, char err_
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ofs->color = GPU_texture_create_2D_multisample(width, height, NULL, GPU_HDR_NONE, samples, err_out);
|
||||
ofs->color = GPU_texture_create_2D_multisample(width, height, NULL, samples, err_out);
|
||||
if (!ofs->color) {
|
||||
GPU_offscreen_free(ofs);
|
||||
return NULL;
|
||||
|
|
|
@ -2369,6 +2369,11 @@ static void gpu_lamp_shadow_free(GPULamp *lamp)
|
|||
}
|
||||
}
|
||||
|
||||
static GPUTexture *gpu_lamp_create_vsm_shadow_map(int size)
|
||||
{
|
||||
return GPU_texture_create_2D_custom(size, size, 2, GPU_RG32F, NULL, NULL);
|
||||
}
|
||||
|
||||
GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
|
||||
{
|
||||
Lamp *la;
|
||||
|
@ -2415,7 +2420,7 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
|
|||
}
|
||||
|
||||
/* Shadow color map */
|
||||
lamp->tex = GPU_texture_create_vsm_shadow_map(lamp->size, NULL);
|
||||
lamp->tex = gpu_lamp_create_vsm_shadow_map(lamp->size);
|
||||
if (!lamp->tex) {
|
||||
gpu_lamp_shadow_free(lamp);
|
||||
return lamp;
|
||||
|
@ -2438,7 +2443,7 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
|
|||
return lamp;
|
||||
}
|
||||
|
||||
lamp->blurtex = GPU_texture_create_vsm_shadow_map(lamp->size * 0.5, NULL);
|
||||
lamp->blurtex = gpu_lamp_create_vsm_shadow_map(lamp->size * 0.5);
|
||||
if (!lamp->blurtex) {
|
||||
gpu_lamp_shadow_free(lamp);
|
||||
return lamp;
|
||||
|
|
|
@ -49,9 +49,8 @@ static struct GPUTextureGlobal {
|
|||
} GG = {NULL, NULL, NULL};
|
||||
|
||||
/* GPUTexture */
|
||||
|
||||
struct GPUTexture {
|
||||
int w, h; /* width/height */
|
||||
int w, h, d; /* width/height/depth */
|
||||
int number; /* number for multitexture binding */
|
||||
int refcount; /* reference count */
|
||||
GLenum target; /* GL_TEXTURE_* */
|
||||
|
@ -62,259 +61,63 @@ struct GPUTexture {
|
|||
|
||||
GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
|
||||
int fb_attachment; /* slot the texture is attached to */
|
||||
int depth; /* is a depth texture? if 3D how deep? */
|
||||
bool depth; /* is a depth texture? */
|
||||
};
|
||||
|
||||
static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels)
|
||||
static GLenum GPU_texture_get_format(int components, GPUTextureFormat data_type, GLenum *format, bool *is_depth)
|
||||
{
|
||||
unsigned char *pixels, *p;
|
||||
const float *fp = fpixels;
|
||||
const int len = 4 * length;
|
||||
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;
|
||||
|
||||
p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
for (int a = 0; a < len; a++, p++, fp++)
|
||||
*p = FTOCHAR((*fp));
|
||||
|
||||
return pixels;
|
||||
/* 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
static void GPU_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
|
||||
static float *GPU_texture_3D_rescale(GPUTexture *tex, int w, int h, int d, int channels, const float *fpixels)
|
||||
{
|
||||
void *pixels = MEM_callocN(sizeof(char) * 4 * w * h, "GPUTextureEmptyPixels");
|
||||
|
||||
if (target == GL_TEXTURE_1D)
|
||||
glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
|
||||
else
|
||||
glTexSubImage2D(target, 0, x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
MEM_freeN(pixels);
|
||||
}
|
||||
|
||||
static GPUTexture *GPU_texture_create_nD(
|
||||
int w, int h, int n, const float *fpixels, int depth,
|
||||
GPUHDRType hdr_type, int components, int samples,
|
||||
char err_out[256])
|
||||
{
|
||||
GLenum type, format, internalformat;
|
||||
void *pixels = NULL;
|
||||
|
||||
if (samples) {
|
||||
CLAMP_MAX(samples, GPU_max_color_texture_samples());
|
||||
}
|
||||
|
||||
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
||||
tex->w = w;
|
||||
tex->h = h;
|
||||
tex->number = -1;
|
||||
tex->refcount = 1;
|
||||
tex->target = (n == 1) ? GL_TEXTURE_1D : (samples ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D);
|
||||
tex->target_base = (n == 1) ? GL_TEXTURE_1D : GL_TEXTURE_2D;
|
||||
tex->depth = depth;
|
||||
tex->fb_attachment = -1;
|
||||
|
||||
glGenTextures(1, &tex->bindcode);
|
||||
|
||||
if (!tex->bindcode) {
|
||||
if (err_out) {
|
||||
BLI_snprintf(err_out, 256, "GPUTexture: texture create failed");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "GPUTexture: texture create failed");
|
||||
}
|
||||
GPU_texture_free(tex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if 0 /* this should be a compile-time check */
|
||||
if (!GPU_full_non_power_of_two_support()) {
|
||||
tex->w = power_of_2_max_i(tex->w);
|
||||
tex->h = power_of_2_max_i(tex->h);
|
||||
}
|
||||
#endif
|
||||
|
||||
tex->number = 0;
|
||||
glBindTexture(tex->target, tex->bindcode);
|
||||
|
||||
if (depth) {
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
format = GL_DEPTH_COMPONENT;
|
||||
internalformat = GL_DEPTH_COMPONENT;
|
||||
}
|
||||
else {
|
||||
type = GL_FLOAT;
|
||||
|
||||
if (components == 4) {
|
||||
format = GL_RGBA;
|
||||
switch (hdr_type) {
|
||||
case GPU_HDR_NONE:
|
||||
internalformat = GL_RGBA8;
|
||||
break;
|
||||
/* the following formats rely on ARB_texture_float or OpenGL 3.0 */
|
||||
case GPU_HDR_HALF_FLOAT:
|
||||
internalformat = GL_RGBA16F_ARB;
|
||||
break;
|
||||
case GPU_HDR_FULL_FLOAT:
|
||||
internalformat = GL_RGBA32F_ARB;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (components == 2) {
|
||||
/* these formats rely on ARB_texture_rg or OpenGL 3.0 */
|
||||
format = GL_RG;
|
||||
switch (hdr_type) {
|
||||
case GPU_HDR_NONE:
|
||||
internalformat = GL_RG8;
|
||||
break;
|
||||
case GPU_HDR_HALF_FLOAT:
|
||||
internalformat = GL_RG16F;
|
||||
break;
|
||||
case GPU_HDR_FULL_FLOAT:
|
||||
internalformat = GL_RG32F;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fpixels && hdr_type == GPU_HDR_NONE) {
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
pixels = GPU_texture_convert_pixels(w * h, fpixels);
|
||||
}
|
||||
}
|
||||
|
||||
if (tex->target == GL_TEXTURE_1D) {
|
||||
glTexImage1D(tex->target, 0, internalformat, tex->w, 0, format, type, NULL);
|
||||
|
||||
if (fpixels) {
|
||||
glTexSubImage1D(tex->target, 0, 0, w, format, type,
|
||||
pixels ? pixels : fpixels);
|
||||
|
||||
if (tex->w > w) {
|
||||
GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w - w, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (samples) {
|
||||
glTexImage2DMultisample(tex->target, samples, internalformat, tex->w, tex->h, true);
|
||||
}
|
||||
else {
|
||||
glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0,
|
||||
format, type, NULL);
|
||||
}
|
||||
|
||||
if (fpixels) {
|
||||
glTexSubImage2D(tex->target, 0, 0, 0, w, h,
|
||||
format, type, pixels ? pixels : fpixels);
|
||||
|
||||
if (tex->w > w)
|
||||
GPU_glTexSubImageEmpty(tex->target, format, w, 0, tex->w - w, tex->h);
|
||||
if (tex->h > h)
|
||||
GPU_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h - h);
|
||||
}
|
||||
}
|
||||
|
||||
if (pixels)
|
||||
MEM_freeN(pixels);
|
||||
|
||||
if (depth) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (tex->target_base != GL_TEXTURE_1D) {
|
||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
else
|
||||
glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
||||
GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels)
|
||||
{
|
||||
GLenum type, format, internalformat;
|
||||
void *pixels = NULL;
|
||||
|
||||
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
||||
tex->w = w;
|
||||
tex->h = h;
|
||||
tex->depth = depth;
|
||||
tex->number = -1;
|
||||
tex->refcount = 1;
|
||||
tex->target = GL_TEXTURE_3D;
|
||||
tex->target_base = GL_TEXTURE_3D;
|
||||
|
||||
glGenTextures(1, &tex->bindcode);
|
||||
|
||||
if (!tex->bindcode) {
|
||||
fprintf(stderr, "GPUTexture: texture create failed");
|
||||
GPU_texture_free(tex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tex->number = 0;
|
||||
glBindTexture(tex->target, tex->bindcode);
|
||||
|
||||
type = GL_FLOAT;
|
||||
if (channels == 4) {
|
||||
format = GL_RGBA;
|
||||
internalformat = GL_RGBA8;
|
||||
}
|
||||
else {
|
||||
format = GL_RED;
|
||||
internalformat = GL_INTENSITY8;
|
||||
}
|
||||
|
||||
/* 3D textures are quite heavy, test if it's possible to create them first */
|
||||
glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
|
||||
|
||||
bool rescale = false;
|
||||
int r_width;
|
||||
|
||||
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
|
||||
|
||||
while (r_width == 0) {
|
||||
rescale = true;
|
||||
tex->w /= 2;
|
||||
tex->h /= 2;
|
||||
tex->depth /= 2;
|
||||
glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
|
||||
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
|
||||
}
|
||||
|
||||
/* really unlikely to happen but keep this just in case */
|
||||
tex->w = max_ii(tex->w, 1);
|
||||
tex->h = max_ii(tex->h, 1);
|
||||
tex->depth = max_ii(tex->depth, 1);
|
||||
|
||||
#if 0
|
||||
if (fpixels)
|
||||
pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
|
||||
#endif
|
||||
|
||||
/* hardcore stuff, 3D texture rescaling - warning, this is gonna hurt your performance a lot, but we need it
|
||||
* for gooseberry */
|
||||
if (rescale && fpixels) {
|
||||
/* FIXME: should these be floating point? */
|
||||
const unsigned int xf = w / tex->w, yf = h / tex->h, zf = depth / tex->depth;
|
||||
float *tex3d = MEM_mallocN(channels * sizeof(float) * tex->w * tex->h * tex->depth, "tex3d");
|
||||
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");
|
||||
|
||||
if (nfpixels) {
|
||||
GPU_print_error_debug("You need to scale a 3D texture, feel the pain!");
|
||||
|
||||
for (unsigned k = 0; k < tex->depth; k++) {
|
||||
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,
|
||||
|
@ -326,33 +129,212 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const f
|
|||
unsigned int offset_orig = (zb) * (w * h) + (xb) * h + (yb);
|
||||
|
||||
if (channels == 4) {
|
||||
tex3d[offset * 4] = fpixels[offset_orig * 4];
|
||||
tex3d[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
|
||||
tex3d[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
|
||||
tex3d[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
|
||||
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
|
||||
tex3d[offset] = fpixels[offset_orig];
|
||||
nfpixels[offset] = fpixels[offset_orig];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, tex3d);
|
||||
|
||||
MEM_freeN(tex3d);
|
||||
}
|
||||
else if (fpixels) {
|
||||
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, fpixels);
|
||||
}
|
||||
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
return nfpixels;
|
||||
}
|
||||
|
||||
if (pixels)
|
||||
MEM_freeN(pixels);
|
||||
/* 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)
|
||||
{
|
||||
int r_width;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static GPUTexture *GPU_texture_create_nD(
|
||||
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])
|
||||
{
|
||||
GLenum format, internalformat, proxy;
|
||||
float *rescaled_fpixels = NULL;
|
||||
const float *pix;
|
||||
bool valid;
|
||||
|
||||
if (samples) {
|
||||
CLAMP_MAX(samples, GPU_max_color_texture_samples());
|
||||
}
|
||||
|
||||
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
|
||||
tex->w = w;
|
||||
tex->h = h;
|
||||
tex->d = d;
|
||||
tex->number = -1;
|
||||
tex->refcount = 1;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
tex->fb_attachment = -1;
|
||||
|
||||
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 */
|
||||
glGenTextures(1, &tex->bindcode);
|
||||
|
||||
if (!tex->bindcode) {
|
||||
if (err_out)
|
||||
BLI_snprintf(err_out, 256, "GPUTexture: texture create failed");
|
||||
else
|
||||
fprintf(stderr, "GPUTexture: texture create failed");
|
||||
GPU_texture_free(tex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tex->number = 0;
|
||||
glBindTexture(tex->target, tex->bindcode);
|
||||
|
||||
/* Check if texture fit in VRAM */
|
||||
if (d > 0) {
|
||||
proxy = GL_PROXY_TEXTURE_3D;
|
||||
}
|
||||
else if (h > 0) {
|
||||
proxy = GL_PROXY_TEXTURE_2D;
|
||||
}
|
||||
else {
|
||||
proxy = GL_PROXY_TEXTURE_1D;
|
||||
}
|
||||
|
||||
valid = GPU_texture_try_alloc(tex, proxy, internalformat, format, components, can_rescale, fpixels,
|
||||
&rescaled_fpixels);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
else if (tex->target == GL_TEXTURE_1D_ARRAY ||
|
||||
tex->target == GL_TEXTURE_2D ||
|
||||
tex->target == GL_TEXTURE_2D_MULTISAMPLE)
|
||||
{
|
||||
if (samples) {
|
||||
glTexImage2DMultisample(tex->target, samples, internalformat, tex->w, tex->h, true);
|
||||
if (pix)
|
||||
glTexSubImage2D(tex->target, 0, 0, 0, tex->w, tex->h, format, GL_FLOAT, pix);
|
||||
}
|
||||
else {
|
||||
glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0, format, GL_FLOAT, pix);
|
||||
}
|
||||
}
|
||||
else {
|
||||
glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->d, 0, format, GL_FLOAT, pix);
|
||||
}
|
||||
|
||||
if (rescaled_fpixels)
|
||||
MEM_freeN(rescaled_fpixels);
|
||||
|
||||
/* Texture Parameters */
|
||||
if (tex->depth) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
|
@ -464,114 +446,64 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
|
|||
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_1D(int w, const float *fpixels, char err_out[256])
|
||||
GPUTexture *GPU_texture_create_1D(int w, const float *pixels, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, 1, 1, fpixels, 0, GPU_HDR_NONE, 4, 0, err_out);
|
||||
|
||||
if (tex)
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
return tex;
|
||||
return GPU_texture_create_nD(w, 0, 0, 1, pixels, GPU_RGBA8, 4, 0, false, err_out);
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_2D(int w, int h, const float *fpixels, GPUHDRType hdr, char err_out[256])
|
||||
GPUTexture *GPU_texture_create_1D_custom(
|
||||
int w, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0, hdr, 4, 0, err_out);
|
||||
|
||||
if (tex)
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
return tex;
|
||||
return GPU_texture_create_nD(w, 0, 0, 1, pixels, data_type, channels, 0, false, err_out);
|
||||
}
|
||||
GPUTexture *GPU_texture_create_2D_multisample(
|
||||
int w, int h, const float *fpixels, GPUHDRType hdr, int samples, char err_out[256])
|
||||
|
||||
GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0, hdr, 4, samples, err_out);
|
||||
return GPU_texture_create_nD(w, h, 0, 2, pixels, GPU_RGBA8, 4, 0, false, err_out);
|
||||
}
|
||||
|
||||
if (tex)
|
||||
GPU_texture_unbind(tex);
|
||||
GPUTexture *GPU_texture_create_2D_custom(
|
||||
int w, int h, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256])
|
||||
{
|
||||
return GPU_texture_create_nD(w, h, 0, 2, pixels, data_type, channels, 0, false, err_out);
|
||||
}
|
||||
|
||||
return tex;
|
||||
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);
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_2D_array(int w, int h, int d, const float *pixels, char err_out[256])
|
||||
{
|
||||
return GPU_texture_create_nD(w, h, d, 2, pixels, GPU_RGBA8, 4, 0, false, err_out);
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_3D(int w, int h, int d, const float *pixels, char err_out[256])
|
||||
{
|
||||
return GPU_texture_create_nD(w, h, d, 3, pixels, GPU_RGBA8, 4, 0, true, err_out);
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_3D_custom(int w, int h, int d, int channels, GPUTextureFormat data_type, const float *pixels, char err_out[256])
|
||||
{
|
||||
return GPU_texture_create_nD(w, h, d, 3, pixels, data_type, channels, 0, true, err_out);
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1, GPU_HDR_NONE, 1, 0, err_out);
|
||||
|
||||
if (tex)
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
return tex;
|
||||
return GPU_texture_create_nD(w, h, 0, 2, NULL, GPU_DEPTH_COMPONENT24, 1, 0, false, err_out);
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_depth_multisample(int w, int h, int samples, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1, GPU_HDR_NONE, 1, samples, err_out);
|
||||
|
||||
if (tex)
|
||||
GPU_texture_unbind(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
/**
|
||||
* A shadow map for VSM needs two components (depth and depth^2)
|
||||
*/
|
||||
GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, GPU_HDR_FULL_FLOAT, 2, 0, err_out);
|
||||
|
||||
if (tex) {
|
||||
/* Now we tweak some of the settings */
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
GPU_texture_unbind(tex);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, bool repeat, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, h, 2, pixels, 0, GPU_HDR_HALF_FLOAT, 2, 0, err_out);
|
||||
|
||||
if (tex) {
|
||||
/* Now we tweak some of the settings */
|
||||
if (repeat) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
GPU_texture_unbind(tex);
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
GPUTexture *GPU_texture_create_1D_procedural(int w, const float *pixels, char err_out[256])
|
||||
{
|
||||
GPUTexture *tex = GPU_texture_create_nD(w, 0, 1, pixels, 0, GPU_HDR_HALF_FLOAT, 2, 0, err_out);
|
||||
|
||||
if (tex) {
|
||||
/* Now we tweak some of the settings */
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
GPU_texture_unbind(tex);
|
||||
}
|
||||
|
||||
return tex;
|
||||
return GPU_texture_create_nD(w, h, 0, 2, NULL, GPU_DEPTH_COMPONENT24, 1, samples, false, err_out);
|
||||
}
|
||||
|
||||
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);
|
||||
GG.invalid_tex_2D = GPU_texture_create_2D(1, 1, color, GPU_HDR_NONE, NULL);
|
||||
GG.invalid_tex_3D = GPU_texture_create_3D(1, 1, 1, 4, color);
|
||||
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);
|
||||
}
|
||||
|
||||
void GPU_invalid_tex_bind(int mode)
|
||||
|
@ -624,7 +556,13 @@ void GPU_texture_bind(GPUTexture *tex, int number)
|
|||
else
|
||||
GPU_invalid_tex_bind(tex->target_base);
|
||||
|
||||
glEnable(tex->target_base); /* TODO: remove this line once we're using GLSL everywhere */
|
||||
/* 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);
|
||||
|
||||
if (number != 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
@ -646,7 +584,14 @@ void GPU_texture_unbind(GPUTexture *tex)
|
|||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
||||
|
||||
glBindTexture(tex->target_base, 0);
|
||||
glDisable(tex->target_base); /* TODO: remove this line */
|
||||
|
||||
/* 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);
|
||||
|
||||
if (tex->number != 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
@ -659,7 +604,7 @@ int GPU_texture_bound_number(GPUTexture *tex)
|
|||
return tex->number;
|
||||
}
|
||||
|
||||
void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter)
|
||||
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
|
||||
{
|
||||
if (tex->number >= GPU_max_textures()) {
|
||||
fprintf(stderr, "Not enough texture slots.\n");
|
||||
|
@ -672,13 +617,54 @@ void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter)
|
|||
if (tex->number != 0)
|
||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
||||
|
||||
if (tex->depth) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE);
|
||||
/* 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;
|
||||
}
|
||||
|
||||
if (tex->number == -1)
|
||||
return;
|
||||
|
||||
if (tex->number != 0)
|
||||
glActiveTexture(GL_TEXTURE0 + tex->number);
|
||||
|
||||
GLenum filter = use_filter ? GL_LINEAR : GL_NEAREST;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
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);
|
||||
|
||||
if (tex->number != 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
|
|
@ -62,7 +62,7 @@ void GPU_viewport_free(GPUViewport *viewport)
|
|||
|
||||
bool GPU_viewport_debug_depth_create(GPUViewport *viewport, int width, int height, char err_out[256])
|
||||
{
|
||||
viewport->debug_depth = GPU_texture_create_2D(width, height, NULL, GPU_HDR_HALF_FLOAT, err_out);
|
||||
viewport->debug_depth = GPU_texture_create_2D_custom(width, height, 4, GPU_RGBA16F, NULL, err_out);
|
||||
return (viewport->debug_depth != NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue