Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Werner <stefan.werner@tangent-animation.com>2021-08-21 23:03:31 +0300
committerStefan Werner <stefan.werner@tangent-animation.com>2021-08-21 23:03:31 +0300
commitc5b56a525cd6113caa2bd3ec7bfb91fe4a04513a (patch)
tree77dae5ae2fbeccf6703034c94ad3e1f3aa81140b /source/blender/gpu/intern
parent34e8d79c3edbc58fd242cec0c1f2bed4e43855af (diff)
parent67c29bc5a273b66e278bd20c18187b425acf1869 (diff)
Merge branch 'master' into cycles_texture_cachecycles_texture_cache
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r--source/blender/gpu/intern/gpu_framebuffer.cc5
-rw-r--r--source/blender/gpu/intern/gpu_immediate.cc12
-rw-r--r--source/blender/gpu/intern/gpu_material.c1
-rw-r--r--source/blender/gpu/intern/gpu_matrix.cc122
-rw-r--r--source/blender/gpu/intern/gpu_texture.cc36
5 files changed, 72 insertions, 104 deletions
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index a6f7d43e563..9099a6e4245 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -591,7 +591,7 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs)
}
GPUOffScreen *GPU_offscreen_create(
- int width, int height, bool depth, bool high_bitdepth, char err_out[256])
+ int width, int height, bool depth, eGPUTextureFormat format, char err_out[256])
{
GPUOffScreen *ofs = (GPUOffScreen *)MEM_callocN(sizeof(GPUOffScreen), __func__);
@@ -600,8 +600,7 @@ GPUOffScreen *GPU_offscreen_create(
height = max_ii(1, height);
width = max_ii(1, width);
- ofs->color = GPU_texture_create_2d(
- "ofs_color", width, height, 1, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, nullptr);
+ ofs->color = GPU_texture_create_2d("ofs_color", width, height, 1, format, nullptr);
if (depth) {
ofs->depth = GPU_texture_create_2d(
diff --git a/source/blender/gpu/intern/gpu_immediate.cc b/source/blender/gpu/intern/gpu_immediate.cc
index 062741a6270..cdd56a117db 100644
--- a/source/blender/gpu/intern/gpu_immediate.cc
+++ b/source/blender/gpu/intern/gpu_immediate.cc
@@ -313,7 +313,7 @@ void immAttr1f(uint attr_id, float x)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
}
@@ -329,7 +329,7 @@ void immAttr2f(uint attr_id, float x, float y)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
data[1] = y;
@@ -346,7 +346,7 @@ void immAttr3f(uint attr_id, float x, float y, float z)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
data[1] = y;
@@ -364,7 +364,7 @@ void immAttr4f(uint attr_id, float x, float y, float z, float w)
setAttrValueBit(attr_id);
float *data = (float *)(imm->vertex_data + attr->offset);
- /* printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm->buffer_data, data);
data[0] = x;
data[1] = y;
@@ -445,7 +445,7 @@ void immAttr3ub(uint attr_id, uchar r, uchar g, uchar b)
setAttrValueBit(attr_id);
uchar *data = imm->vertex_data + attr->offset;
- /* printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data);
data[0] = r;
data[1] = g;
@@ -463,7 +463,7 @@ void immAttr4ub(uint attr_id, uchar r, uchar g, uchar b, uchar a)
setAttrValueBit(attr_id);
uchar *data = imm->vertex_data + attr->offset;
- /* printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data); */
+ // printf("%s %td %p\n", __FUNCTION__, data - imm->buffer_data, data);
data[0] = r;
data[1] = g;
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 37089785e0e..56e72fbeca9 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -758,6 +758,7 @@ GPUMaterial *GPU_material_from_nodetree(Scene *scene,
/* Only free after GPU_pass_shader_get where GPUUniformBuf
* read data from the local tree. */
ntreeFreeLocalTree(localtree);
+ BLI_assert(!localtree->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
MEM_freeN(localtree);
/* note that even if building the shader fails in some way, we still keep
diff --git a/source/blender/gpu/intern/gpu_matrix.cc b/source/blender/gpu/intern/gpu_matrix.cc
index 6eb9cb823d5..bbcc241f5e3 100644
--- a/source/blender/gpu/intern/gpu_matrix.cc
+++ b/source/blender/gpu/intern/gpu_matrix.cc
@@ -513,93 +513,55 @@ void GPU_matrix_project_2fv(const float world[3],
win[1] = view[1] + (view[3] * (v[1] + 1)) * 0.5f;
}
-/**
- * The same result could be obtained as follows:
- *
- * \code{.c}
- * float projinv[4][4];
- * invert_m4_m4(projinv, projmat);
- * co[0] = 2 * co[0] - 1;
- * co[1] = 2 * co[1] - 1;
- * co[2] = 2 * co[2] - 1;
- * mul_project_m4_v3(projinv, co);
- * \endcode
- *
- * But that solution loses much precision.
- * Therefore, get the same result without inverting the matrix.
- */
-static void gpu_mul_invert_projmat_m4_unmapped_v3_with_precalc(
- const struct GPUMatrixUnproject_Precalc *precalc, float co[3])
-{
- /* 'precalc->dims' is the result of 'projmat_dimensions(proj, ...)'. */
- co[0] = precalc->dims.xmin + co[0] * (precalc->dims.xmax - precalc->dims.xmin);
- co[1] = precalc->dims.ymin + co[1] * (precalc->dims.ymax - precalc->dims.ymin);
-
- if (precalc->is_persp) {
- co[2] = precalc->dims.zmax * precalc->dims.zmin /
- (precalc->dims.zmax + co[2] * (precalc->dims.zmin - precalc->dims.zmax));
- co[0] *= co[2];
- co[1] *= co[2];
- }
- else {
- co[2] = precalc->dims.zmin + co[2] * (precalc->dims.zmax - precalc->dims.zmin);
- }
- co[2] *= -1;
-}
-
-bool GPU_matrix_unproject_precalc(struct GPUMatrixUnproject_Precalc *precalc,
- const float model[4][4],
- const float proj[4][4],
- const int view[4])
-{
- precalc->is_persp = proj[3][3] == 0.0f;
- projmat_dimensions_db(proj,
- &precalc->dims.xmin,
- &precalc->dims.xmax,
- &precalc->dims.ymin,
- &precalc->dims.ymax,
- &precalc->dims.zmin,
- &precalc->dims.zmax);
- if (isinf(precalc->dims.zmax)) {
- /* We cannot retrieve the actual value of the clip_end.
- * Use `FLT_MAX` to avoid NAN's. */
- precalc->dims.zmax = FLT_MAX;
- }
- for (int i = 0; i < 4; i++) {
- precalc->view[i] = (float)view[i];
- }
- if (!invert_m4_m4(precalc->model_inverted, model)) {
- unit_m4(precalc->model_inverted);
- return false;
- }
- return true;
-}
-
-void GPU_matrix_unproject_3fv_with_precalc(const struct GPUMatrixUnproject_Precalc *precalc,
- const float win[3],
- float r_world[3])
-{
- float in[3] = {
- (win[0] - precalc->view[0]) / precalc->view[2],
- (win[1] - precalc->view[1]) / precalc->view[3],
- win[2],
- };
- gpu_mul_invert_projmat_m4_unmapped_v3_with_precalc(precalc, in);
- mul_v3_m4v3(r_world, precalc->model_inverted, in);
-}
-
bool GPU_matrix_unproject_3fv(const float win[3],
- const float model[4][4],
+ const float model_inverted[4][4],
const float proj[4][4],
const int view[4],
float r_world[3])
{
- struct GPUMatrixUnproject_Precalc precalc;
- if (!GPU_matrix_unproject_precalc(&precalc, model, proj, view)) {
- zero_v3(r_world);
+ zero_v3(r_world);
+ float in[3] = {
+ 2 * ((win[0] - view[0]) / view[2]) - 1.0f,
+ 2 * ((win[1] - view[1]) / view[3]) - 1.0f,
+ 2 * win[2] - 1.0f,
+ };
+
+ /**
+ * The same result could be obtained as follows:
+ *
+ * \code{.c}
+ * float projinv[4][4];
+ * invert_m4_m4(projinv, projview);
+ * copy_v3_v3(r_world, in);
+ * mul_project_m4_v3(projinv, r_world);
+ * \endcode
+ *
+ * But that solution loses much precision.
+ * Therefore, get the same result without inverting the project view matrix.
+ */
+
+ float out[3];
+ const bool is_persp = proj[3][3] == 0.0f;
+ if (is_persp) {
+ out[2] = proj[3][2] / (proj[2][2] + in[2]);
+ if (isinf(out[2])) {
+ out[2] = FLT_MAX;
+ }
+ out[0] = out[2] * ((proj[2][0] + in[0]) / proj[0][0]);
+ out[1] = out[2] * ((proj[2][1] + in[1]) / proj[1][1]);
+ out[2] *= -1;
+ }
+ else {
+ out[0] = (-proj[3][0] + in[0]) / proj[0][0];
+ out[1] = (-proj[3][1] + in[1]) / proj[1][1];
+ out[2] = (-proj[3][2] + in[2]) / proj[2][2];
+ }
+
+ if (!is_finite_v3(out)) {
return false;
}
- GPU_matrix_unproject_3fv_with_precalc(&precalc, win, r_world);
+
+ mul_v3_m4v3(r_world, model_inverted, out);
return true;
}
diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc
index 6564cbda694..d5d13ea269f 100644
--- a/source/blender/gpu/intern/gpu_texture.cc
+++ b/source/blender/gpu/intern/gpu_texture.cc
@@ -241,55 +241,61 @@ static inline GPUTexture *gpu_texture_create(const char *name,
}
GPUTexture *GPU_texture_create_1d(
- const char *name, int w, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
{
- return gpu_texture_create(name, w, 0, 0, GPU_TEXTURE_1D, mips, format, GPU_DATA_FLOAT, data);
+ return gpu_texture_create(name, w, 0, 0, GPU_TEXTURE_1D, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_1d_array(
- const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
{
return gpu_texture_create(
- name, w, h, 0, GPU_TEXTURE_1D_ARRAY, mips, format, GPU_DATA_FLOAT, data);
+ name, w, h, 0, GPU_TEXTURE_1D_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_2d(
- const char *name, int w, int h, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
{
- return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_2D, mips, format, GPU_DATA_FLOAT, data);
+ return gpu_texture_create(name, w, h, 0, GPU_TEXTURE_2D, mip_len, format, GPU_DATA_FLOAT, data);
}
-GPUTexture *GPU_texture_create_2d_array(
- const char *name, int w, int h, int d, int mips, eGPUTextureFormat format, const float *data)
+GPUTexture *GPU_texture_create_2d_array(const char *name,
+ int w,
+ int h,
+ int d,
+ int mip_len,
+ eGPUTextureFormat format,
+ const float *data)
{
return gpu_texture_create(
- name, w, h, d, GPU_TEXTURE_2D_ARRAY, mips, format, GPU_DATA_FLOAT, data);
+ name, w, h, d, GPU_TEXTURE_2D_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_3d(const char *name,
int w,
int h,
int d,
- int mips,
+ int mip_len,
eGPUTextureFormat texture_format,
eGPUDataFormat data_format,
const void *data)
{
return gpu_texture_create(
- name, w, h, d, GPU_TEXTURE_3D, mips, texture_format, data_format, data);
+ name, w, h, d, GPU_TEXTURE_3D, mip_len, texture_format, data_format, data);
}
GPUTexture *GPU_texture_create_cube(
- const char *name, int w, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
{
- return gpu_texture_create(name, w, w, 0, GPU_TEXTURE_CUBE, mips, format, GPU_DATA_FLOAT, data);
+ return gpu_texture_create(
+ name, w, w, 0, GPU_TEXTURE_CUBE, mip_len, format, GPU_DATA_FLOAT, data);
}
GPUTexture *GPU_texture_create_cube_array(
- const char *name, int w, int d, int mips, eGPUTextureFormat format, const float *data)
+ const char *name, int w, int d, int mip_len, eGPUTextureFormat format, const float *data)
{
return gpu_texture_create(
- name, w, w, d, GPU_TEXTURE_CUBE_ARRAY, mips, format, GPU_DATA_FLOAT, data);
+ name, w, w, d, GPU_TEXTURE_CUBE_ARRAY, mip_len, format, GPU_DATA_FLOAT, data);
}
/* DDS texture loading. Return NULL if support is not available. */