[Bf-blender-cvs] [c79216d77df] blender2.8: GPU_offscreen: Add option for high bit depth.

Clément Foucault noreply at git.blender.org
Thu Jan 4 10:53:35 CET 2018


Commit: c79216d77df77e10f7ee3fed17836c77eb29da54
Author: Clément Foucault
Date:   Wed Jan 3 13:15:32 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBc79216d77df77e10f7ee3fed17836c77eb29da54

GPU_offscreen: Add option for high bit depth.

This way we can render in HDR and read the real pixel values.

===================================================================

M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/screen/screen_draw.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_draw_legacy.c
M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/gpu/intern/gpu_texture.c
M	source/blender/python/intern/gpu_offscreen.c

===================================================================

diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 3c63aed9473..cc52a814a29 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -652,7 +652,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
 	sizey = (scene->r.size * scene->r.ysch) / 100;
 
 	/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
-	ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
+	ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, true, err_out);
 
 	if (!ofs) {
 		BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c
index 5690076fedb..91b2be27d84 100644
--- a/source/blender/editors/screen/screen_draw.c
+++ b/source/blender/editors/screen/screen_draw.c
@@ -481,7 +481,7 @@ static void screen_preview_draw(const bScreen *screen, int size_x, int size_y)
 void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, unsigned int *r_rect)
 {
 	char err_out[256] = "unknown";
-	GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, 0, err_out);
+	GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, 0, false, err_out);
 
 	GPU_offscreen_bind(offscreen, true);
 	glClearColor(0.0, 0.0, 0.0, 0.0);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 4a00329bd09..5f9c7a598f5 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2109,7 +2109,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 
 	if (own_ofs) {
 		/* bind */
-		ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, err_out);
+		ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, false, err_out);
 		if (ofs == NULL) {
 			return NULL;
 		}
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
index fa09ca169fe..ffb7c3dc612 100644
--- a/source/blender/editors/space_view3d/view3d_draw_legacy.c
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -284,7 +284,7 @@ static void backdrawview3d(const struct EvaluationContext *eval_ctx, Scene *scen
 		}
 
 		if (!rv3d->gpuoffscreen) {
-			rv3d->gpuoffscreen = GPU_offscreen_create(w, h, 0, error);
+			rv3d->gpuoffscreen = GPU_offscreen_create(w, h, 0, false, error);
 
 			if (!rv3d->gpuoffscreen)
 				fprintf(stderr, "Failed to create offscreen selection buffer for multisample: %s\n", error);
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 705ef1997c1..c58d98c201e 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -83,7 +83,7 @@ void GPU_framebuffer_recursive_downsample(
  * - wrapper around framebuffer and texture for simple offscreen drawing
  * - changes size if graphics card can't support it */
 
-GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, char err_out[256]);
+GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool high_bitdepth, char err_out[256]);
 void GPU_offscreen_free(GPUOffScreen *ofs);
 void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
 void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 82e215f6fae..3ed9ab4bf2c 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -152,6 +152,8 @@ GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, char err_ou
 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_custom_multisample(
+        int w, int h, int channels, GPUTextureFormat data_type, const float *pixels, int samples, char err_out[256]);
 GPUTexture *GPU_texture_create_2D_array_custom(
         int w, int h, int d, int channels, GPUTextureFormat data_type, 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]);
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c
index 6830e73cb03..09013cd29bd 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.c
+++ b/source/blender/gpu/intern/gpu_framebuffer.c
@@ -650,7 +650,7 @@ struct GPUOffScreen {
 	GPUTexture *depth;
 };
 
-GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, char err_out[256])
+GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool high_bitdepth, char err_out[256])
 {
 	GPUOffScreen *ofs;
 
@@ -683,7 +683,12 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, char err_
 		return NULL;
 	}
 
-	ofs->color = GPU_texture_create_2D_multisample(width, height, NULL, samples, err_out);
+	if (high_bitdepth) {
+		ofs->color = GPU_texture_create_2D_custom_multisample(width, height, 4, GPU_RGBA16F, NULL, samples, err_out);
+	}
+	else {
+		ofs->color = GPU_texture_create_2D_multisample(width, height, NULL, samples, err_out);
+	}
 	if (!ofs->color) {
 		GPU_offscreen_free(ofs);
 		return NULL;
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index 252eede8758..bcc0bb2649f 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -663,6 +663,12 @@ GPUTexture *GPU_texture_create_2D_multisample(int w, int h, const float *pixels,
 	return GPU_texture_create_nD(w, h, 0, 2, pixels, GPU_RGBA8, 4, samples, false, err_out);
 }
 
+GPUTexture *GPU_texture_create_2D_custom_multisample(
+        int w, int h, int channels, GPUTextureFormat data_type, const float *pixels, int samples, char err_out[256])
+{
+	return GPU_texture_create_nD(w, h, 0, 2, pixels, data_type, channels, samples, false, err_out);
+}
+
 GPUTexture *GPU_texture_create_2D_array_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, 2, pixels, data_type, channels, 0, false, err_out);
diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c
index 226bfcc7c21..91d407d18a8 100644
--- a/source/blender/python/intern/gpu_offscreen.c
+++ b/source/blender/python/intern/gpu_offscreen.c
@@ -354,7 +354,7 @@ static PyObject *pygpu_offscreen_new(PyObject *UNUSED(self), PyObject *args, PyO
 		return NULL;
 	}
 
-	ofs = GPU_offscreen_create(width, height, samples, err_out);
+	ofs = GPU_offscreen_create(width, height, samples, false, err_out);
 
 	if (ofs == NULL) {
 		PyErr_Format(PyExc_RuntimeError,



More information about the Bf-blender-cvs mailing list