[Bf-blender-cvs] [5eddb80] blender2.8: Extend Gawain to use Blender's built-in shaders

Mike Erwin noreply at git.blender.org
Thu Sep 15 21:45:36 CEST 2016


Commit: 5eddb8051382aa4406f6fb33b3eb0f748c6d1911
Author: Mike Erwin
Date:   Thu Sep 15 18:41:28 2016 +0200
Branches: blender2.8
https://developer.blender.org/rB5eddb8051382aa4406f6fb33b3eb0f748c6d1911

Extend Gawain to use Blender's built-in shaders

Was already done for immediate mode, but rearranged code to make a clean separation. Cleaned up #includes for code that uses this feature.

Added same for batched rendering.

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

M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_batch.h
M	source/blender/gpu/GPU_immediate.h
M	source/blender/gpu/GPU_shader.h
A	source/blender/gpu/intern/gpu_batch.c
A	source/blender/gpu/intern/gpu_immediate.c
M	source/blender/gpu/intern/gpu_shader.c
A	source/blender/gpu/intern/gpu_shader_private.h

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

diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index c6f7224..5ee05a4 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -57,7 +57,6 @@
 
 #include "GPU_draw.h"
 #include "GPU_basic_shader.h"
-#include "GPU_shader.h"
 #include "GPU_immediate.h"
 
 #include "UI_interface.h"
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index f3c0b72..0ae4c7e 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -58,7 +58,6 @@
 #include "interface_intern.h"
 
 #include "GPU_basic_shader.h"
-#include "GPU_shader.h"
 #include "GPU_immediate.h"
 
 #ifdef WITH_INPUT_IME
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 0924f02..574f887 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -57,7 +57,6 @@
 #include "ED_screen_types.h"
 #include "ED_space_api.h"
 
-#include "GPU_shader.h"
 #include "GPU_immediate.h"
 
 #include "BIF_gl.h"
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index e3b32eb..77f19d3 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -100,7 +100,6 @@
 #include "GPU_material.h"
 #include "GPU_compositing.h"
 #include "GPU_extensions.h"
-#include "GPU_shader.h"
 #include "GPU_immediate.h"
 
 #include "view3d_intern.h"  /* own include */
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 63ae58d..6d3052b 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -47,6 +47,7 @@ set(INC_SYS
 
 set(SRC
 	intern/gpu_basic_shader.c
+	intern/gpu_batch.c
 	intern/gpu_buffers.c
 	intern/gpu_codegen.c
 	intern/gpu_compositing.c
@@ -54,6 +55,7 @@ set(SRC
 	intern/gpu_draw.c
 	intern/gpu_extensions.c
 	intern/gpu_framebuffer.c
+	intern/gpu_immediate.c
 	intern/gpu_init_exit.c
 	intern/gpu_material.c
 	intern/gpu_select.c
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 10b00c3..bc3017e 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -31,3 +31,7 @@
 #pragma once
 
 #include "gawain/batch.h"
+#include "GPU_shader.h"
+
+/* Extend Batch_set_program to use Blender’s library of built-in shader programs. */
+void Batch_set_builtin_program(Batch*, GPUBuiltinShader);
diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h
index 8b88275..7c4b161 100644
--- a/source/blender/gpu/GPU_immediate.h
+++ b/source/blender/gpu/GPU_immediate.h
@@ -31,3 +31,8 @@
 #pragma once
 
 #include "gawain/immediate.h"
+#include "GPU_shader.h"
+
+/* Extend immBindProgram to use Blender’s library of built-in shader programs.
+ * Use immUnbindProgram() when done. */
+void immBindBuiltinProgram(GPUBuiltinShader);
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 2a1c5e0..196b0ec 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -106,10 +106,6 @@ GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp);
 
 void GPU_shader_free_builtin_shaders(void);
 
-/* Extend Gawain’s immBindProgram to use Blender’s library of built-in shader programs.
- * Use immUnbindProgram() when done. */
-void immBindBuiltinProgram(GPUBuiltinShader);
-
 /* Vertex attributes for shaders */
 
 #define GPU_MAX_ATTRIB 32
diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/intern/gpu_batch.c
similarity index 71%
copy from source/blender/gpu/GPU_immediate.h
copy to source/blender/gpu/intern/gpu_batch.c
index 8b88275..23f9f68 100644
--- a/source/blender/gpu/GPU_immediate.h
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -4,7 +4,7 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. 
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,16 +18,18 @@
  * The Original Code is Copyright (C) 2016 Blender Foundation.
  * All rights reserved.
  *
- * 
+ * The Original Code is: all of this file.
+ *
  * Contributor(s): Mike Erwin
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/* Immediate mode rendering is powered by the Gawain library.
- * This file contains any additions or modifications specific to Blender.
- */
-
-#pragma once
+#include "GPU_batch.h"
+#include "gpu_shader_private.h"
 
-#include "gawain/immediate.h"
+void Batch_set_builtin_program(Batch* batch, GPUBuiltinShader shader_id)
+{
+	GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
+	Batch_set_program(batch, shader->program);
+}
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/intern/gpu_immediate.c
similarity index 73%
copy from source/blender/gpu/GPU_batch.h
copy to source/blender/gpu/intern/gpu_immediate.c
index 10b00c3..0fc4253 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -4,7 +4,7 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. 
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,16 +18,18 @@
  * The Original Code is Copyright (C) 2016 Blender Foundation.
  * All rights reserved.
  *
- * 
+ * The Original Code is: all of this file.
+ *
  * Contributor(s): Mike Erwin
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/* Batched geometry rendering is powered by the Gawain library.
- * This file contains any additions or modifications specific to Blender.
- */
-
-#pragma once
+#include "GPU_immediate.h"
+#include "gpu_shader_private.h"
 
-#include "gawain/batch.h"
+void immBindBuiltinProgram(GPUBuiltinShader shader_id)
+{
+	GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
+	immBindProgram(shader->program);
+}
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 9fe3c3a..e9a5732 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -36,10 +36,9 @@
 #include "GPU_compositing.h"
 #include "GPU_debug.h"
 #include "GPU_extensions.h"
-#include "GPU_glew.h"
 #include "GPU_shader.h"
+#include "GPU_shader_private.h"
 #include "GPU_texture.h"
-#include "GPU_immediate.h"
 
 /* TODO(sergey): Find better default values for this constants. */
 #define MAX_DEFINE_LENGTH 1024
@@ -95,20 +94,6 @@ static struct GPUShadersGlobal {
 	} shaders;
 } GG = {{NULL}};
 
-/* GPUShader */
-
-struct GPUShader {
-	GLuint program;  /* handle for full program (links shader stages below) */
-
-	GLuint vertex;   /* handle for vertex shader */
-	GLuint geometry; /* handle for geometry shader */
-	GLuint fragment; /* handle for fragment shader */
-
-	int totattrib;   /* total number of attributes */
-	int uniforms;    /* required uniforms */
-
-	void *uniform_interface; /* cached uniform interface for shader. Data depends on shader */
-};
 
 static void shader_print_errors(const char *task, const char *log, const char **code, int totcode)
 {
@@ -828,9 +813,3 @@ void GPU_shader_free_builtin_shaders(void)
 		}
 	}
 }
-
-void immBindBuiltinProgram(GPUBuiltinShader shader_id)
-{
-	GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
-	immBindProgram(shader->program);
-}
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/intern/gpu_shader_private.h
similarity index 57%
copy from source/blender/gpu/GPU_batch.h
copy to source/blender/gpu/intern/gpu_shader_private.h
index 10b00c3..d5193e0 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/intern/gpu_shader_private.h
@@ -4,7 +4,7 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. 
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,19 +15,26 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2016 Blender Foundation.
- * All rights reserved.
- *
- * 
- * Contributor(s): Mike Erwin
- *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/* Batched geometry rendering is powered by the Gawain library.
- * This file contains any additions or modifications specific to Blender.
+/** \file gpu_shader_private.h
+ *  \ingroup gpu
  */
 
 #pragma once
 
-#include "gawain/batch.h"
+#include "GPU_glew.h"
+
+struct GPUShader {
+	GLuint program;  /* handle for full program (links shader stages below) */
+
+	GLuint vertex;   /* handle for vertex shader */
+	GLuint geometry; /* handle for geometry shader */
+	GLuint fragment; /* handle for fragment shader */
+
+	int totattrib;   /* total number of attributes */
+	int uniforms;    /* required uniforms */
+
+	void *uniform_interface; /* cached uniform interface for shader. Data depends on shader */
+};




More information about the Bf-blender-cvs mailing list