Gawain: add immRect utility functions (replaces legacy glRect)
authorMike Erwin <significant.bit@gmail.com>
Mon, 10 Oct 2016 16:30:55 +0000 (12:30 -0400)
committerMike Erwin <significant.bit@gmail.com>
Mon, 10 Oct 2016 16:31:38 +0000 (12:31 -0400)
Caller is responsible for setting up vertex format, binding a shader program, and setting the color *before* calling immRect.

source/blender/gpu/CMakeLists.txt
source/blender/gpu/GPU_immediate.h
source/blender/gpu/gawain/imm_util.c [new file with mode: 0644]
source/blender/gpu/gawain/imm_util.h [new file with mode: 0644]

index 6b23bfc46428db7a96dd08d74843fbac011401f5..668a948144a1dda23108c6b816967ac95ffec8d0 100644 (file)
@@ -72,6 +72,8 @@ set(SRC
        gawain/element.h
        gawain/immediate.c
        gawain/immediate.h
+       gawain/imm_util.c
+       gawain/imm_util.h
        gawain/vertex_buffer.c
        gawain/vertex_buffer.h
        gawain/vertex_format.c
index 7c4b1614f375b04bd7ee0d39d975cf5da7924d96..8e7f91b0f7f6c7e7dc1b4e27f1308b56fe25a105 100644 (file)
@@ -31,6 +31,7 @@
 #pragma once
 
 #include "gawain/immediate.h"
+#include "gawain/imm_util.h"
 #include "GPU_shader.h"
 
 /* Extend immBindProgram to use Blender’s library of built-in shader programs.
diff --git a/source/blender/gpu/gawain/imm_util.c b/source/blender/gpu/gawain/imm_util.c
new file mode 100644 (file)
index 0000000..0f253fe
--- /dev/null
@@ -0,0 +1,46 @@
+
+// Gawain immediate mode drawing utilities
+//
+// This code is part of the Gawain library, with modifications
+// specific to integration with Blender.
+//
+// Copyright 2016 Mike Erwin
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
+// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+#include "imm_util.h"
+#include "immediate.h"
+
+
+void immRectf(unsigned pos, float x1, float y1, float x2, float y2)
+{
+       immBegin(GL_TRIANGLE_FAN, 4);
+       immVertex2f(pos, x1, y1);
+       immVertex2f(pos, x2, y1);
+       immVertex2f(pos, x2, y2);
+       immVertex2f(pos, x1, y2);
+       immEnd();
+}
+
+void immRecti(unsigned pos, int x1, int y1, int x2, int y2)
+{
+       immBegin(GL_TRIANGLE_FAN, 4);
+       immVertex2i(pos, x1, y1);
+       immVertex2i(pos, x2, y1);
+       immVertex2i(pos, x2, y2);
+       immVertex2i(pos, x1, y2);
+       immEnd();
+}
+
+#if 0 // more complete version in case we want that
+void immRecti_complete(int x1, int y1, int x2, int y2, const float color[4])
+{
+       VertexFormat *format = immVertexFormat();
+       unsigned pos = add_attrib(format, "pos", GL_INT, 2, CONVERT_INT_TO_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformColor4fv(color);
+       immRecti(pos, x1, y1, x2, y2);
+       immUnbindProgram();
+}
+#endif
diff --git a/source/blender/gpu/gawain/imm_util.h b/source/blender/gpu/gawain/imm_util.h
new file mode 100644 (file)
index 0000000..730bd7c
--- /dev/null
@@ -0,0 +1,18 @@
+
+// Gawain immediate mode drawing utilities
+//
+// This code is part of the Gawain library, with modifications
+// specific to integration with Blender.
+//
+// Copyright 2016 Mike Erwin
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
+// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+#pragma once
+
+
+// Draw 2D rectangles (replaces glRect functions)
+// caller is reponsible for vertex format & shader
+void immRectf(unsigned pos, float x1, float y1, float x2, float y2);
+void immRecti(unsigned pos, int x1, int y1, int x2, int y2);