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:
authorDalai Felinto <dfelinto@gmail.com>2016-10-21 23:50:00 +0300
committerDalai Felinto <dfelinto@gmail.com>2016-10-21 23:51:12 +0300
commit5ff586610a47aa26ed388270c9a26487c553f1f1 (patch)
treec152a29097278e1e52c29678eefc4dbff136e8d6 /source/blender/gpu
parentdeb77c0e7490ed300a7688bf462de85f36ee1ca3 (diff)
Viewport: use depth shader to debug the depth
At the moment this already shows that the depth is the same after the solid plates and in the very end of drawing, while they should be different. Later on we can adapt this to show different buffers we want to debug. I am using near=0.1, far=2.0 for my tests. I decided not to make a doversion for near/far because this is for debugging only
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/GPU_viewport.h11
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c89
2 files changed, 100 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_viewport.h b/source/blender/gpu/GPU_viewport.h
index 82b537e1c3d..e2519484eb4 100644
--- a/source/blender/gpu/GPU_viewport.h
+++ b/source/blender/gpu/GPU_viewport.h
@@ -32,10 +32,21 @@
#ifndef __GPU_VIEWPORT_H__
#define __GPU_VIEWPORT_H__
+#include <stdbool.h>
+
typedef struct GPUViewport GPUViewport;
GPUViewport *GPU_viewport_create(void);
void GPU_viewport_free(GPUViewport *viewport);
+/* debug */
+bool GPU_viewport_debug_depth_create(GPUViewport *viewport, int width, int height, int samples, char err_out[256]);
+void GPU_viewport_debug_depth_free(GPUViewport *viewport);
+void GPU_viewport_debug_depth_store(GPUViewport *viewport, const int x, const int y);
+void GPU_viewport_debug_depth_draw(GPUViewport *viewport, const float znear, const float zfar);
+bool GPU_viewport_debug_depth_is_valid(GPUViewport *viewport);
+int GPU_viewport_debug_depth_width(const GPUViewport *viewport);
+int GPU_viewport_debug_depth_height(const GPUViewport *viewport);
+
#endif // __GPU_VIEWPORT_H__
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index bae2fdc552d..6cad0506cf4 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -31,12 +31,19 @@
* System that manages viewport drawing.
*/
+#include "GPU_glew.h"
+#include "GPU_immediate.h"
#include "GPU_viewport.h"
+#include "GPU_texture.h"
#include "MEM_guardedalloc.h"
struct GPUViewport {
float pad[4];
+
+ /* debug */
+ GPUTexture *debug_depth;
+ int debug_width, debug_height;
};
GPUViewport *GPU_viewport_create(void)
@@ -47,6 +54,88 @@ GPUViewport *GPU_viewport_create(void)
void GPU_viewport_free(GPUViewport *viewport)
{
+ GPU_viewport_debug_depth_free(viewport);
MEM_freeN(viewport);
}
+/****************** debug ********************/
+
+bool GPU_viewport_debug_depth_create(GPUViewport *viewport, int width, int height, int samples, char err_out[256])
+{
+ viewport->debug_depth = GPU_texture_create_2D(width, height, NULL, GPU_HDR_HALF_FLOAT, err_out);
+ return (viewport->debug_depth != NULL);
+}
+
+void GPU_viewport_debug_depth_free(GPUViewport *viewport)
+{
+ if (viewport->debug_depth != NULL) {
+ MEM_freeN(viewport->debug_depth);
+ viewport->debug_depth = NULL;
+ }
+}
+
+void GPU_viewport_debug_depth_store(GPUViewport *viewport, const int x, const int y)
+{
+ const int w = GPU_texture_width(viewport->debug_depth);
+ const int h = GPU_texture_height(viewport->debug_depth);
+
+ GPU_texture_bind(viewport->debug_depth, 0);
+ glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, x, y, w, h, 0);
+ GPU_texture_unbind(viewport->debug_depth);
+}
+
+void GPU_viewport_debug_depth_draw(GPUViewport *viewport, const float znear, const float zfar)
+{
+ const float w = (float)GPU_texture_width(viewport->debug_depth);
+ const float h = (float)GPU_texture_height(viewport->debug_depth);
+
+ const int activeTex = GL_TEXTURE0;
+ glActiveTexture(activeTex);
+
+ VertexFormat *format = immVertexFormat();
+ unsigned texcoord = add_attrib(format, "texCoord", GL_FLOAT, 2, KEEP_FLOAT);
+ unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_DEPTH);
+
+ GPU_texture_bind(viewport->debug_depth, 0);
+
+ immUniform1f("znear", znear);
+ immUniform1f("zfar", zfar);
+ immUniform1i("image", activeTex);
+
+ immBegin(GL_QUADS, 4);
+
+ immAttrib2f(texcoord, 0.0f, 0.0f);
+ immVertex2f(pos, 0.0f, 0.0f);
+
+ immAttrib2f(texcoord, 1.0f, 0.0f);
+ immVertex2f(pos, w, 0.0f);
+
+ immAttrib2f(texcoord, 1.0f, 1.0f);
+ immVertex2f(pos, w, h);
+
+ immAttrib2f(texcoord, 0.0f, 1.0f);
+ immVertex2f(pos, 0.0f, h);
+
+ immEnd();
+
+ GPU_texture_unbind(viewport->debug_depth);
+
+ immUnbindProgram();
+}
+
+int GPU_viewport_debug_depth_width(const GPUViewport *viewport)
+{
+ return GPU_texture_width(viewport->debug_depth);
+}
+
+int GPU_viewport_debug_depth_height(const GPUViewport *viewport)
+{
+ return GPU_texture_height(viewport->debug_depth);
+}
+
+bool GPU_viewport_debug_depth_is_valid(GPUViewport *viewport)
+{
+ return viewport->debug_depth != NULL;
+}