GWN: Port to GPU module: Move files to GPU
authorClément Foucault <foucault.clem@gmail.com>
Tue, 17 Jul 2018 19:11:23 +0000 (21:11 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Tue, 17 Jul 2018 22:17:57 +0000 (00:17 +0200)
This does not include all the struct and type renaming. Only files were
renamed.

gwn_batch.c/h was fusioned with GPU_batch.c/h
gwn_immediate.c/h was fusioned with GPU_immediate.c/h
gwn_imm_util.c/h was fusioned with GPU_immediate_util.c/h

51 files changed:
intern/CMakeLists.txt
intern/gawain/CMakeLists.txt [deleted file]
intern/gawain/gawain/gwn_batch.h [deleted file]
intern/gawain/gawain/gwn_imm_util.h [deleted file]
intern/gawain/gawain/gwn_immediate.h [deleted file]
intern/gawain/src/gwn_batch.c [deleted file]
intern/gawain/src/gwn_imm_util.c [deleted file]
intern/gawain/src/gwn_immediate.c [deleted file]
intern/opencolorio/CMakeLists.txt
intern/opencolorio/ocio_impl_glsl.cc
source/blender/blenfont/intern/blf_internal_types.h
source/blender/draw/engines/eevee/eevee_lightcache.c
source/blender/draw/intern/draw_manager.c
source/blender/draw/intern/draw_manager.h
source/blender/gpu/CMakeLists.txt
source/blender/gpu/GPU_attr_binding.h [moved from intern/gawain/gawain/gwn_attr_binding.h with 98% similarity]
source/blender/gpu/GPU_batch.h
source/blender/gpu/GPU_buffer_id.h [moved from intern/gawain/gawain/gwn_buffer_id.h with 98% similarity]
source/blender/gpu/GPU_common.h [moved from intern/gawain/gawain/gwn_common.h with 100% similarity]
source/blender/gpu/GPU_context.h [moved from intern/gawain/gawain/gwn_context.h with 94% similarity]
source/blender/gpu/GPU_element.h [moved from intern/gawain/gawain/gwn_element.h with 99% similarity]
source/blender/gpu/GPU_immediate.h
source/blender/gpu/GPU_immediate_util.h
source/blender/gpu/GPU_primitive.h [moved from intern/gawain/gawain/gwn_primitive.h with 98% similarity]
source/blender/gpu/GPU_shader_interface.h [moved from intern/gawain/gawain/gwn_shader_interface.h with 99% similarity]
source/blender/gpu/GPU_vertex_array_id.h [moved from intern/gawain/gawain/gwn_vertex_array_id.h with 96% similarity]
source/blender/gpu/GPU_vertex_buffer.h [moved from intern/gawain/gawain/gwn_vertex_buffer.h with 99% similarity]
source/blender/gpu/GPU_vertex_format.h [moved from intern/gawain/gawain/gwn_vertex_format.h with 99% similarity]
source/blender/gpu/intern/gpu_attr_binding.c [moved from intern/gawain/src/gwn_attr_binding.c with 97% similarity]
source/blender/gpu/intern/gpu_attr_binding_private.h [moved from intern/gawain/gawain/gwn_attr_binding_private.h with 95% similarity]
source/blender/gpu/intern/gpu_batch.c
source/blender/gpu/intern/gpu_batch_private.h [moved from intern/gawain/gawain/gwn_batch_private.h with 92% similarity]
source/blender/gpu/intern/gpu_buffer_id.cpp [moved from intern/gawain/src/gwn_buffer_id.cpp with 98% similarity]
source/blender/gpu/intern/gpu_element.c [moved from intern/gawain/src/gwn_element.c with 99% similarity]
source/blender/gpu/intern/gpu_immediate.c
source/blender/gpu/intern/gpu_immediate_util.c
source/blender/gpu/intern/gpu_matrix.c
source/blender/gpu/intern/gpu_primitive.c [moved from intern/gawain/src/gwn_primitive.c with 97% similarity]
source/blender/gpu/intern/gpu_primitive_private.h [moved from intern/gawain/gawain/gwn_primitive_private.h with 100% similarity]
source/blender/gpu/intern/gpu_shader_interface.c [moved from intern/gawain/src/gwn_shader_interface.c with 99% similarity]
source/blender/gpu/intern/gpu_shader_private.h
source/blender/gpu/intern/gpu_vertex_array_id.cpp [moved from intern/gawain/src/gwn_vertex_array_id.cpp with 98% similarity]
source/blender/gpu/intern/gpu_vertex_buffer.c [moved from intern/gawain/src/gwn_vertex_buffer.c with 98% similarity]
source/blender/gpu/intern/gpu_vertex_format.c [moved from intern/gawain/src/gwn_vertex_format.c with 99% similarity]
source/blender/gpu/intern/gpu_vertex_format_private.h [moved from intern/gawain/gawain/gwn_vertex_format_private.h with 100% similarity]
source/blender/python/gawain/gwn_py_api.c
source/blender/python/gawain/gwn_py_types.c
source/blender/render/CMakeLists.txt
source/blender/render/intern/source/pipeline.c
source/blender/windowmanager/intern/wm_playanim.c
source/blender/windowmanager/intern/wm_window.c

index 1a0508928362b64d779f685bc977846f323ecbd4..1459100d41583d334add5d744b7d7141c90fedde 100644 (file)
@@ -34,7 +34,6 @@ add_subdirectory(opencolorio)
 add_subdirectory(mikktspace)
 add_subdirectory(glew-mx)
 add_subdirectory(eigen)
-add_subdirectory(gawain)
 
 if(WITH_AUDASPACE)
        add_subdirectory(audaspace)
diff --git a/intern/gawain/CMakeLists.txt b/intern/gawain/CMakeLists.txt
deleted file mode 100644 (file)
index 7ebd3ee..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-# WITH_OPENGL limits the visibility of the opengl headers to just gawain and bg_gpu,
-# to more easily highlight codepadths in other libraries that need to be refactored,
-# bf_intern_gawain is allowed to have opengl regardless of this option.
-
-if(NOT WITH_OPENGL)
-       add_definitions(-DWITH_OPENGL)
-endif()
-
-set(INC
-       gawain
-)
-
-set(INC_SYS
-       ${GLEW_INCLUDE_PATH}
-)
-
-set(SRC
-       src/gwn_attr_binding.c
-       src/gwn_batch.c
-       src/gwn_element.c
-       src/gwn_buffer_id.cpp
-       src/gwn_immediate.c
-       src/gwn_imm_util.c
-       src/gwn_primitive.c
-       src/gwn_shader_interface.c
-       src/gwn_vertex_array_id.cpp
-       src/gwn_vertex_buffer.c
-       src/gwn_vertex_format.c
-
-       gawain/gwn_attr_binding.h
-       gawain/gwn_attr_binding_private.h
-       gawain/gwn_batch.h
-       gawain/gwn_batch_private.h
-       gawain/gwn_buffer_id.h
-       gawain/gwn_common.h
-       gawain/gwn_element.h
-       gawain/gwn_imm_util.h
-       gawain/gwn_immediate.h
-       gawain/gwn_primitive.h
-       gawain/gwn_primitive_private.h
-       gawain/gwn_shader_interface.h
-       gawain/gwn_vertex_array_id.h
-       gawain/gwn_vertex_buffer.h
-       gawain/gwn_vertex_format.h
-       gawain/gwn_vertex_format_private.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-blender_add_lib(bf_intern_gawain "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/gawain/gawain/gwn_batch.h b/intern/gawain/gawain/gwn_batch.h
deleted file mode 100644 (file)
index a7a5450..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 by Mike Erwin.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/gwn_batch.h
- *  \ingroup gpu
- *
- * Gawain geometry batch
- * Contains VAOs + VBOs + Shader representing a drawable entity.
- */
-
-#ifndef __GWN_BATCH_H__
-#define __GWN_BATCH_H__
-
-#include "gwn_vertex_buffer.h"
-#include "gwn_element.h"
-#include "gwn_shader_interface.h"
-
-typedef enum {
-       GWN_BATCH_READY_TO_FORMAT,
-       GWN_BATCH_READY_TO_BUILD,
-       GWN_BATCH_BUILDING,
-       GWN_BATCH_READY_TO_DRAW
-} Gwn_BatchPhase;
-
-#define GWN_BATCH_VBO_MAX_LEN 3
-#define GWN_BATCH_VAO_STATIC_LEN 3
-#define GWN_BATCH_VAO_DYN_ALLOC_COUNT 16
-
-typedef struct Gwn_Batch {
-       /* geometry */
-       Gwn_VertBuf* verts[GWN_BATCH_VBO_MAX_LEN]; /* verts[0] is required, others can be NULL */
-       Gwn_VertBuf* inst; /* instance attribs */
-       Gwn_IndexBuf* elem; /* NULL if element list not needed */
-       uint32_t gl_prim_type;
-
-       /* cached values (avoid dereferencing later) */
-       uint32_t vao_id;
-       uint32_t program;
-       const struct Gwn_ShaderInterface* interface;
-
-       /* book-keeping */
-       uint owns_flag;
-       struct Gwn_Context *context; /* used to free all vaos. this implies all vaos were created under the same context. */
-       Gwn_BatchPhase phase;
-       bool program_in_use;
-
-       /* Vao management: remembers all geometry state (vertex attrib bindings & element buffer)
-        * for each shader interface. Start with a static number of vaos and fallback to dynamic count
-        * if necessary. Once a batch goes dynamic it does not go back. */
-       bool is_dynamic_vao_count;
-       union {
-               /* Static handle count */
-               struct {
-                       const struct Gwn_ShaderInterface* interfaces[GWN_BATCH_VAO_STATIC_LEN];
-                       uint32_t vao_ids[GWN_BATCH_VAO_STATIC_LEN];
-               } static_vaos;
-               /* Dynamic handle count */
-               struct {
-                       uint count;
-                       const struct Gwn_ShaderInterface** interfaces;
-                       uint32_t* vao_ids;
-               } dynamic_vaos;
-       };
-
-       /* XXX This is the only solution if we want to have some data structure using
-        * batches as key to identify nodes. We must destroy these nodes with this callback. */
-       void (*free_callback)(struct Gwn_Batch*, void*);
-       void* callback_data;
-} Gwn_Batch;
-
-enum {
-       GWN_BATCH_OWNS_VBO = (1 << 0),
-       /* each vbo index gets bit-shifted */
-       GWN_BATCH_OWNS_INSTANCES = (1 << 30),
-       GWN_BATCH_OWNS_INDEX = (1 << 31),
-};
-
-Gwn_Batch* GWN_batch_create_ex(Gwn_PrimType, Gwn_VertBuf*, Gwn_IndexBuf*, uint owns_flag);
-void GWN_batch_init_ex(Gwn_Batch*, Gwn_PrimType, Gwn_VertBuf*, Gwn_IndexBuf*, uint owns_flag);
-Gwn_Batch* GWN_batch_duplicate(Gwn_Batch* batch_src);
-
-#define GWN_batch_create(prim, verts, elem) \
-       GWN_batch_create_ex(prim, verts, elem, 0)
-#define GWN_batch_init(batch, prim, verts, elem) \
-       GWN_batch_init_ex(batch, prim, verts, elem, 0)
-
-void GWN_batch_discard(Gwn_Batch*); /* verts & elem are not discarded */
-
-void GWN_batch_callback_free_set(Gwn_Batch*, void (*callback)(Gwn_Batch*, void*), void*);
-
-void GWN_batch_instbuf_set(Gwn_Batch*, Gwn_VertBuf*, bool own_vbo); /* Instancing */
-
-int GWN_batch_vertbuf_add_ex(Gwn_Batch*, Gwn_VertBuf*, bool own_vbo);
-
-#define GWN_batch_vertbuf_add(batch, verts) \
-       GWN_batch_vertbuf_add_ex(batch, verts, false)
-
-void GWN_batch_program_set_no_use(Gwn_Batch*, uint32_t program, const Gwn_ShaderInterface*);
-void GWN_batch_program_set(Gwn_Batch*, uint32_t program, const Gwn_ShaderInterface*);
-/* Entire batch draws with one shader program, but can be redrawn later with another program. */
-/* Vertex shader's inputs must be compatible with the batch's vertex format. */
-
-void GWN_batch_program_use_begin(Gwn_Batch*); /* call before Batch_Uniform (temp hack?) */
-void GWN_batch_program_use_end(Gwn_Batch*);
-
-void GWN_batch_uniform_1ui(Gwn_Batch*, const char* name, int value);
-void GWN_batch_uniform_1i(Gwn_Batch*, const char* name, int value);
-void GWN_batch_uniform_1b(Gwn_Batch*, const char* name, bool value);
-void GWN_batch_uniform_1f(Gwn_Batch*, const char* name, float value);
-void GWN_batch_uniform_2f(Gwn_Batch*, const char* name, float x, float y);
-void GWN_batch_uniform_3f(Gwn_Batch*, const char* name, float x, float y, float z);
-void GWN_batch_uniform_4f(Gwn_Batch*, const char* name, float x, float y, float z, float w);
-void GWN_batch_uniform_2fv(Gwn_Batch*, const char* name, const float data[2]);
-void GWN_batch_uniform_3fv(Gwn_Batch*, const char* name, const float data[3]);
-void GWN_batch_uniform_4fv(Gwn_Batch*, const char* name, const float data[4]);
-void GWN_batch_uniform_2fv_array(Gwn_Batch*, const char* name, int len, const float *data);
-void GWN_batch_uniform_4fv_array(Gwn_Batch*, const char* name, int len, const float *data);
-void GWN_batch_uniform_mat4(Gwn_Batch*, const char* name, const float data[4][4]);
-
-void GWN_batch_draw(Gwn_Batch*);
-
-/* This does not bind/unbind shader and does not call GPU_matrix_bind() */
-void GWN_batch_draw_range_ex(Gwn_Batch*, int v_first, int v_count, bool force_instance);
-
-/* Does not even need batch */
-void GWN_draw_primitive(Gwn_PrimType, int v_count);
-
-#if 0 /* future plans */
-
-/* Can multiple batches share a Gwn_VertBuf? Use ref count? */
-
-
-/* We often need a batch with its own data, to be created and discarded together. */
-/* WithOwn variants reduce number of system allocations. */
-
-typedef struct BatchWithOwnVertexBuffer {
-       Gwn_Batch batch;
-       Gwn_VertBuf verts; /* link batch.verts to this */
-} BatchWithOwnVertexBuffer;
-
-typedef struct BatchWithOwnElementList {
-       Gwn_Batch batch;
-       Gwn_IndexBuf elem; /* link batch.elem to this */
-} BatchWithOwnElementList;
-
-typedef struct BatchWithOwnVertexBufferAndElementList {
-       Gwn_Batch batch;
-       Gwn_IndexBuf elem; /* link batch.elem to this */
-       Gwn_VertBuf verts; /* link batch.verts to this */
-} BatchWithOwnVertexBufferAndElementList;
-
-Gwn_Batch* create_BatchWithOwnVertexBuffer(Gwn_PrimType, Gwn_VertFormat*, uint v_len, Gwn_IndexBuf*);
-Gwn_Batch* create_BatchWithOwnElementList(Gwn_PrimType, Gwn_VertBuf*, uint prim_len);
-Gwn_Batch* create_BatchWithOwnVertexBufferAndElementList(Gwn_PrimType, Gwn_VertFormat*, uint v_len, uint prim_len);
-/* verts: shared, own */
-/* elem: none, shared, own */
-Gwn_Batch* create_BatchInGeneral(Gwn_PrimType, VertexBufferStuff, ElementListStuff);
-
-#endif /* future plans */
-
-
-/* Macros */
-
-#define GWN_BATCH_DISCARD_SAFE(batch) do { \
-       if (batch != NULL) { \
-               GWN_batch_discard(batch); \
-               batch = NULL; \
-       } \
-} while (0)
-
-#endif /* __GWN_BATCH_H__ */
diff --git a/intern/gawain/gawain/gwn_imm_util.h b/intern/gawain/gawain/gwn_imm_util.h
deleted file mode 100644 (file)
index e512d07..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 by Mike Erwin.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/gwn_imm_util.h
- *  \ingroup gpu
- *
- * Gawain element list (AKA index buffer)
- */
-
-#ifndef __GWN_IMM_UTIL_H__
-#define __GWN_IMM_UTIL_H__
-
-#include <stdlib.h>
-
-/* Draw 2D rectangles (replaces glRect functions) */
-/* caller is reponsible for vertex format & shader */
-void immRectf(uint pos, float x1, float y1, float x2, float y2);
-void immRecti(uint pos, int x1, int y1, int x2, int y2);
-
-/* Same as immRectf/immRecti but does not call immBegin/immEnd. To use with GWN_PRIM_TRIS. */
-void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4]);
-void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4]);
-
-#endif /* __GWN_IMM_UTIL_H__ */
diff --git a/intern/gawain/gawain/gwn_immediate.h b/intern/gawain/gawain/gwn_immediate.h
deleted file mode 100644 (file)
index 8231942..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 by Mike Erwin.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/gwn_immediate.h
- *  \ingroup gpu
- *
- * Gawain immediate mode work-alike
- */
-
-#ifndef __GWN_IMMEDIATE_H__
-#define __GWN_IMMEDIATE_H__
-
-#include "gwn_vertex_format.h"
-#include "gwn_primitive.h"
-#include "gwn_shader_interface.h"
-#include "gwn_batch.h"
-
-Gwn_VertFormat* immVertexFormat(void); /* returns a cleared vertex format, ready for add_attrib. */
-
-void immBindProgram(uint32_t program, const Gwn_ShaderInterface*); /* every immBegin must have a program bound first. */
-void immUnbindProgram(void); /* call after your last immEnd, or before binding another program. */
-
-void immBegin(Gwn_PrimType, uint vertex_len); /* must supply exactly vertex_len vertices. */
-void immBeginAtMost(Gwn_PrimType, uint max_vertex_len); /* can supply fewer vertices. */
-void immEnd(void); /* finishes and draws. */
-
-/* ImmBegin a batch, then use standard immFunctions as usual. */
-/* ImmEnd will finalize the batch instead of drawing. */
-/* Then you can draw it as many times as you like! Partially replaces the need for display lists. */
-Gwn_Batch* immBeginBatch(Gwn_PrimType, uint vertex_len);
-Gwn_Batch* immBeginBatchAtMost(Gwn_PrimType, uint vertex_len);
-
-/* Provide attribute values that can change per vertex. */
-/* First vertex after immBegin must have all its attributes specified. */
-/* Skipped attributes will continue using the previous value for that attrib_id. */
-void immAttrib1f(uint attrib_id, float x);
-void immAttrib2f(uint attrib_id, float x, float y);
-void immAttrib3f(uint attrib_id, float x, float y, float z);
-void immAttrib4f(uint attrib_id, float x, float y, float z, float w);
-
-void immAttrib2i(uint attrib_id, int x, int y);
-
-void immAttrib1u(uint attrib_id, uint x);
-
-void immAttrib2s(uint attrib_id, short x, short y);
-
-void immAttrib2fv(uint attrib_id, const float data[2]);
-void immAttrib3fv(uint attrib_id, const float data[3]);
-void immAttrib4fv(uint attrib_id, const float data[4]);
-
-void immAttrib3ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b);
-void immAttrib4ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
-
-void immAttrib3ubv(uint attrib_id, const unsigned char data[4]);
-void immAttrib4ubv(uint attrib_id, const unsigned char data[4]);
-
-/* Explicitly skip an attribute. */
-/* This advanced option kills automatic value copying for this attrib_id. */
-void immSkipAttrib(uint attrib_id);
-
-/* Provide one last attribute value & end the current vertex. */
-/* This is most often used for 2D or 3D position (similar to glVertex). */
-void immVertex2f(uint attrib_id, float x, float y);
-void immVertex3f(uint attrib_id, float x, float y, float z);
-void immVertex4f(uint attrib_id, float x, float y, float z, float w);
-
-void immVertex2i(uint attrib_id, int x, int y);
-
-void immVertex2s(uint attrib_id, short x, short y);
-
-void immVertex2fv(uint attrib_id, const float data[2]);
-void immVertex3fv(uint attrib_id, const float data[3]);
-
-void immVertex2iv(uint attrib_id, const int data[2]);
-
-/* Provide uniform values that don't change for the entire draw call. */
-void immUniform1i(const char* name, int x);
-void immUniform4iv(const char* name, const int data[4]);
-void immUniform1f(const char* name, float x);
-void immUniform2f(const char* name, float x, float y);
-void immUniform2fv(const char* name, const float data[2]);
-void immUniform3f(const char* name, float x, float y, float z);
-void immUniform3fv(const char* name, const float data[3]);
-void immUniformArray3fv(const char* name, const float *data, int count);
-void immUniform4f(const char* name, float x, float y, float z, float w);
-void immUniform4fv(const char* name, const float data[4]);
-void immUniformArray4fv(const char* bare_name, const float *data, int count);
-void immUniformMatrix4fv(const char* name, const float data[4][4]);
-
-/* Convenience functions for setting "uniform vec4 color". */
-/* The rgb functions have implicit alpha = 1.0. */
-void immUniformColor4f(float r, float g, float b, float a);
-void immUniformColor4fv(const float rgba[4]);
-void immUniformColor3f(float r, float g, float b);
-void immUniformColor3fv(const float rgb[3]);
-void immUniformColor3fvAlpha(const float rgb[3], float a);
-
-void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b);
-void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
-void immUniformColor3ubv(const unsigned char rgb[3]);
-void immUniformColor3ubvAlpha(const unsigned char rgb[3], unsigned char a);
-void immUniformColor4ubv(const unsigned char rgba[4]);
-
-/* These are called by the system -- not part of drawing API. */
-void immInit(void);
-void immActivate(void);
-void immDeactivate(void);
-void immDestroy(void);
-
-#endif /* __GWN_IMMEDIATE_H__ */
diff --git a/intern/gawain/src/gwn_batch.c b/intern/gawain/src/gwn_batch.c
deleted file mode 100644 (file)
index 5daf0e8..0000000
+++ /dev/null
@@ -1,645 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 by Mike Erwin.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/intern/gwn_batch.c
- *  \ingroup gpu
- *
- * Gawain geometry batch
- * Contains VAOs + VBOs + Shader representing a drawable entity.
- */
-
-#include "gwn_batch.h"
-#include "gwn_batch_private.h"
-#include "gwn_buffer_id.h"
-#include "gwn_vertex_array_id.h"
-#include "gwn_primitive_private.h"
-#include <stdlib.h>
-#include <string.h>
-
-/* necessary functions from matrix API */
-extern void GPU_matrix_bind(const Gwn_ShaderInterface* shaderface);
-
-static void batch_update_program_bindings(Gwn_Batch* batch, uint v_first);
-
-void gwn_batch_vao_cache_clear(Gwn_Batch* batch)
-{
-       if (batch->context == NULL) {
-               return;
-       }
-       if (batch->is_dynamic_vao_count) {
-               for (int i = 0; i < batch->dynamic_vaos.count; ++i) {
-                       if (batch->dynamic_vaos.vao_ids[i]) {
-                               GWN_vao_free(batch->dynamic_vaos.vao_ids[i], batch->context);
-                       }
-                       if (batch->dynamic_vaos.interfaces[i]) {
-                               GWN_shaderinterface_remove_batch_ref((Gwn_ShaderInterface *)batch->dynamic_vaos.interfaces[i], batch);
-                       }
-               }
-               free(batch->dynamic_vaos.interfaces);
-               free(batch->dynamic_vaos.vao_ids);
-       }
-       else {
-               for (int i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) {
-                       if (batch->static_vaos.vao_ids[i]) {
-                               GWN_vao_free(batch->static_vaos.vao_ids[i], batch->context);
-                       }
-                       if (batch->static_vaos.interfaces[i]) {
-                               GWN_shaderinterface_remove_batch_ref((Gwn_ShaderInterface *)batch->static_vaos.interfaces[i], batch);
-                       }
-               }
-       }
-       batch->is_dynamic_vao_count = false;
-       for (int i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) {
-               batch->static_vaos.vao_ids[i] = 0;
-               batch->static_vaos.interfaces[i] = NULL;
-       }
-       gwn_context_remove_batch(batch->context, batch);
-       batch->context = NULL;
-}
-
-Gwn_Batch* GWN_batch_create_ex(
-        Gwn_PrimType prim_type, Gwn_VertBuf* verts, Gwn_IndexBuf* elem,
-        uint owns_flag)
-{
-       Gwn_Batch* batch = calloc(1, sizeof(Gwn_Batch));
-       GWN_batch_init_ex(batch, prim_type, verts, elem, owns_flag);
-       return batch;
-}
-
-void GWN_batch_init_ex(
-        Gwn_Batch* batch, Gwn_PrimType prim_type, Gwn_VertBuf* verts, Gwn_IndexBuf* elem,
-        uint owns_flag)
-{
-#if TRUST_NO_ONE
-       assert(verts != NULL);
-#endif
-
-       batch->verts[0] = verts;
-       for (int v = 1; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
-               batch->verts[v] = NULL;
-       }
-       batch->inst = NULL;
-       batch->elem = elem;
-       batch->gl_prim_type = convert_prim_type_to_gl(prim_type);
-       batch->phase = GWN_BATCH_READY_TO_DRAW;
-       batch->is_dynamic_vao_count = false;
-       batch->owns_flag = owns_flag;
-       batch->free_callback = NULL;
-}
-
-/* This will share the VBOs with the new batch. */
-Gwn_Batch* GWN_batch_duplicate(Gwn_Batch* batch_src)
-{
-       Gwn_Batch* batch = GWN_batch_create_ex(GWN_PRIM_POINTS, batch_src->verts[0], batch_src->elem, 0);
-
-       batch->gl_prim_type = batch_src->gl_prim_type;
-       for (int v = 1; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
-               batch->verts[v] = batch_src->verts[v];
-       }
-       return batch;
-}
-
-void GWN_batch_discard(Gwn_Batch* batch)
-{
-       if (batch->owns_flag & GWN_BATCH_OWNS_INDEX) {
-               GWN_indexbuf_discard(batch->elem);
-       }
-       if (batch->owns_flag & GWN_BATCH_OWNS_INSTANCES) {
-               GWN_vertbuf_discard(batch->inst);
-       }
-       if ((batch->owns_flag & ~GWN_BATCH_OWNS_INDEX) != 0) {
-               for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
-                       if (batch->verts[v] == NULL) {
-                               break;
-                       }
-                       if (batch->owns_flag & (1 << v)) {
-                               GWN_vertbuf_discard(batch->verts[v]);
-                       }
-               }
-       }
-       gwn_batch_vao_cache_clear(batch);
-
-       if (batch->free_callback) {
-               batch->free_callback(batch, batch->callback_data);
-       }
-       free(batch);
-}
-
-void GWN_batch_callback_free_set(Gwn_Batch* batch, void (*callback)(Gwn_Batch*, void*), void* user_data)
-{
-       batch->free_callback = callback;
-       batch->callback_data = user_data;
-}
-
-void GWN_batch_instbuf_set(Gwn_Batch* batch, Gwn_VertBuf* inst, bool own_vbo)
-{
-#if TRUST_NO_ONE
-       assert(inst != NULL);
-#endif
-       /* redo the bindings */
-       gwn_batch_vao_cache_clear(batch);
-
-       if (batch->inst != NULL && (batch->owns_flag & GWN_BATCH_OWNS_INSTANCES)) {
-               GWN_vertbuf_discard(batch->inst);
-       }
-       batch->inst = inst;
-
-       if (own_vbo) {
-               batch->owns_flag |= GWN_BATCH_OWNS_INSTANCES;
-       }
-       else {
-               batch->owns_flag &= ~GWN_BATCH_OWNS_INSTANCES;
-       }
-}
-
-/* Returns the index of verts in the batch. */
-int GWN_batch_vertbuf_add_ex(
-        Gwn_Batch* batch, Gwn_VertBuf* verts,
-        bool own_vbo)
-{
-       /* redo the bindings */
-       gwn_batch_vao_cache_clear(batch);
-
-       for (uint v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
-               if (batch->verts[v] == NULL) {
-#if TRUST_NO_ONE
-                       /* for now all VertexBuffers must have same vertex_len */
-                       assert(verts->vertex_len == batch->verts[0]->vertex_len);
-#endif
-                       batch->verts[v] = verts;
-                       /* TODO: mark dirty so we can keep attrib bindings up-to-date */
-                       if (own_vbo)
-                               batch->owns_flag |= (1 << v);
-                       return v;
-               }
-       }
-
-       /* we only make it this far if there is no room for another Gwn_VertBuf */
-#if TRUST_NO_ONE
-       assert(false);
-#endif
-       return -1;
-}
-
-static GLuint batch_vao_get(Gwn_Batch *batch)
-{
-       /* Search through cache */
-       if (batch->is_dynamic_vao_count) {
-               for (int i = 0; i < batch->dynamic_vaos.count; ++i)
-                       if (batch->dynamic_vaos.interfaces[i] == batch->interface)
-                               return batch->dynamic_vaos.vao_ids[i];
-       }
-       else {
-               for (int i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i)
-                       if (batch->static_vaos.interfaces[i] == batch->interface)
-                               return batch->static_vaos.vao_ids[i];
-       }
-
-       /* Set context of this batch.
-        * It will be bound to it until gwn_batch_vao_cache_clear is called.
-        * Until then it can only be drawn with this context. */
-       if (batch->context == NULL) {
-               batch->context = GWN_context_active_get();
-               gwn_context_add_batch(batch->context, batch);
-       }
-#if TRUST_NO_ONE
-       else {
-               /* Make sure you are not trying to draw this batch in another context. */
-               assert(batch->context == GWN_context_active_get());
-       }
-#endif
-
-       /* Cache miss, time to add a new entry! */
-       GLuint new_vao = 0;
-       if (!batch->is_dynamic_vao_count) {
-               int i; /* find first unused slot */
-               for (i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) 
-                       if (batch->static_vaos.vao_ids[i] == 0)
-                               break;
-
-               if (i < GWN_BATCH_VAO_STATIC_LEN) {
-                       batch->static_vaos.interfaces[i] = batch->interface;
-                       batch->static_vaos.vao_ids[i] = new_vao = GWN_vao_alloc();
-               }
-               else {
-                       /* Not enough place switch to dynamic. */
-                       batch->is_dynamic_vao_count = true;
-                       /* Erase previous entries, they will be added back if drawn again. */
-                       for (int j = 0; j < GWN_BATCH_VAO_STATIC_LEN; ++j) {
-                               GWN_shaderinterface_remove_batch_ref((Gwn_ShaderInterface*)batch->static_vaos.interfaces[j], batch);
-                               GWN_vao_free(batch->static_vaos.vao_ids[j], batch->context);
-                       }
-                       /* Init dynamic arrays and let the branch below set the values. */
-                       batch->dynamic_vaos.count = GWN_BATCH_VAO_DYN_ALLOC_COUNT;
-                       batch->dynamic_vaos.interfaces = calloc(batch->dynamic_vaos.count, sizeof(Gwn_ShaderInterface*));
-                       batch->dynamic_vaos.vao_ids = calloc(batch->dynamic_vaos.count, sizeof(GLuint));
-               }
-       }
-
-       if (batch->is_dynamic_vao_count) {
-               int i; /* find first unused slot */
-               for (i = 0; i < batch->dynamic_vaos.count; ++i)
-                       if (batch->dynamic_vaos.vao_ids[i] == 0)
-                               break;
-
-               if (i == batch->dynamic_vaos.count) {
-                       /* Not enough place, realloc the array. */
-                       i = batch->dynamic_vaos.count;
-                       batch->dynamic_vaos.count += GWN_BATCH_VAO_DYN_ALLOC_COUNT;
-                       batch->dynamic_vaos.interfaces = realloc(batch->dynamic_vaos.interfaces, sizeof(Gwn_ShaderInterface*) * batch->dynamic_vaos.count);
-                       batch->dynamic_vaos.vao_ids = realloc(batch->dynamic_vaos.vao_ids, sizeof(GLuint) * batch->dynamic_vaos.count);
-                       memset(batch->dynamic_vaos.interfaces + i, 0, sizeof(Gwn_ShaderInterface*) * GWN_BATCH_VAO_DYN_ALLOC_COUNT);
-                       memset(batch->dynamic_vaos.vao_ids + i, 0, sizeof(GLuint) * GWN_BATCH_VAO_DYN_ALLOC_COUNT);
-               }
-               batch->dynamic_vaos.interfaces[i] = batch->interface;
-               batch->dynamic_vaos.vao_ids[i] = new_vao = GWN_vao_alloc();
-       }
-
-       GWN_shaderinterface_add_batch_ref((Gwn_ShaderInterface*)batch->interface, batch);
-
-#if TRUST_NO_ONE
-       assert(new_vao != 0);
-#endif
-
-       /* We just got a fresh VAO we need to initialize it. */
-       glBindVertexArray(new_vao);
-       batch_update_program_bindings(batch, 0);
-       glBindVertexArray(0);
-
-       return new_vao;
-}
-
-void GWN_batch_program_set_no_use(Gwn_Batch* batch, uint32_t program, const Gwn_ShaderInterface* shaderface)
-{
-#if TRUST_NO_ONE
-       assert(glIsProgram(shaderface->program));
-       assert(batch->program_in_use == 0);
-#endif
-       batch->interface = shaderface;
-       batch->program = program;
-       batch->vao_id = batch_vao_get(batch);
-}
-
-void GWN_batch_program_set(Gwn_Batch* batch, uint32_t program, const Gwn_ShaderInterface* shaderface)
-{
-       GWN_batch_program_set_no_use(batch, program, shaderface);
-       GWN_batch_program_use_begin(batch); /* hack! to make Batch_Uniform* simpler */
-}
-
-void gwn_batch_remove_interface_ref(Gwn_Batch* batch, const Gwn_ShaderInterface* interface)
-{
-       if (batch->is_dynamic_vao_count) {
-               for (int i = 0; i < batch->dynamic_vaos.count; ++i) {
-                       if (batch->dynamic_vaos.interfaces[i] == interface) {
-                               GWN_vao_free(batch->dynamic_vaos.vao_ids[i], batch->context);
-                               batch->dynamic_vaos.vao_ids[i] = 0;
-                               batch->dynamic_vaos.interfaces[i] = NULL;
-                               break; /* cannot have duplicates */
-                       }
-               }
-       }
-       else {
-               int i;
-               for (i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) {
-                       if (batch->static_vaos.interfaces[i] == interface) {
-                               GWN_vao_free(batch->static_vaos.vao_ids[i], batch->context);
-                               batch->static_vaos.vao_ids[i] = 0;
-                               batch->static_vaos.interfaces[i] = NULL;
-                               break; /* cannot have duplicates */
-                       }
-               }
-       }
-}
-
-static void create_bindings(
-        Gwn_VertBuf* verts, const Gwn_ShaderInterface* interface,
-        uint v_first, const bool use_instancing)
-{
-       const Gwn_VertFormat* format = &verts->format;
-
-       const uint attr_len = format->attr_len;
-       const uint stride = format->stride;
-
-       GWN_vertbuf_use(verts);
-
-       for (uint a_idx = 0; a_idx < attr_len; ++a_idx) {
-               const Gwn_VertAttr* a = format->attribs + a_idx;
-               const GLvoid* pointer = (const GLubyte*)0 + a->offset + v_first * stride;
-
-               for (uint n_idx = 0; n_idx < a->name_len; ++n_idx) {
-                       const Gwn_ShaderInput* input = GWN_shaderinterface_attr(interface, a->name[n_idx]);
-
-                       if (input == NULL) continue;
-
-                       if (a->comp_len == 16 || a->comp_len == 12 || a->comp_len == 8) {
-#if TRUST_NO_ONE
-                               assert(a->fetch_mode == GWN_FETCH_FLOAT);
-                               assert(a->gl_comp_type == GL_FLOAT);
-#endif
-                               for (int i = 0; i < a->comp_len / 4; ++i) {
-                                       glEnableVertexAttribArray(input->location + i);
-                                       glVertexAttribDivisor(input->location + i, (use_instancing) ? 1 : 0);
-                                       glVertexAttribPointer(input->location + i, 4, a->gl_comp_type, GL_FALSE, stride,
-                                                             (const GLubyte*)pointer + i * 16);
-                               }
-                       }
-                       else
-                               {
-                               glEnableVertexAttribArray(input->location);
-                               glVertexAttribDivisor(input->location, (use_instancing) ? 1 : 0);
-
-                               switch (a->fetch_mode) {
-                                       case GWN_FETCH_FLOAT:
-                                       case GWN_FETCH_INT_TO_FLOAT:
-                                               glVertexAttribPointer(input->location, a->comp_len, a->gl_comp_type, GL_FALSE, stride, pointer);
-                                               break;
-                                       case GWN_FETCH_INT_TO_FLOAT_UNIT:
-                                               glVertexAttribPointer(input->location, a->comp_len, a->gl_comp_type, GL_TRUE, stride, pointer);
-                                               break;
-                                       case GWN_FETCH_INT:
-                                               glVertexAttribIPointer(input->location, a->comp_len, a->gl_comp_type, stride, pointer);
-                                               break;
-                               }
-                       }
-               }
-       }
-}
-
-static void batch_update_program_bindings(Gwn_Batch* batch, uint v_first)
-{
-       for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN && batch->verts[v] != NULL; ++v) {
-               create_bindings(batch->verts[v], batch->interface, (batch->inst) ? 0 : v_first, false);
-       }
-       if (batch->inst) {
-               create_bindings(batch->inst, batch->interface, v_first, true);
-       }
-       if (batch->elem) {
-               GWN_indexbuf_use(batch->elem);
-       }
-}
-
-void GWN_batch_program_use_begin(Gwn_Batch* batch)
-{
-       /* NOTE: use_program & done_using_program are fragile, depend on staying in sync with
-        *       the GL context's active program. use_program doesn't mark other programs as "not used". */
-       /* TODO: make not fragile (somehow) */
-
-       if (!batch->program_in_use) {
-               glUseProgram(batch->program);
-               batch->program_in_use = true;
-       }
-}
-
-void GWN_batch_program_use_end(Gwn_Batch* batch)
-{
-       if (batch->program_in_use) {
-#if PROGRAM_NO_OPTI
-               glUseProgram(0);
-#endif
-               batch->program_in_use = false;
-       }
-}
-
-#if TRUST_NO_ONE
-  #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(batch->interface, name); assert(uniform);
-#else
-  #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(batch->interface, name);
-#endif
-
-void GWN_batch_uniform_1ui(Gwn_Batch* batch, const char* name, int value)
-{
-       GET_UNIFORM
-       glUniform1ui(uniform->location, value);
-}
-
-void GWN_batch_uniform_1i(Gwn_Batch* batch, const char* name, int value)
-{
-       GET_UNIFORM
-       glUniform1i(uniform->location, value);
-}
-
-void GWN_batch_uniform_1b(Gwn_Batch* batch, const char* name, bool value)
-{
-       GET_UNIFORM
-       glUniform1i(uniform->location, value ? GL_TRUE : GL_FALSE);
-}
-
-void GWN_batch_uniform_2f(Gwn_Batch* batch, const char* name, float x, float y)
-{
-       GET_UNIFORM
-       glUniform2f(uniform->location, x, y);
-}
-
-void GWN_batch_uniform_3f(Gwn_Batch* batch, const char* name, float x, float y, float z)
-{
-       GET_UNIFORM
-       glUniform3f(uniform->location, x, y, z);
-}
-
-void GWN_batch_uniform_4f(Gwn_Batch* batch, const char* name, float x, float y, float z, float w)
-{
-       GET_UNIFORM
-       glUniform4f(uniform->location, x, y, z, w);
-}
-
-void GWN_batch_uniform_1f(Gwn_Batch* batch, const char* name, float x)
-{
-       GET_UNIFORM
-       glUniform1f(uniform->location, x);
-}
-
-void GWN_batch_uniform_2fv(Gwn_Batch* batch, const char* name, const float data[2])
-{
-       GET_UNIFORM
-       glUniform2fv(uniform->location, 1, data);
-}
-
-void GWN_batch_uniform_3fv(Gwn_Batch* batch, const char* name, const float data[3])
-{
-       GET_UNIFORM
-       glUniform3fv(uniform->location, 1, data);
-}
-
-void GWN_batch_uniform_4fv(Gwn_Batch* batch, const char* name, const float data[4])
-{
-       GET_UNIFORM
-       glUniform4fv(uniform->location, 1, data);
-}
-
-void GWN_batch_uniform_2fv_array(Gwn_Batch* batch, const char* name, const int len, const float *data)
-{
-       GET_UNIFORM
-       glUniform2fv(uniform->location, len, data);
-}
-
-void GWN_batch_uniform_4fv_array(Gwn_Batch* batch, const char* name, const int len, const float *data)
-{
-       GET_UNIFORM
-       glUniform4fv(uniform->location, len, data);
-}
-
-void GWN_batch_uniform_mat4(Gwn_Batch* batch, const char* name, const float data[4][4])
-{
-       GET_UNIFORM
-       glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (const float *)data);
-}
-
-static void primitive_restart_enable(const Gwn_IndexBuf *el)
-{
-       // TODO(fclem) Replace by GL_PRIMITIVE_RESTART_FIXED_INDEX when we have ogl 4.3
-       glEnable(GL_PRIMITIVE_RESTART);
-       GLuint restart_index = (GLuint)0xFFFFFFFF;
-
-#if GWN_TRACK_INDEX_RANGE
-       if (el->index_type == GWN_INDEX_U8)
-               restart_index = (GLuint)0xFF;
-       else if (el->index_type == GWN_INDEX_U16)
-               restart_index = (GLuint)0xFFFF;
-#endif
-
-       glPrimitiveRestartIndex(restart_index);
-}
-
-static void primitive_restart_disable(void)
-{
-       glDisable(GL_PRIMITIVE_RESTART);
-}
-
-void GWN_batch_draw(Gwn_Batch* batch)
-{
-#if TRUST_NO_ONE
-       assert(batch->phase == GWN_BATCH_READY_TO_DRAW);
-       assert(batch->verts[0]->vbo_id != 0);
-#endif
-       GWN_batch_program_use_begin(batch);
-       GPU_matrix_bind(batch->interface); // external call.
-
-       GWN_batch_draw_range_ex(batch, 0, 0, false);
-
-       GWN_batch_program_use_end(batch);
-}
-
-void GWN_batch_draw_range_ex(Gwn_Batch* batch, int v_first, int v_count, bool force_instance)
-{
-#if TRUST_NO_ONE
-       assert(!(force_instance && (batch->inst == NULL)) || v_count > 0); // we cannot infer length if force_instance
-#endif
-       const bool do_instance = (force_instance || batch->inst);
-
-       // If using offset drawing, use the default VAO and redo bindings.
-       if (v_first != 0 && (do_instance || batch->elem)) {
-               glBindVertexArray(GWN_vao_default());
-               batch_update_program_bindings(batch, v_first);
-       }
-       else {
-               glBindVertexArray(batch->vao_id);
-       }
-
-       if (do_instance) {
-               /* Infer length if vertex count is not given */
-               if (v_count == 0) {
-                       v_count = batch->inst->vertex_len;
-               }
-
-               if (batch->elem) {
-                       const Gwn_IndexBuf* el = batch->elem;
-
-                       if (el->use_prim_restart) {
-                               primitive_restart_enable(el);
-                       }
-#if GWN_TRACK_INDEX_RANGE
-                       glDrawElementsInstancedBaseVertex(batch->gl_prim_type,
-                                                         el->index_len,
-                                                         el->gl_index_type,
-                                                         0,
-                                                         v_count,
-                                                         el->base_index);
-#else
-                       glDrawElementsInstanced(batch->gl_prim_type, el->index_len, GL_UNSIGNED_INT, 0, v_count);
-#endif
-                       if (el->use_prim_restart) {
-                               primitive_restart_disable();
-                       }
-               }
-               else {
-                       glDrawArraysInstanced(batch->gl_prim_type, 0, batch->verts[0]->vertex_len, v_count);
-               }
-       }
-       else {
-               /* Infer length if vertex count is not given */
-               if (v_count == 0) {
-                       v_count = (batch->elem) ? batch->elem->index_len : batch->verts[0]->vertex_len;
-               }
-
-               if (batch->elem) {
-                       const Gwn_IndexBuf* el = batch->elem;
-
-                       if (el->use_prim_restart) {
-                               primitive_restart_enable(el);
-                       }
-
-#if GWN_TRACK_INDEX_RANGE
-                       if (el->base_index) {
-                               glDrawRangeElementsBaseVertex(batch->gl_prim_type,
-                                                             el->min_index,
-                                                             el->max_index,
-                                                             v_count,
-                                                             el->gl_index_type,
-                                                             0,
-                                                             el->base_index);
-                       }
-                       else {
-                               glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, 0);
-                       }
-#else
-                       glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, 0);
-#endif
-                       if (el->use_prim_restart) {
-                               primitive_restart_disable();
-                       }
-               }
-               else {
-                       glDrawArrays(batch->gl_prim_type, v_first, v_count);
-               }
-       }
-
-       /* Performance hog if you are drawing with the same vao multiple time.
-        * Only activate for debugging. */
-       // glBindVertexArray(0);
-}
-
-/* just draw some vertices and let shader place them where we want. */
-void GWN_draw_primitive(Gwn_PrimType prim_type, int v_count)
-       {
-       /* we cannot draw without vao ... annoying ... */
-       glBindVertexArray(GWN_vao_default());
-
-       GLenum type = convert_prim_type_to_gl(prim_type);
-       glDrawArrays(type, 0, v_count);
-
-       /* Performance hog if you are drawing with the same vao multiple time.
-        * Only activate for debugging.*/
-       // glBindVertexArray(0);
-       }
diff --git a/intern/gawain/src/gwn_imm_util.c b/intern/gawain/src/gwn_imm_util.c
deleted file mode 100644 (file)
index cdf55c3..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 by Mike Erwin.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/intern/gwn_imm_util.c
- *  \ingroup gpu
- *
- * Gawain immediate mode drawing utilities
- */
-
-#include "gwn_imm_util.h"
-#include "gwn_immediate.h"
-#include <stdlib.h>
-
-void immRectf(uint pos, float x1, float y1, float x2, float y2)
-{
-       immBegin(GWN_PRIM_TRI_FAN, 4);
-       immVertex2f(pos, x1, y1);
-       immVertex2f(pos, x2, y1);
-       immVertex2f(pos, x2, y2);
-       immVertex2f(pos, x1, y2);
-       immEnd();
-}
-
-void immRecti(uint pos, int x1, int y1, int x2, int y2)
-{
-       immBegin(GWN_PRIM_TRI_FAN, 4);
-       immVertex2i(pos, x1, y1);
-       immVertex2i(pos, x2, y1);
-       immVertex2i(pos, x2, y2);
-       immVertex2i(pos, x1, y2);
-       immEnd();
-}
-
-void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4])
-{
-       immAttrib4fv(col, color);
-       immVertex2f(pos, x1, y1);
-       immAttrib4fv(col, color);
-       immVertex2f(pos, x2, y1);
-       immAttrib4fv(col, color);
-       immVertex2f(pos, x2, y2);
-
-       immAttrib4fv(col, color);
-       immVertex2f(pos, x1, y1);
-       immAttrib4fv(col, color);
-       immVertex2f(pos, x2, y2);
-       immAttrib4fv(col, color);
-       immVertex2f(pos, x1, y2);
-}
-
-void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4])
-{
-       immAttrib4fv(col, color);
-       immVertex2i(pos, x1, y1);
-       immAttrib4fv(col, color);
-       immVertex2i(pos, x2, y1);
-       immAttrib4fv(col, color);
-       immVertex2i(pos, x2, y2);
-
-       immAttrib4fv(col, color);
-       immVertex2i(pos, x1, y1);
-       immAttrib4fv(col, color);
-       immVertex2i(pos, x2, y2);
-       immAttrib4fv(col, color);
-       immVertex2i(pos, x1, y2);
-}
-
-#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])
-{
-       Gwn_VertFormat *format = immVertexFormat();
-       uint pos = add_attrib(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
-       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-       immUniformColor4fv(color);
-       immRecti(pos, x1, y1, x2, y2);
-       immUnbindProgram();
-}
-#endif
diff --git a/intern/gawain/src/gwn_immediate.c b/intern/gawain/src/gwn_immediate.c
deleted file mode 100644 (file)
index 442aa85..0000000
+++ /dev/null
@@ -1,863 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * 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 by Mike Erwin.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/intern/gwn_immediate.c
- *  \ingroup gpu
- *
- * Gawain immediate mode work-alike
- */
-
-#include "gwn_immediate.h"
-#include "gwn_buffer_id.h"
-#include "gwn_attr_binding.h"
-#include "gwn_attr_binding_private.h"
-#include "gwn_vertex_format_private.h"
-#include "gwn_vertex_array_id.h"
-#include "gwn_primitive_private.h"
-#include <string.h>
-#include <stdlib.h>
-
-/* necessary functions from matrix API */
-extern void GPU_matrix_bind(const Gwn_ShaderInterface*);
-extern bool GPU_matrix_dirty_get(void);
-
-typedef struct {
-       /* TODO: organize this struct by frequency of change (run-time) */
-
-       Gwn_Batch* batch;
-       Gwn_Context* context;
-
-       /* current draw call */
-       GLubyte* buffer_data;
-       uint buffer_offset;
-       uint buffer_bytes_mapped;
-       uint vertex_len;
-       bool strict_vertex_len;
-       Gwn_PrimType prim_type;
-
-       Gwn_VertFormat vertex_format;
-
-       /* current vertex */
-       uint vertex_idx;
-       GLubyte* vertex_data;
-       uint16_t unassigned_attrib_bits; /* which attributes of current vertex have not been given values? */
-
-       GLuint vbo_id;
-       GLuint vao_id;
-
-       GLuint bound_program;
-       const Gwn_ShaderInterface* shader_interface;
-       Gwn_AttrBinding attrib_binding;
-       uint16_t prev_enabled_attrib_bits; /* <-- only affects this VAO, so we're ok */
-} Immediate;
-
-/* size of internal buffer -- make this adjustable? */
-#define IMM_BUFFER_SIZE (4 * 1024 * 1024)
-
-static bool initialized = false;
-static Immediate imm;
-
-void immInit(void)
-{
-#if TRUST_NO_ONE
-       assert(!initialized);
-#endif
-       memset(&imm, 0, sizeof(Immediate));
-
-       imm.vbo_id = GWN_buf_id_alloc();
-       glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id);
-       glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW);
-
-       imm.prim_type = GWN_PRIM_NONE;
-       imm.strict_vertex_len = true;
-
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-       initialized = true;
-}
-
-void immActivate(void)
-{
-#if TRUST_NO_ONE
-       assert(initialized);
-       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we're not between a Begin/End pair */
-       assert(imm.vao_id == 0);
-#endif
-       imm.vao_id = GWN_vao_alloc();
-       imm.context = GWN_context_active_get();
-}
-
-void immDeactivate(void)
-{
-#if TRUST_NO_ONE
-       assert(initialized);
-       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we're not between a Begin/End pair */
-       assert(imm.vao_id != 0);
-#endif
-       GWN_vao_free(imm.vao_id, imm.context);
-       imm.vao_id = 0;
-       imm.prev_enabled_attrib_bits = 0;
-}
-
-void immDestroy(void)
-{
-       GWN_buf_id_free(imm.vbo_id);
-       initialized = false;
-}
-
-Gwn_VertFormat* immVertexFormat(void)
-{
-       GWN_vertformat_clear(&imm.vertex_format);
-       return &imm.vertex_format;
-}
-
-void immBindProgram(GLuint program, const Gwn_ShaderInterface* shaderface)
-{
-#if TRUST_NO_ONE
-       assert(imm.bound_program == 0);
-       assert(glIsProgram(program));
-#endif
-
-       imm.bound_program = program;
-       imm.shader_interface = shaderface;
-
-       if (!imm.vertex_format.packed)
-               VertexFormat_pack(&imm.vertex_format);
-
-       glUseProgram(program);
-       get_attrib_locations(&imm.vertex_format, &imm.attrib_binding, shaderface);
-       GPU_matrix_bind(shaderface);
-}
-
-void immUnbindProgram(void)
-{
-#if TRUST_NO_ONE
-       assert(imm.bound_program != 0);
-#endif
-#if PROGRAM_NO_OPTI
-       glUseProgram(0);
-#endif
-       imm.bound_program = 0;
-}
-
-#if TRUST_NO_ONE
-static bool vertex_count_makes_sense_for_primitive(uint vertex_len, Gwn_PrimType prim_type)
-{
-       /* does vertex_len make sense for this primitive type? */
-       if (vertex_len == 0) {
-               return false;
-       }
-
-       switch (prim_type) {
-               case GWN_PRIM_POINTS:
-                       return true;
-               case GWN_PRIM_LINES:
-                       return vertex_len % 2 == 0;
-               case GWN_PRIM_LINE_STRIP:
-               case GWN_PRIM_LINE_LOOP:
-                       return vertex_len >= 2;
-               case GWN_PRIM_LINE_STRIP_ADJ:
-                       return vertex_len >= 4;
-               case GWN_PRIM_TRIS:
-                       return vertex_len % 3 == 0;
-               case GWN_PRIM_TRI_STRIP:
-               case GWN_PRIM_TRI_FAN:
-                       return vertex_len >= 3;
-               default:
-                       return false;
-       }
-}
-#endif
-
-void immBegin(Gwn_PrimType prim_type, uint vertex_len)
-{
-#if TRUST_NO_ONE
-       assert(initialized);
-       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we haven't already begun */
-       assert(vertex_count_makes_sense_for_primitive(vertex_len, prim_type));
-#endif
-       imm.prim_type = prim_type;
-       imm.vertex_len = vertex_len;
-       imm.vertex_idx = 0;
-       imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
-
-       /* how many bytes do we need for this draw call? */
-       const uint bytes_needed = vertex_buffer_size(&imm.vertex_format, vertex_len);
-
-#if TRUST_NO_ONE
-       assert(bytes_needed <= IMM_BUFFER_SIZE);
-#endif
-
-       glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id);
-
-       /* does the current buffer have enough room? */
-       const uint available_bytes = IMM_BUFFER_SIZE - imm.buffer_offset;
-       /* ensure vertex data is aligned */
-       const uint pre_padding = padding(imm.buffer_offset, imm.vertex_format.stride); /* might waste a little space, but it's safe */
-       if ((bytes_needed + pre_padding) <= available_bytes) {
-               imm.buffer_offset += pre_padding;
-       }
-       else {
-               /* orphan this buffer & start with a fresh one */
-               /* this method works on all platforms, old & new */
-               glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW);
-
-               imm.buffer_offset = 0;
-       }
-
-/*     printf("mapping %u to %u\n", imm.buffer_offset, imm.buffer_offset + bytes_needed - 1); */
-
-       imm.buffer_data = glMapBufferRange(GL_ARRAY_BUFFER, imm.buffer_offset, bytes_needed,
-                                          GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | (imm.strict_vertex_len ? 0 : GL_MAP_FLUSH_EXPLICIT_BIT));
-
-#if TRUST_NO_ONE
-       assert(imm.buffer_data != NULL);
-#endif
-
-       imm.buffer_bytes_mapped = bytes_needed;
-       imm.vertex_data = imm.buffer_data;
-}
-
-void immBeginAtMost(Gwn_PrimType prim_type, uint vertex_len)
-{
-#if TRUST_NO_ONE
-       assert(vertex_len > 0);
-#endif
-
-       imm.strict_vertex_len = false;
-       immBegin(prim_type, vertex_len);
-}
-
-
-Gwn_Batch* immBeginBatch(Gwn_PrimType prim_type, uint vertex_len)
-{
-#if TRUST_NO_ONE
-       assert(initialized);
-       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we haven't already begun */
-       assert(vertex_count_makes_sense_for_primitive(vertex_len, prim_type));
-#endif
-       imm.prim_type = prim_type;
-       imm.vertex_len = vertex_len;
-       imm.vertex_idx = 0;
-       imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
-
-       Gwn_VertBuf* verts = GWN_vertbuf_create_with_format(&imm.vertex_format);
-       GWN_vertbuf_data_alloc(verts, vertex_len);
-
-       imm.buffer_bytes_mapped = GWN_vertbuf_size_get(verts);
-       imm.vertex_data = verts->data;
-
-       imm.batch = GWN_batch_create_ex(prim_type, verts, NULL, GWN_BATCH_OWNS_VBO);
-       imm.batch->phase = GWN_BATCH_BUILDING;
-
-       return imm.batch;
-}
-
-Gwn_Batch* immBeginBatchAtMost(Gwn_PrimType prim_type, uint vertex_len)
-{
-       imm.strict_vertex_len = false;
-       return immBeginBatch(prim_type, vertex_len);
-}
-
-static void immDrawSetup(void)
-{
-       /* set up VAO -- can be done during Begin or End really */
-       glBindVertexArray(imm.vao_id);
-
-       /* enable/disable vertex attribs as needed */
-       if (imm.attrib_binding.enabled_bits != imm.prev_enabled_attrib_bits) {
-               for (uint loc = 0; loc < GWN_VERT_ATTR_MAX_LEN; ++loc) {
-                       bool is_enabled = imm.attrib_binding.enabled_bits & (1 << loc);
-                       bool was_enabled = imm.prev_enabled_attrib_bits & (1 << loc);
-
-                       if (is_enabled && !was_enabled) {
-                               glEnableVertexAttribArray(loc);
-                       }
-                       else if (was_enabled && !is_enabled) {
-                               glDisableVertexAttribArray(loc);
-                       }
-               }
-
-               imm.prev_enabled_attrib_bits = imm.attrib_binding.enabled_bits;
-       }
-
-       const uint stride = imm.vertex_format.stride;
-
-       for (uint a_idx = 0; a_idx < imm.vertex_format.attr_len; ++a_idx) {
-               const Gwn_VertAttr* a = imm.vertex_format.attribs + a_idx;
-
-               const uint offset = imm.buffer_offset + a->offset;
-               const GLvoid* pointer = (const GLubyte*)0 + offset;
-
-               const uint loc = read_attrib_location(&imm.attrib_binding, a_idx);
-
-               switch (a->fetch_mode) {
-                       case GWN_FETCH_FLOAT:
-                       case GWN_FETCH_INT_TO_FLOAT:
-                               glVertexAttribPointer(loc, a->comp_len, a->gl_comp_type, GL_FALSE, stride, pointer);
-                               break;
-                       case GWN_FETCH_INT_TO_FLOAT_UNIT:
-                               glVertexAttribPointer(loc, a->comp_len, a->gl_comp_type, GL_TRUE, stride, pointer);
-                               break;
-                       case GWN_FETCH_INT:
-                               glVertexAttribIPointer(loc, a->comp_len, a->gl_comp_type, stride, pointer);
-               }
-       }
-
-       if (GPU_matrix_dirty_get()) {
-               GPU_matrix_bind(imm.shader_interface);
-       }
-}
-
-void immEnd(void)
-{
-#if TRUST_NO_ONE
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-
-       uint buffer_bytes_used;
-       if (imm.strict_vertex_len) {
-#if TRUST_NO_ONE
-               assert(imm.vertex_idx == imm.vertex_len); /* with all vertices defined */
-#endif
-               buffer_bytes_used = imm.buffer_bytes_mapped;
-       }
-       else {
-#if TRUST_NO_ONE
-               assert(imm.vertex_idx <= imm.vertex_len);
-#endif
-               if (imm.vertex_idx == imm.vertex_len) {
-                       buffer_bytes_used = imm.buffer_bytes_mapped;
-               }
-               else {
-#if TRUST_NO_ONE
-                       assert(imm.vertex_idx == 0 || vertex_count_makes_sense_for_primitive(imm.vertex_idx, imm.prim_type));
-#endif
-                       imm.vertex_len = imm.vertex_idx;
-                       buffer_bytes_used = vertex_buffer_size(&imm.vertex_format, imm.vertex_len);
-                       /* unused buffer bytes are available to the next immBegin */
-               }
-               /* tell OpenGL what range was modified so it doesn't copy the whole mapped range */
-               glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, buffer_bytes_used);
-       }
-
-       if (imm.batch) {
-               if (buffer_bytes_used != imm.buffer_bytes_mapped) {
-                       GWN_vertbuf_data_resize(imm.batch->verts[0], imm.vertex_len);
-                       /* TODO: resize only if vertex count is much smaller */
-               }
-               GWN_batch_program_set(imm.batch, imm.bound_program, imm.shader_interface);
-               imm.batch->phase = GWN_BATCH_READY_TO_DRAW;
-               imm.batch = NULL; /* don't free, batch belongs to caller */
-       }
-       else {
-               glUnmapBuffer(GL_ARRAY_BUFFER);
-               if (imm.vertex_len > 0) {
-                       immDrawSetup();
-                       glDrawArrays(convert_prim_type_to_gl(imm.prim_type), 0, imm.vertex_len);
-               }
-               glBindBuffer(GL_ARRAY_BUFFER, 0);
-               glBindVertexArray(0);
-               /* prep for next immBegin */
-               imm.buffer_offset += buffer_bytes_used;
-       }
-
-       /* prep for next immBegin */
-       imm.prim_type = GWN_PRIM_NONE;
-       imm.strict_vertex_len = true;
-}
-
-static void setAttribValueBit(uint attrib_id)
-{
-       uint16_t mask = 1 << attrib_id;
-#if TRUST_NO_ONE
-       assert(imm.unassigned_attrib_bits & mask); /* not already set */
-#endif
-       imm.unassigned_attrib_bits &= ~mask;
-}
-
-
-/* --- generic attribute functions --- */
-
-void immAttrib1f(uint attrib_id, float x)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_F32);
-       assert(attrib->comp_len == 1);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       float* data = (float*)(imm.vertex_data + attrib->offset);
-/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
-
-       data[0] = x;
-}
-
-void immAttrib2f(uint attrib_id, float x, float y)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_F32);
-       assert(attrib->comp_len == 2);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       float* data = (float*)(imm.vertex_data + attrib->offset);
-/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
-
-       data[0] = x;
-       data[1] = y;
-}
-
-void immAttrib3f(uint attrib_id, float x, float y, float z)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_F32);
-       assert(attrib->comp_len == 3);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       float* data = (float*)(imm.vertex_data + attrib->offset);
-/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
-
-       data[0] = x;
-       data[1] = y;
-       data[2] = z;
-}
-
-void immAttrib4f(uint attrib_id, float x, float y, float z, float w)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_F32);
-       assert(attrib->comp_len == 4);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       float* data = (float*)(imm.vertex_data + attrib->offset);
-/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
-
-       data[0] = x;
-       data[1] = y;
-       data[2] = z;
-       data[3] = w;
-}
-
-void immAttrib1u(uint attrib_id, uint x)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_U32);
-       assert(attrib->comp_len == 1);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       uint* data = (uint*)(imm.vertex_data + attrib->offset);
-
-       data[0] = x;
-}
-
-void immAttrib2i(uint attrib_id, int x, int y)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_I32);
-       assert(attrib->comp_len == 2);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       int* data = (int*)(imm.vertex_data + attrib->offset);
-
-       data[0] = x;
-       data[1] = y;
-}
-
-void immAttrib2s(uint attrib_id, short x, short y)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_I16);
-       assert(attrib->comp_len == 2);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       short* data = (short*)(imm.vertex_data + attrib->offset);
-
-       data[0] = x;
-       data[1] = y;
-}
-
-void immAttrib2fv(uint attrib_id, const float data[2])
-{
-       immAttrib2f(attrib_id, data[0], data[1]);
-}
-
-void immAttrib3fv(uint attrib_id, const float data[3])
-{
-       immAttrib3f(attrib_id, data[0], data[1], data[2]);
-}
-
-void immAttrib4fv(uint attrib_id, const float data[4])
-{
-       immAttrib4f(attrib_id, data[0], data[1], data[2], data[3]);
-}
-
-void immAttrib3ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_U8);
-       assert(attrib->comp_len == 3);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       GLubyte* data = imm.vertex_data + attrib->offset;
-/*     printf("%s %td %p\n", __FUNCTION__, data - imm.buffer_data, data); */
-
-       data[0] = r;
-       data[1] = g;
-       data[2] = b;
-}
-
-void immAttrib4ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
-{
-       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(attrib->comp_type == GWN_COMP_U8);
-       assert(attrib->comp_len == 4);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-
-       GLubyte* data = imm.vertex_data + attrib->offset;
-/*     printf("%s %td %p\n", __FUNCTION__, data - imm.buffer_data, data); */
-
-       data[0] = r;
-       data[1] = g;
-       data[2] = b;
-       data[3] = a;
-}
-
-void immAttrib3ubv(uint attrib_id, const unsigned char data[3])
-{
-       immAttrib3ub(attrib_id, data[0], data[1], data[2]);
-}
-
-void immAttrib4ubv(uint attrib_id, const unsigned char data[4])
-{
-       immAttrib4ub(attrib_id, data[0], data[1], data[2], data[3]);
-}
-
-void immSkipAttrib(uint attrib_id)
-{
-#if TRUST_NO_ONE
-       assert(attrib_id < imm.vertex_format.attr_len);
-       assert(imm.vertex_idx < imm.vertex_len);
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-#endif
-       setAttribValueBit(attrib_id);
-}
-
-static void immEndVertex(void) /* and move on to the next vertex */
-{
-#if TRUST_NO_ONE
-       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
-       assert(imm.vertex_idx < imm.vertex_len);
-#endif
-
-       /* have all attribs been assigned values?
-        * if not, copy value from previous vertex */
-       if (imm.unassigned_attrib_bits) {
-#if TRUST_NO_ONE
-               assert(imm.vertex_idx > 0); /* first vertex must have all attribs specified */
-#endif
-               for (uint a_idx = 0; a_idx < imm.vertex_format.attr_len; ++a_idx) {
-                       if ((imm.unassigned_attrib_bits >> a_idx) & 1) {
-                               const Gwn_VertAttr* a = imm.vertex_format.attribs + a_idx;
-
-/*                             printf("copying %s from vertex %u to %u\n", a->name, imm.vertex_idx - 1, imm.vertex_idx); */
-
-                               GLubyte* data = imm.vertex_data + a->offset;
-                               memcpy(data, data - imm.vertex_format.stride, a->sz);
-                               /* TODO: consolidate copy of adjacent attributes */
-                       }
-               }
-       }
-
-       imm.vertex_idx++;
-       imm.vertex_data += imm.vertex_format.stride;
-       imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
-}
-
-void immVertex2f(uint attrib_id, float x, float y)
-{
-       immAttrib2f(attrib_id, x, y);
-       immEndVertex();
-}
-
-void immVertex3f(uint attrib_id, float x, float y, float z)
-{
-       immAttrib3f(attrib_id, x, y, z);
-       immEndVertex();
-}
-
-void immVertex4f(uint attrib_id, float x, float y, float z, float w)
-{
-       immAttrib4f(attrib_id, x, y, z, w);
-       immEndVertex();
-}
-
-void immVertex2i(uint attrib_id, int x, int y)
-{
-       immAttrib2i(attrib_id, x, y);
-       immEndVertex();
-}
-
-void immVertex2s(uint attrib_id, short x, short y)
-{
-       immAttrib2s(attrib_id, x, y);
-       immEndVertex();
-}
-
-void immVertex2fv(uint attrib_id, const float data[2])
-{
-       immAttrib2f(attrib_id, data[0], data[1]);
-       immEndVertex();
-}
-
-void immVertex3fv(uint attrib_id, const float data[3])
-{
-       immAttrib3f(attrib_id, data[0], data[1], data[2]);
-       immEndVertex();
-}
-
-void immVertex2iv(uint attrib_id, const int data[2])
-{
-       immAttrib2i(attrib_id, data[0], data[1]);
-       immEndVertex();
-}
-
-
-/* --- generic uniform functions --- */
-
-#if 0
-  #if TRUST_NO_ONE
-    #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); assert(uniform);
-  #else
-    #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name);
-  #endif
-#else
-       /* NOTE: It is possible to have uniform fully optimized out from the shader.
-        *       In this case we can't assert failure or allow NULL-pointer dereference.
-        * TODO(sergey): How can we detect existing-but-optimized-out uniform but still
-        *               catch typos in uniform names passed to immUniform*() functions? */
-  #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); if (uniform == NULL) return;
-#endif
-
-void immUniform1f(const char* name, float x)
-{
-       GET_UNIFORM
-       glUniform1f(uniform->location, x);
-}
-
-void immUniform2f(const char* name, float x, float y)
-{
-       GET_UNIFORM
-       glUniform2f(uniform->location, x, y);
-}
-
-void immUniform2fv(const char* name, const float data[2])
-{
-       GET_UNIFORM
-       glUniform2fv(uniform->location, 1, data);
-}
-
-void immUniform3f(const char* name, float x, float y, float z)
-{
-       GET_UNIFORM
-       glUniform3f(uniform->location, x, y, z);
-}
-
-void immUniform3fv(const char* name, const float data[3])
-{
-       GET_UNIFORM
-       glUniform3fv(uniform->location, 1, data);
-}
-
-/* can increase this limit or move to another file */
-#define MAX_UNIFORM_NAME_LEN 60
-
-void immUniformArray3fv(const char* bare_name, const float *data, int count)
-{
-       /* look up "name[0]" when given "name" */
-       const size_t len = strlen(bare_name);
-#if TRUST_NO_ONE
-       assert(len <= MAX_UNIFORM_NAME_LEN);
-#endif
-       char name[MAX_UNIFORM_NAME_LEN];
-       strcpy(name, bare_name);
-       name[len + 0] = '[';
-       name[len + 1] = '0';
-       name[len + 2] = ']';
-       name[len + 3] = '\0';
-
-       GET_UNIFORM
-       glUniform3fv(uniform->location, count, data);
-}
-
-void immUniform4f(const char* name, float x, float y, float z, float w)
-{
-       GET_UNIFORM
-       glUniform4f(uniform->location, x, y, z, w);
-}
-
-void immUniform4fv(const char* name, const float data[4])
-{
-       GET_UNIFORM
-       glUniform4fv(uniform->location, 1, data);
-}
-
-void immUniformArray4fv(const char* bare_name, const float *data, int count)
-{
-       /* look up "name[0]" when given "name" */
-       const size_t len = strlen(bare_name);
-#if TRUST_NO_ONE
-       assert(len <= MAX_UNIFORM_NAME_LEN);
-#endif
-       char name[MAX_UNIFORM_NAME_LEN];
-       strcpy(name, bare_name);
-       name[len + 0] = '[';
-       name[len + 1] = '0';
-       name[len + 2] = ']';
-       name[len + 3] = '\0';
-
-       GET_UNIFORM
-       glUniform4fv(uniform->location, count, data);
-}
-
-void immUniformMatrix4fv(const char* name, const float data[4][4])
-{
-       GET_UNIFORM
-       glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (float *)data);
-}
-
-void immUniform1i(const char* name, int x)
-{
-       GET_UNIFORM
-       glUniform1i(uniform->location, x);
-}
-
-void immUniform4iv(const char* name, const int data[4])
-{
-       GET_UNIFORM
-       glUniform4iv(uniform->location, 1, data);
-}
-
-/* --- convenience functions for setting "uniform vec4 color" --- */
-
-void immUniformColor4f(float r, float g, float b, float a)
-{
-       const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform_builtin(imm.shader_interface, GWN_UNIFORM_COLOR);
-#if TRUST_NO_ONE
-       assert(uniform != NULL);
-#endif
-       glUniform4f(uniform->location, r, g, b, a);
-}
-
-void immUniformColor4fv(const float rgba[4])
-{
-       immUniformColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
-}
-
-void immUniformColor3f(float r, float g, float b)
-{
-       immUniformColor4f(r, g, b, 1.0f);
-}
-
-void immUniformColor3fv(const float rgb[3])
-{
-       immUniformColor4f(rgb[0], rgb[1], rgb[2], 1.0f);
-}
-
-void immUniformColor3fvAlpha(const float rgb[3], float a)
-{
-       immUniformColor4f(rgb[0], rgb[1], rgb[2], a);
-}
-
-/* TODO: v-- treat as sRGB? --v */
-
-void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b)
-{
-       const float scale = 1.0f / 255.0f;
-       immUniformColor4f(scale * r, scale * g, scale * b, 1.0f);
-}
-
-void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
-{
-       const float scale = 1.0f / 255.0f;
-       immUniformColor4f(scale * r, scale * g, scale * b, scale * a);
-}
-
-void immUniformColor3ubv(const unsigned char rgb[3])
-{
-       immUniformColor3ub(rgb[0], rgb[1], rgb[2]);
-}
-
-void immUniformColor3ubvAlpha(const unsigned char rgb[3], unsigned char alpha)
-{
-       immUniformColor4ub(rgb[0], rgb[1], rgb[2], alpha);
-}
-
-void immUniformColor4ubv(const unsigned char rgba[4])
-{
-       immUniformColor4ub(rgba[0], rgba[1], rgba[2], rgba[3]);
-}
index 2611477252add9f62bd433791c9e055bf72719f5..10898e4239bbb57e99d1ed8b37795ac241a009d7 100644 (file)
@@ -27,8 +27,8 @@ set(INC
        .
        ../glew-mx
        ../guardedalloc
-       ../gawain
        ../../source/blender/blenlib
+       ../../source/blender/gpu
 )
 
 set(INC_SYS
index 090422ff79582a4359a6eff660a9eca390770cae..10acdb9d281c4a25bf41e8450df8a03f0505ba08 100644 (file)
@@ -49,7 +49,7 @@
 #endif
 
 extern "C" {
-#include "gawain/gwn_immediate.h"
+#include "GPU_immediate.h"
 }
 
 using namespace OCIO_NAMESPACE;
index 999773d021295fe13e615fba95c0d0fee67986c2..03bf7fa67d88064b24dc5f2fd7e44a563735139b 100644 (file)
@@ -31,7 +31,7 @@
 #ifndef __BLF_INTERNAL_TYPES_H__
 #define __BLF_INTERNAL_TYPES_H__
 
-#include "../../../intern/gawain/gawain/gwn_vertex_buffer.h"
+#include "GPU_vertex_buffer.h"
 #include "GPU_texture.h"
 
 #define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
index bf3ee34a03e25e2cf628aad259e31f5b916698cf..a6d11f1edacea394f7836a4986e7d1e1dc589f3a 100644 (file)
@@ -45,7 +45,7 @@
 #include "eevee_lightcache.h"
 #include "eevee_private.h"
 
-#include "../../../intern/gawain/gawain/gwn_context.h"
+#include "GPU_context.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
index 58ce9dd521827ab7f2f9de4bac7f91a1183db00d..4c6f8962d820da9ca7b6fab167b47200461e2ce4 100644 (file)
@@ -82,7 +82,7 @@
 #include "engines/workbench/workbench_engine.h"
 #include "engines/external/external_engine.h"
 
-#include "../../../intern/gawain/gawain/gwn_context.h"
+#include "GPU_context.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
index d25e372c26e94b199143f7c4522476ee5b3a2c80..2d44fb5b6d8dea7d4543b5d28f08793e6d959db8 100644 (file)
@@ -35,6 +35,7 @@
 #include "BLI_threads.h"
 
 #include "GPU_batch.h"
+#include "GPU_context.h"
 #include "GPU_framebuffer.h"
 #include "GPU_shader.h"
 #include "GPU_uniformbuffer.h"
index 716e00164cef292733d9d915dd62a817337b19c4..3d207b857600c1da796577ff6515393ae982e12d 100644 (file)
@@ -50,7 +50,6 @@ set(INC
        ../../../intern/glew-mx
        ../../../intern/guardedalloc
        ../../../intern/smoke/extern
-       ../../../intern/gawain
 )
 
 set(INC_SYS
@@ -58,14 +57,17 @@ set(INC_SYS
 )
 
 set(SRC
+       intern/gpu_attr_binding.c
        intern/gpu_basic_shader.c
        intern/gpu_batch.c
        intern/gpu_batch_presets.c
        intern/gpu_batch_utils.c
+       intern/gpu_buffer_id.cpp
        intern/gpu_buffers.c
        intern/gpu_codegen.c
        intern/gpu_debug.c
        intern/gpu_draw.c
+       intern/gpu_element.c
        intern/gpu_extensions.c
        intern/gpu_framebuffer.c
        intern/gpu_immediate.c
@@ -73,13 +75,18 @@ set(SRC
        intern/gpu_init_exit.c
        intern/gpu_material.c
        intern/gpu_matrix.c
+       intern/gpu_primitive.c
        intern/gpu_select.c
        intern/gpu_select_pick.c
        intern/gpu_select_sample_query.c
        intern/gpu_shader.c
+       intern/gpu_shader_interface.c
        intern/gpu_state.c
        intern/gpu_texture.c
        intern/gpu_uniformbuffer.c
+       intern/gpu_vertex_array_id.cpp
+       intern/gpu_vertex_buffer.c
+       intern/gpu_vertex_format.c
        intern/gpu_viewport.c
 
        shaders/gpu_shader_fx_lib.glsl
@@ -103,11 +110,15 @@ set(SRC
        shaders/gpu_shader_smoke_frag.glsl
        shaders/gpu_shader_smoke_vert.glsl
 
+       GPU_attr_binding.h
        GPU_basic_shader.h
        GPU_batch.h
+       GPU_buffer_id.h
        GPU_buffers.h
+       GPU_common.h
        GPU_debug.h
        GPU_draw.h
+       GPU_element.h
        GPU_extensions.h
        GPU_framebuffer.h
        GPU_glew.h
@@ -117,17 +128,26 @@ set(SRC
        GPU_legacy_stubs.h
        GPU_material.h
        GPU_matrix.h
+       GPU_primitive.h
        GPU_select.h
        GPU_shader.h
+       GPU_shader_interface.h
        GPU_state.h
        GPU_texture.h
        GPU_uniformbuffer.h
+       GPU_vertex_array_id.h
+       GPU_vertex_buffer.h
+       GPU_vertex_format.h
        GPU_viewport.h
 
+       intern/gpu_attr_binding_private.h
+       intern/gpu_batch_private.h
        intern/gpu_codegen.h
+       intern/gpu_primitive_private.h
        intern/gpu_private.h
        intern/gpu_select_private.h
        intern/gpu_shader_private.h
+       intern/gpu_vertex_format_private.h
 )
 
 data_to_c_simple(shaders/gpu_shader_depth_only_frag.glsl SRC)
similarity index 98%
rename from intern/gawain/gawain/gwn_attr_binding.h
rename to source/blender/gpu/GPU_attr_binding.h
index 8030e86ea9218f5ea540bcf790525ca9d3d3dbfb..41050a095cd9f3f0f0917468260b918ac393c11a 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __GWN_ATTR_BINDING_H__
 #define __GWN_ATTR_BINDING_H__
 
-#include "gwn_common.h"
+#include "GPU_common.h"
 
 typedef struct Gwn_AttrBinding {
        uint64_t loc_bits; /* store 4 bits for each of the 16 attribs */
index f73968eda54c2ce614d2547134cffbf8e0bc2420..4c98eb8f537a77c9bbe77d921c5c75a2e44c6fc6 100644 (file)
  * 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.
+ * The Original Code is Copyright (C) 2016 by Mike Erwin.
  * All rights reserved.
  *
- *
- * Contributor(s): Mike Erwin
+ * Contributor(s): Blender Foundation
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/* Batched geometry rendering is powered by the Gawain library.
- * This file contains any additions or modifications specific to Blender.
+/** \file blender/gpu/gwn_batch.h
+ *  \ingroup gpu
+ *
+ * Gawain geometry batch
+ * Contains VAOs + VBOs + Shader representing a drawable entity.
  */
 
-#ifndef __GPU_BATCH_H__
-#define __GPU_BATCH_H__
+#ifndef __GWN_BATCH_H__
+#define __GWN_BATCH_H__
 
-#include "../../../intern/gawain/gawain/gwn_batch.h"
-#include "../../../intern/gawain/gawain/gwn_batch_private.h"
+#include "GPU_vertex_buffer.h"
+#include "GPU_element.h"
+#include "GPU_shader_interface.h"
+#include "GPU_shader.h"
 
-// TODO: CMake magic to do this:
-// #include "gawain/batch.h"
+typedef enum {
+       GWN_BATCH_READY_TO_FORMAT,
+       GWN_BATCH_READY_TO_BUILD,
+       GWN_BATCH_BUILDING,
+       GWN_BATCH_READY_TO_DRAW
+} Gwn_BatchPhase;
 
-#include "BLI_compiler_attrs.h"
-#include "BLI_sys_types.h"
+#define GWN_BATCH_VBO_MAX_LEN 3
+#define GWN_BATCH_VAO_STATIC_LEN 3
+#define GWN_BATCH_VAO_DYN_ALLOC_COUNT 16
 
-#include "GPU_shader.h"
+typedef struct Gwn_Batch {
+       /* geometry */
+       Gwn_VertBuf* verts[GWN_BATCH_VBO_MAX_LEN]; /* verts[0] is required, others can be NULL */
+       Gwn_VertBuf* inst; /* instance attribs */
+       Gwn_IndexBuf* elem; /* NULL if element list not needed */
+       uint32_t gl_prim_type;
+
+       /* cached values (avoid dereferencing later) */
+       uint32_t vao_id;
+       uint32_t program;
+       const struct Gwn_ShaderInterface* interface;
+
+       /* book-keeping */
+       uint owns_flag;
+       struct Gwn_Context *context; /* used to free all vaos. this implies all vaos were created under the same context. */
+       Gwn_BatchPhase phase;
+       bool program_in_use;
+
+       /* Vao management: remembers all geometry state (vertex attrib bindings & element buffer)
+        * for each shader interface. Start with a static number of vaos and fallback to dynamic count
+        * if necessary. Once a batch goes dynamic it does not go back. */
+       bool is_dynamic_vao_count;
+       union {
+               /* Static handle count */
+               struct {
+                       const struct Gwn_ShaderInterface* interfaces[GWN_BATCH_VAO_STATIC_LEN];
+                       uint32_t vao_ids[GWN_BATCH_VAO_STATIC_LEN];
+               } static_vaos;
+               /* Dynamic handle count */
+               struct {
+                       uint count;
+                       const struct Gwn_ShaderInterface** interfaces;
+                       uint32_t* vao_ids;
+               } dynamic_vaos;
+       };
+
+       /* XXX This is the only solution if we want to have some data structure using
+        * batches as key to identify nodes. We must destroy these nodes with this callback. */
+       void (*free_callback)(struct Gwn_Batch*, void*);
+       void* callback_data;
+} Gwn_Batch;
+
+enum {
+       GWN_BATCH_OWNS_VBO = (1 << 0),
+       /* each vbo index gets bit-shifted */
+       GWN_BATCH_OWNS_INSTANCES = (1 << 30),
+       GWN_BATCH_OWNS_INDEX = (1 << 31),
+};
+
+Gwn_Batch* GWN_batch_create_ex(Gwn_PrimType, Gwn_VertBuf*, Gwn_IndexBuf*, uint owns_flag);
+void GWN_batch_init_ex(Gwn_Batch*, Gwn_PrimType, Gwn_VertBuf*, Gwn_IndexBuf*, uint owns_flag);
+Gwn_Batch* GWN_batch_duplicate(Gwn_Batch* batch_src);
+
+#define GWN_batch_create(prim, verts, elem) \
+       GWN_batch_create_ex(prim, verts, elem, 0)
+#define GWN_batch_init(batch, prim, verts, elem) \
+       GWN_batch_init_ex(batch, prim, verts, elem, 0)
+
+void GWN_batch_discard(Gwn_Batch*); /* verts & elem are not discarded */
+
+void gwn_batch_vao_cache_clear(Gwn_Batch*);
+
+void GWN_batch_callback_free_set(Gwn_Batch*, void (*callback)(Gwn_Batch*, void*), void*);
+
+void GWN_batch_instbuf_set(Gwn_Batch*, Gwn_VertBuf*, bool own_vbo); /* Instancing */
+
+int GWN_batch_vertbuf_add_ex(Gwn_Batch*, Gwn_VertBuf*, bool own_vbo);
+
+#define GWN_batch_vertbuf_add(batch, verts) \
+       GWN_batch_vertbuf_add_ex(batch, verts, false)
 
-/* gpu_batch.c */
-void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id) ATTR_NONNULL(1);
+void GWN_batch_program_set_no_use(Gwn_Batch*, uint32_t program, const Gwn_ShaderInterface*);
+void GWN_batch_program_set(Gwn_Batch*, uint32_t program, const Gwn_ShaderInterface*);
+void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id);
+/* Entire batch draws with one shader program, but can be redrawn later with another program. */
+/* Vertex shader's inputs must be compatible with the batch's vertex format. */
+
+void GWN_batch_program_use_begin(Gwn_Batch*); /* call before Batch_Uniform (temp hack?) */
+void GWN_batch_program_use_end(Gwn_Batch*);
+
+void GWN_batch_uniform_1ui(Gwn_Batch*, const char* name, int value);
+void GWN_batch_uniform_1i(Gwn_Batch*, const char* name, int value);
+void GWN_batch_uniform_1b(Gwn_Batch*, const char* name, bool value);
+void GWN_batch_uniform_1f(Gwn_Batch*, const char* name, float value);
+void GWN_batch_uniform_2f(Gwn_Batch*, const char* name, float x, float y);
+void GWN_batch_uniform_3f(Gwn_Batch*, const char* name, float x, float y, float z);
+void GWN_batch_uniform_4f(Gwn_Batch*, const char* name, float x, float y, float z, float w);
+void GWN_batch_uniform_2fv(Gwn_Batch*, const char* name, const float data[2]);
+void GWN_batch_uniform_3fv(Gwn_Batch*, const char* name, const float data[3]);
+void GWN_batch_uniform_4fv(Gwn_Batch*, const char* name, const float data[4]);
+void GWN_batch_uniform_2fv_array(Gwn_Batch*, const char* name, int len, const float *data);
+void GWN_batch_uniform_4fv_array(Gwn_Batch*, const char* name, int len, const float *data);
+void GWN_batch_uniform_mat4(Gwn_Batch*, const char* name, const float data[4][4]);
+
+void GWN_batch_draw(Gwn_Batch*);
+
+/* This does not bind/unbind shader and does not call GPU_matrix_bind() */
+void GWN_batch_draw_range_ex(Gwn_Batch*, int v_first, int v_count, bool force_instance);
+
+/* Does not even need batch */
+void GWN_draw_primitive(Gwn_PrimType, int v_count);
+
+#if 0 /* future plans */
+
+/* Can multiple batches share a Gwn_VertBuf? Use ref count? */
+
+
+/* We often need a batch with its own data, to be created and discarded together. */
+/* WithOwn variants reduce number of system allocations. */
+
+typedef struct BatchWithOwnVertexBuffer {
+       Gwn_Batch batch;
+       Gwn_VertBuf verts; /* link batch.verts to this */
+} BatchWithOwnVertexBuffer;
+
+typedef struct BatchWithOwnElementList {
+       Gwn_Batch batch;
+       Gwn_IndexBuf elem; /* link batch.elem to this */
+} BatchWithOwnElementList;
+
+typedef struct BatchWithOwnVertexBufferAndElementList {
+       Gwn_Batch batch;
+       Gwn_IndexBuf elem; /* link batch.elem to this */
+       Gwn_VertBuf verts; /* link batch.verts to this */
+} BatchWithOwnVertexBufferAndElementList;
+
+Gwn_Batch* create_BatchWithOwnVertexBuffer(Gwn_PrimType, Gwn_VertFormat*, uint v_len, Gwn_IndexBuf*);
+Gwn_Batch* create_BatchWithOwnElementList(Gwn_PrimType, Gwn_VertBuf*, uint prim_len);
+Gwn_Batch* create_BatchWithOwnVertexBufferAndElementList(Gwn_PrimType, Gwn_VertFormat*, uint v_len, uint prim_len);
+/* verts: shared, own */
+/* elem: none, shared, own */
+Gwn_Batch* create_BatchInGeneral(Gwn_PrimType, VertexBufferStuff, ElementListStuff);
+
+#endif /* future plans */
 
 void gpu_batch_init(void);
 void gpu_batch_exit(void);
 
-#endif  /* __GPU_BATCH_H__ */
+/* Macros */
+
+#define GWN_BATCH_DISCARD_SAFE(batch) do { \
+       if (batch != NULL) { \
+               GWN_batch_discard(batch); \
+               batch = NULL; \
+       } \
+} while (0)
+
+#endif /* __GWN_BATCH_H__ */
similarity index 98%
rename from intern/gawain/gawain/gwn_buffer_id.h
rename to source/blender/gpu/GPU_buffer_id.h
index 0c2537a5d5a375a7f53ac01d528c322757ca94df..fd680ff31f5637363b34d9db605f2b89ae19cd44 100644 (file)
@@ -41,7 +41,7 @@
 extern "C" {
 #endif
 
-#include "gwn_common.h"
+#include "GPU_common.h"
 
 GLuint GWN_buf_id_alloc(void);
 void GWN_buf_id_free(GLuint buffer_id);
similarity index 94%
rename from intern/gawain/gawain/gwn_context.h
rename to source/blender/gpu/GPU_context.h
index 7784fc30562d3dd10191505a15284df80018f528..0cedc109645c7696d2c77652b2f823bddee0d865 100644 (file)
@@ -36,9 +36,9 @@
 extern "C" {
 #endif
 
-#include "gwn_common.h"
-#include "gwn_batch.h"
-#include "gwn_shader_interface.h"
+#include "GPU_common.h"
+#include "GPU_batch.h"
+#include "GPU_shader_interface.h"
 
 typedef struct Gwn_Context Gwn_Context;
 
similarity index 99%
rename from intern/gawain/gawain/gwn_element.h
rename to source/blender/gpu/GPU_element.h
index 2d5b6bb692b412f566224bea5cc77e9459323422..0c23e90569b288ae50e994bedc928fd001389703 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __GWN_ELEMENT_H__
 #define __GWN_ELEMENT_H__
 
-#include "gwn_primitive.h"
+#include "GPU_primitive.h"
 
 #define GWN_TRACK_INDEX_RANGE 1
 
index 2a2692e6baf67e5db09a87fbcf54d5dfae03fe71..c589288682593e6d40a94ea6af5e8edc3c7d1d77 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/* Immediate mode rendering is powered by the Gawain library.
- * This file contains any additions or modifications specific to Blender.
+/** \file blender/gpu/GPU_immediate.h
+ *  \ingroup gpu
+ *
+ * Gawain immediate mode work-alike
  */
 
 #ifndef __GPU_IMMEDIATE_H__
 #define __GPU_IMMEDIATE_H__
 
-#include "../../../intern/gawain/gawain/gwn_immediate.h"
-#include "../../../intern/gawain/gawain/gwn_imm_util.h"
+#include "GPU_vertex_format.h"
+#include "GPU_primitive.h"
+#include "GPU_shader_interface.h"
+#include "GPU_batch.h"
+#include "GPU_immediate_util.h"
+#include "GPU_shader.h"
 
-// TODO: CMake magic to do this:
-// #include "gawain/gwn_immediate.h"
-// #include "gawain/gwn_imm_util.h"
+Gwn_VertFormat* immVertexFormat(void); /* returns a cleared vertex format, ready for add_attrib. */
 
-#include "GPU_shader.h"
+void immBindProgram(uint32_t program, const Gwn_ShaderInterface*); /* every immBegin must have a program bound first. */
+void immUnbindProgram(void); /* call after your last immEnd, or before binding another program. */
+
+void immBegin(Gwn_PrimType, uint vertex_len); /* must supply exactly vertex_len vertices. */
+void immBeginAtMost(Gwn_PrimType, uint max_vertex_len); /* can supply fewer vertices. */
+void immEnd(void); /* finishes and draws. */
+
+/* ImmBegin a batch, then use standard immFunctions as usual. */
+/* ImmEnd will finalize the batch instead of drawing. */
+/* Then you can draw it as many times as you like! Partially replaces the need for display lists. */
+Gwn_Batch* immBeginBatch(Gwn_PrimType, uint vertex_len);
+Gwn_Batch* immBeginBatchAtMost(Gwn_PrimType, uint vertex_len);
+
+/* Provide attribute values that can change per vertex. */
+/* First vertex after immBegin must have all its attributes specified. */
+/* Skipped attributes will continue using the previous value for that attrib_id. */
+void immAttrib1f(uint attrib_id, float x);
+void immAttrib2f(uint attrib_id, float x, float y);
+void immAttrib3f(uint attrib_id, float x, float y, float z);
+void immAttrib4f(uint attrib_id, float x, float y, float z, float w);
+
+void immAttrib2i(uint attrib_id, int x, int y);
+
+void immAttrib1u(uint attrib_id, uint x);
+
+void immAttrib2s(uint attrib_id, short x, short y);
+
+void immAttrib2fv(uint attrib_id, const float data[2]);
+void immAttrib3fv(uint attrib_id, const float data[3]);
+void immAttrib4fv(uint attrib_id, const float data[4]);
+
+void immAttrib3ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b);
+void immAttrib4ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
+
+void immAttrib3ubv(uint attrib_id, const unsigned char data[4]);
+void immAttrib4ubv(uint attrib_id, const unsigned char data[4]);
+
+/* Explicitly skip an attribute. */
+/* This advanced option kills automatic value copying for this attrib_id. */
+void immSkipAttrib(uint attrib_id);
+
+/* Provide one last attribute value & end the current vertex. */
+/* This is most often used for 2D or 3D position (similar to glVertex). */
+void immVertex2f(uint attrib_id, float x, float y);
+void immVertex3f(uint attrib_id, float x, float y, float z);
+void immVertex4f(uint attrib_id, float x, float y, float z, float w);
+
+void immVertex2i(uint attrib_id, int x, int y);
+
+void immVertex2s(uint attrib_id, short x, short y);
+
+void immVertex2fv(uint attrib_id, const float data[2]);
+void immVertex3fv(uint attrib_id, const float data[3]);
+
+void immVertex2iv(uint attrib_id, const int data[2]);
+
+/* Provide uniform values that don't change for the entire draw call. */
+void immUniform1i(const char* name, int x);
+void immUniform4iv(const char* name, const int data[4]);
+void immUniform1f(const char* name, float x);
+void immUniform2f(const char* name, float x, float y);
+void immUniform2fv(const char* name, const float data[2]);
+void immUniform3f(const char* name, float x, float y, float z);
+void immUniform3fv(const char* name, const float data[3]);
+void immUniformArray3fv(const char* name, const float *data, int count);
+void immUniform4f(const char* name, float x, float y, float z, float w);
+void immUniform4fv(const char* name, const float data[4]);
+void immUniformArray4fv(const char* bare_name, const float *data, int count);
+void immUniformMatrix4fv(const char* name, const float data[4][4]);
+
+/* Convenience functions for setting "uniform vec4 color". */
+/* The rgb functions have implicit alpha = 1.0. */
+void immUniformColor4f(float r, float g, float b, float a);
+void immUniformColor4fv(const float rgba[4]);
+void immUniformColor3f(float r, float g, float b);
+void immUniformColor3fv(const float rgb[3]);
+void immUniformColor3fvAlpha(const float rgb[3], float a);
+
+void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b);
+void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
+void immUniformColor3ubv(const unsigned char rgb[3]);
+void immUniformColor3ubvAlpha(const unsigned char rgb[3], unsigned char a);
+void immUniformColor4ubv(const unsigned char rgba[4]);
 
 /* Extend immBindProgram to use Blender’s library of built-in shader programs.
  * Use immUnbindProgram() when done. */
 void immBindBuiltinProgram(GPUBuiltinShader shader_id);
 
-/*
- * Extend immUniformColor to take Blender's themes
- */
+/* Extend immUniformColor to take Blender's themes */
 void immUniformThemeColor(int color_id);
 void immUniformThemeColor3(int color_id);
 void immUniformThemeColorShade(int color_id, int offset);
@@ -55,4 +139,10 @@ void immUniformThemeColorBlendShade(int color_id1, int color_id2, float fac, int
 void immUniformThemeColorBlend(int color_id1, int color_id2, float fac);
 void immThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset);
 
+/* These are called by the system -- not part of drawing API. */
+void immInit(void);
+void immActivate(void);
+void immDeactivate(void);
+void immDestroy(void);
+
 #endif  /* __GPU_IMMEDIATE_H__ */
index c31d477ff5b4a6c2b205e1c31ba61a84de65cd24..0a5c980550948f36eb7c66b34711795ef4e4f55b 100644 (file)
 #ifndef __GPU_IMMEDIATE_UTIL_H__
 #define __GPU_IMMEDIATE_UTIL_H__
 
+/* Draw 2D rectangles (replaces glRect functions) */
+/* caller is reponsible for vertex format & shader */
+void immRectf(uint pos, float x1, float y1, float x2, float y2);
+void immRecti(uint pos, int x1, int y1, int x2, int y2);
+
+/* Same as immRectf/immRecti but does not call immBegin/immEnd. To use with GWN_PRIM_TRIS. */
+void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4]);
+void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4]);
+
 void imm_cpack(uint x);
 
 void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments);
similarity index 98%
rename from intern/gawain/gawain/gwn_primitive.h
rename to source/blender/gpu/GPU_primitive.h
index 346f77441d3a6f553f4334b0acd0e45030376e81..44348b9b593d8ba6f2a78ef3427ff4b72b98c581 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __GWN_PRIMITIVE_H__
 #define __GWN_PRIMITIVE_H__
 
-#include "gwn_common.h"
+#include "GPU_common.h"
 
 typedef enum {
        GWN_PRIM_POINTS,
similarity index 99%
rename from intern/gawain/gawain/gwn_shader_interface.h
rename to source/blender/gpu/GPU_shader_interface.h
index 4b20719b32989498f78ae842259e348129a4b50e..36842e9847aa55246ac0488ecb961c3eb8ebea1f 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __GWN_SHADER_INTERFACE_H__
 #define __GWN_SHADER_INTERFACE_H__
 
-#include "gwn_common.h"
+#include "GPU_common.h"
 
 typedef enum {
        GWN_UNIFORM_NONE = 0, /* uninitialized/unknown */
similarity index 96%
rename from intern/gawain/gawain/gwn_vertex_array_id.h
rename to source/blender/gpu/GPU_vertex_array_id.h
index 6ba26612b4e5b0f3cf37150202bca6414322b699..925cd74511d20133b882249cb1f32bd2891c99ae 100644 (file)
@@ -41,8 +41,8 @@
 extern "C" {
 #endif
 
-#include "gwn_common.h"
-#include "gwn_context.h"
+#include "GPU_common.h"
+#include "GPU_context.h"
 
 GLuint GWN_vao_default(void);
 GLuint GWN_vao_alloc(void);
similarity index 99%
rename from intern/gawain/gawain/gwn_vertex_buffer.h
rename to source/blender/gpu/GPU_vertex_buffer.h
index 84ea12f86d14199f0f247bee2c374a8d1a57720f..7e4aa24ff2cedf6eaccf9a306f611de88d74ce87 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __GWN_VERTEX_BUFFER_H__
 #define __GWN_VERTEX_BUFFER_H__
 
-#include "gwn_vertex_format.h"
+#include "GPU_vertex_format.h"
 
 #define VRAM_USAGE 1
 /* How to create a Gwn_VertBuf: */
similarity index 99%
rename from intern/gawain/gawain/gwn_vertex_format.h
rename to source/blender/gpu/GPU_vertex_format.h
index 1197a8ef842debbf3e56395e41d95a7e36fbe754..91e31b5ece4fe4ee650a3f8abbcbd8f5d673cd02 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef __GWN_VERTEX_FORMAT_H__
 #define __GWN_VERTEX_FORMAT_H__
 
-#include "gwn_common.h"
+#include "GPU_common.h"
 
 #define GWN_VERT_ATTR_MAX_LEN 16
 #define GWN_VERT_ATTR_MAX_NAMES 3
similarity index 97%
rename from intern/gawain/src/gwn_attr_binding.c
rename to source/blender/gpu/intern/gpu_attr_binding.c
index 727aceb014096205362e7dfcad7ea867c57318b7..e7eba3693350a6dda0724ba56fb7a3e647c642b6 100644 (file)
@@ -29,8 +29,8 @@
  * Gawain vertex attribute binding
  */
 
-#include "gwn_attr_binding.h"
-#include "gwn_attr_binding_private.h"
+#include "GPU_attr_binding.h"
+#include "gpu_attr_binding_private.h"
 #include <stddef.h>
 #include <stdlib.h>
 
similarity index 95%
rename from intern/gawain/gawain/gwn_attr_binding_private.h
rename to source/blender/gpu/intern/gpu_attr_binding_private.h
index cead1896ec70e5ce2ff9a359c7c523aa68c06bf2..0e0bf89178adc8bc84b16ed818efd86d739bbdb3 100644 (file)
@@ -32,8 +32,8 @@
 #ifndef __GWN_ATTR_BINDING_PRIVATE_H__
 #define __GWN_ATTR_BINDING_PRIVATE_H__
 
-#include "gwn_vertex_format.h"
-#include "gwn_shader_interface.h"
+#include "GPU_vertex_format.h"
+#include "GPU_shader_interface.h"
 
 void AttribBinding_clear(Gwn_AttrBinding*);
 
index 5bfd20e3c8bbf8a66d8348dfceaf8e83ce8c7fad..90f3093088470598d32cce4f396cfbae557f3b2d 100644 (file)
  * 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.
+ * The Original Code is Copyright (C) 2016 by Mike Erwin.
  * All rights reserved.
  *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Mike Erwin
+ * Contributor(s): Blender Foundation
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file blender/gpu/intern/gpu_batch.c
+/** \file blender/gpu/intern/gwn_batch.c
  *  \ingroup gpu
+ *
+ * Gawain geometry batch
+ * Contains VAOs + VBOs + Shader representing a drawable entity.
  */
 
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_rect.h"
-#include "BLI_math.h"
-#include "BLI_polyfill_2d.h"
-#include "BLI_sort_utils.h"
-
-#include "GPU_batch.h"  /* own include */
+#include "GPU_batch.h"
 #include "GPU_batch_presets.h"
+#include "GPU_buffer_id.h"
+#include "GPU_matrix.h"
+#include "GPU_shader.h"
+#include "GPU_vertex_array_id.h"
+
+#include "gpu_batch_private.h"
+#include "gpu_primitive_private.h"
 #include "gpu_shader_private.h"
 
+#include <stdlib.h>
+#include <string.h>
+
+static void batch_update_program_bindings(Gwn_Batch* batch, uint v_first);
+
+void gwn_batch_vao_cache_clear(Gwn_Batch* batch)
+{
+       if (batch->context == NULL) {
+               return;
+       }
+       if (batch->is_dynamic_vao_count) {
+               for (int i = 0; i < batch->dynamic_vaos.count; ++i) {
+                       if (batch->dynamic_vaos.vao_ids[i]) {
+                               GWN_vao_free(batch->dynamic_vaos.vao_ids[i], batch->context);
+                       }
+                       if (batch->dynamic_vaos.interfaces[i]) {
+                               GWN_shaderinterface_remove_batch_ref((Gwn_ShaderInterface *)batch->dynamic_vaos.interfaces[i], batch);
+                       }
+               }
+               free(batch->dynamic_vaos.interfaces);
+               free(batch->dynamic_vaos.vao_ids);
+       }
+       else {
+               for (int i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) {
+                       if (batch->static_vaos.vao_ids[i]) {
+                               GWN_vao_free(batch->static_vaos.vao_ids[i], batch->context);
+                       }
+                       if (batch->static_vaos.interfaces[i]) {
+                               GWN_shaderinterface_remove_batch_ref((Gwn_ShaderInterface *)batch->static_vaos.interfaces[i], batch);
+                       }
+               }
+       }
+       batch->is_dynamic_vao_count = false;
+       for (int i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) {
+               batch->static_vaos.vao_ids[i] = 0;
+               batch->static_vaos.interfaces[i] = NULL;
+       }
+       gwn_context_remove_batch(batch->context, batch);
+       batch->context = NULL;
+}
+
+Gwn_Batch* GWN_batch_create_ex(
+        Gwn_PrimType prim_type, Gwn_VertBuf* verts, Gwn_IndexBuf* elem,
+        uint owns_flag)
+{
+       Gwn_Batch* batch = calloc(1, sizeof(Gwn_Batch));
+       GWN_batch_init_ex(batch, prim_type, verts, elem, owns_flag);
+       return batch;
+}
+
+void GWN_batch_init_ex(
+        Gwn_Batch* batch, Gwn_PrimType prim_type, Gwn_VertBuf* verts, Gwn_IndexBuf* elem,
+        uint owns_flag)
+{
+#if TRUST_NO_ONE
+       assert(verts != NULL);
+#endif
+
+       batch->verts[0] = verts;
+       for (int v = 1; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
+               batch->verts[v] = NULL;
+       }
+       batch->inst = NULL;
+       batch->elem = elem;
+       batch->gl_prim_type = convert_prim_type_to_gl(prim_type);
+       batch->phase = GWN_BATCH_READY_TO_DRAW;
+       batch->is_dynamic_vao_count = false;
+       batch->owns_flag = owns_flag;
+       batch->free_callback = NULL;
+}
+
+/* This will share the VBOs with the new batch. */
+Gwn_Batch* GWN_batch_duplicate(Gwn_Batch* batch_src)
+{
+       Gwn_Batch* batch = GWN_batch_create_ex(GWN_PRIM_POINTS, batch_src->verts[0], batch_src->elem, 0);
+
+       batch->gl_prim_type = batch_src->gl_prim_type;
+       for (int v = 1; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
+               batch->verts[v] = batch_src->verts[v];
+       }
+       return batch;
+}
+
+void GWN_batch_discard(Gwn_Batch* batch)
+{
+       if (batch->owns_flag & GWN_BATCH_OWNS_INDEX) {
+               GWN_indexbuf_discard(batch->elem);
+       }
+       if (batch->owns_flag & GWN_BATCH_OWNS_INSTANCES) {
+               GWN_vertbuf_discard(batch->inst);
+       }
+       if ((batch->owns_flag & ~GWN_BATCH_OWNS_INDEX) != 0) {
+               for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
+                       if (batch->verts[v] == NULL) {
+                               break;
+                       }
+                       if (batch->owns_flag & (1 << v)) {
+                               GWN_vertbuf_discard(batch->verts[v]);
+                       }
+               }
+       }
+       gwn_batch_vao_cache_clear(batch);
+
+       if (batch->free_callback) {
+               batch->free_callback(batch, batch->callback_data);
+       }
+       free(batch);
+}
+
+void GWN_batch_callback_free_set(Gwn_Batch* batch, void (*callback)(Gwn_Batch*, void*), void* user_data)
+{
+       batch->free_callback = callback;
+       batch->callback_data = user_data;
+}
+
+void GWN_batch_instbuf_set(Gwn_Batch* batch, Gwn_VertBuf* inst, bool own_vbo)
+{
+#if TRUST_NO_ONE
+       assert(inst != NULL);
+#endif
+       /* redo the bindings */
+       gwn_batch_vao_cache_clear(batch);
+
+       if (batch->inst != NULL && (batch->owns_flag & GWN_BATCH_OWNS_INSTANCES)) {
+               GWN_vertbuf_discard(batch->inst);
+       }
+       batch->inst = inst;
+
+       if (own_vbo) {
+               batch->owns_flag |= GWN_BATCH_OWNS_INSTANCES;
+       }
+       else {
+               batch->owns_flag &= ~GWN_BATCH_OWNS_INSTANCES;
+       }
+}
+
+/* Returns the index of verts in the batch. */
+int GWN_batch_vertbuf_add_ex(
+        Gwn_Batch* batch, Gwn_VertBuf* verts,
+        bool own_vbo)
+{
+       /* redo the bindings */
+       gwn_batch_vao_cache_clear(batch);
+
+       for (uint v = 0; v < GWN_BATCH_VBO_MAX_LEN; ++v) {
+               if (batch->verts[v] == NULL) {
+#if TRUST_NO_ONE
+                       /* for now all VertexBuffers must have same vertex_len */
+                       assert(verts->vertex_len == batch->verts[0]->vertex_len);
+#endif
+                       batch->verts[v] = verts;
+                       /* TODO: mark dirty so we can keep attrib bindings up-to-date */
+                       if (own_vbo)
+                               batch->owns_flag |= (1 << v);
+                       return v;
+               }
+       }
+
+       /* we only make it this far if there is no room for another Gwn_VertBuf */
+#if TRUST_NO_ONE
+       assert(false);
+#endif
+       return -1;
+}
+
+static GLuint batch_vao_get(Gwn_Batch *batch)
+{
+       /* Search through cache */
+       if (batch->is_dynamic_vao_count) {
+               for (int i = 0; i < batch->dynamic_vaos.count; ++i)
+                       if (batch->dynamic_vaos.interfaces[i] == batch->interface)
+                               return batch->dynamic_vaos.vao_ids[i];
+       }
+       else {
+               for (int i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i)
+                       if (batch->static_vaos.interfaces[i] == batch->interface)
+                               return batch->static_vaos.vao_ids[i];
+       }
+
+       /* Set context of this batch.
+        * It will be bound to it until gwn_batch_vao_cache_clear is called.
+        * Until then it can only be drawn with this context. */
+       if (batch->context == NULL) {
+               batch->context = GWN_context_active_get();
+               gwn_context_add_batch(batch->context, batch);
+       }
+#if TRUST_NO_ONE
+       else {
+               /* Make sure you are not trying to draw this batch in another context. */
+               assert(batch->context == GWN_context_active_get());
+       }
+#endif
+
+       /* Cache miss, time to add a new entry! */
+       GLuint new_vao = 0;
+       if (!batch->is_dynamic_vao_count) {
+               int i; /* find first unused slot */
+               for (i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) 
+                       if (batch->static_vaos.vao_ids[i] == 0)
+                               break;
+
+               if (i < GWN_BATCH_VAO_STATIC_LEN) {
+                       batch->static_vaos.interfaces[i] = batch->interface;
+                       batch->static_vaos.vao_ids[i] = new_vao = GWN_vao_alloc();
+               }
+               else {
+                       /* Not enough place switch to dynamic. */
+                       batch->is_dynamic_vao_count = true;
+                       /* Erase previous entries, they will be added back if drawn again. */
+                       for (int j = 0; j < GWN_BATCH_VAO_STATIC_LEN; ++j) {
+                               GWN_shaderinterface_remove_batch_ref((Gwn_ShaderInterface*)batch->static_vaos.interfaces[j], batch);
+                               GWN_vao_free(batch->static_vaos.vao_ids[j], batch->context);
+                       }
+                       /* Init dynamic arrays and let the branch below set the values. */
+                       batch->dynamic_vaos.count = GWN_BATCH_VAO_DYN_ALLOC_COUNT;
+                       batch->dynamic_vaos.interfaces = calloc(batch->dynamic_vaos.count, sizeof(Gwn_ShaderInterface*));
+                       batch->dynamic_vaos.vao_ids = calloc(batch->dynamic_vaos.count, sizeof(GLuint));
+               }
+       }
+
+       if (batch->is_dynamic_vao_count) {
+               int i; /* find first unused slot */
+               for (i = 0; i < batch->dynamic_vaos.count; ++i)
+                       if (batch->dynamic_vaos.vao_ids[i] == 0)
+                               break;
+
+               if (i == batch->dynamic_vaos.count) {
+                       /* Not enough place, realloc the array. */
+                       i = batch->dynamic_vaos.count;
+                       batch->dynamic_vaos.count += GWN_BATCH_VAO_DYN_ALLOC_COUNT;
+                       batch->dynamic_vaos.interfaces = realloc(batch->dynamic_vaos.interfaces, sizeof(Gwn_ShaderInterface*) * batch->dynamic_vaos.count);
+                       batch->dynamic_vaos.vao_ids = realloc(batch->dynamic_vaos.vao_ids, sizeof(GLuint) * batch->dynamic_vaos.count);
+                       memset(batch->dynamic_vaos.interfaces + i, 0, sizeof(Gwn_ShaderInterface*) * GWN_BATCH_VAO_DYN_ALLOC_COUNT);
+                       memset(batch->dynamic_vaos.vao_ids + i, 0, sizeof(GLuint) * GWN_BATCH_VAO_DYN_ALLOC_COUNT);
+               }
+               batch->dynamic_vaos.interfaces[i] = batch->interface;
+               batch->dynamic_vaos.vao_ids[i] = new_vao = GWN_vao_alloc();
+       }
+
+       GWN_shaderinterface_add_batch_ref((Gwn_ShaderInterface*)batch->interface, batch);
+
+#if TRUST_NO_ONE
+       assert(new_vao != 0);
+#endif
+
+       /* We just got a fresh VAO we need to initialize it. */
+       glBindVertexArray(new_vao);
+       batch_update_program_bindings(batch, 0);
+       glBindVertexArray(0);
+
+       return new_vao;
+}
+
+void GWN_batch_program_set_no_use(Gwn_Batch* batch, uint32_t program, const Gwn_ShaderInterface* shaderface)
+{
+#if TRUST_NO_ONE
+       assert(glIsProgram(shaderface->program));
+       assert(batch->program_in_use == 0);
+#endif
+       batch->interface = shaderface;
+       batch->program = program;
+       batch->vao_id = batch_vao_get(batch);
+}
+
+void GWN_batch_program_set(Gwn_Batch* batch, uint32_t program, const Gwn_ShaderInterface* shaderface)
+{
+       GWN_batch_program_set_no_use(batch, program, shaderface);
+       GWN_batch_program_use_begin(batch); /* hack! to make Batch_Uniform* simpler */
+}
+
+void gwn_batch_remove_interface_ref(Gwn_Batch* batch, const Gwn_ShaderInterface* interface)
+{
+       if (batch->is_dynamic_vao_count) {
+               for (int i = 0; i < batch->dynamic_vaos.count; ++i) {
+                       if (batch->dynamic_vaos.interfaces[i] == interface) {
+                               GWN_vao_free(batch->dynamic_vaos.vao_ids[i], batch->context);
+                               batch->dynamic_vaos.vao_ids[i] = 0;
+                               batch->dynamic_vaos.interfaces[i] = NULL;
+                               break; /* cannot have duplicates */
+                       }
+               }
+       }
+       else {
+               int i;
+               for (i = 0; i < GWN_BATCH_VAO_STATIC_LEN; ++i) {
+                       if (batch->static_vaos.interfaces[i] == interface) {
+                               GWN_vao_free(batch->static_vaos.vao_ids[i], batch->context);
+                               batch->static_vaos.vao_ids[i] = 0;
+                               batch->static_vaos.interfaces[i] = NULL;
+                               break; /* cannot have duplicates */
+                       }
+               }
+       }
+}
+
+static void create_bindings(
+        Gwn_VertBuf* verts, const Gwn_ShaderInterface* interface,
+        uint v_first, const bool use_instancing)
+{
+       const Gwn_VertFormat* format = &verts->format;
+
+       const uint attr_len = format->attr_len;
+       const uint stride = format->stride;
+
+       GWN_vertbuf_use(verts);
+
+       for (uint a_idx = 0; a_idx < attr_len; ++a_idx) {
+               const Gwn_VertAttr* a = format->attribs + a_idx;
+               const GLvoid* pointer = (const GLubyte*)0 + a->offset + v_first * stride;
+
+               for (uint n_idx = 0; n_idx < a->name_len; ++n_idx) {
+                       const Gwn_ShaderInput* input = GWN_shaderinterface_attr(interface, a->name[n_idx]);
+
+                       if (input == NULL) continue;
+
+                       if (a->comp_len == 16 || a->comp_len == 12 || a->comp_len == 8) {
+#if TRUST_NO_ONE
+                               assert(a->fetch_mode == GWN_FETCH_FLOAT);
+                               assert(a->gl_comp_type == GL_FLOAT);
+#endif
+                               for (int i = 0; i < a->comp_len / 4; ++i) {
+                                       glEnableVertexAttribArray(input->location + i);
+                                       glVertexAttribDivisor(input->location + i, (use_instancing) ? 1 : 0);
+                                       glVertexAttribPointer(input->location + i, 4, a->gl_comp_type, GL_FALSE, stride,
+                                                             (const GLubyte*)pointer + i * 16);
+                               }
+                       }
+                       else
+                               {
+                               glEnableVertexAttribArray(input->location);
+                               glVertexAttribDivisor(input->location, (use_instancing) ? 1 : 0);
+
+                               switch (a->fetch_mode) {
+                                       case GWN_FETCH_FLOAT:
+                                       case GWN_FETCH_INT_TO_FLOAT:
+                                               glVertexAttribPointer(input->location, a->comp_len, a->gl_comp_type, GL_FALSE, stride, pointer);
+                                               break;
+                                       case GWN_FETCH_INT_TO_FLOAT_UNIT:
+                                               glVertexAttribPointer(input->location, a->comp_len, a->gl_comp_type, GL_TRUE, stride, pointer);
+                                               break;
+                                       case GWN_FETCH_INT:
+                                               glVertexAttribIPointer(input->location, a->comp_len, a->gl_comp_type, stride, pointer);
+                                               break;
+                               }
+                       }
+               }
+       }
+}
+
+static void batch_update_program_bindings(Gwn_Batch* batch, uint v_first)
+{
+       for (int v = 0; v < GWN_BATCH_VBO_MAX_LEN && batch->verts[v] != NULL; ++v) {
+               create_bindings(batch->verts[v], batch->interface, (batch->inst) ? 0 : v_first, false);
+       }
+       if (batch->inst) {
+               create_bindings(batch->inst, batch->interface, v_first, true);
+       }
+       if (batch->elem) {
+               GWN_indexbuf_use(batch->elem);
+       }
+}
+
+void GWN_batch_program_use_begin(Gwn_Batch* batch)
+{
+       /* NOTE: use_program & done_using_program are fragile, depend on staying in sync with
+        *       the GL context's active program. use_program doesn't mark other programs as "not used". */
+       /* TODO: make not fragile (somehow) */
+
+       if (!batch->program_in_use) {
+               glUseProgram(batch->program);
+               batch->program_in_use = true;
+       }
+}
+
+void GWN_batch_program_use_end(Gwn_Batch* batch)
+{
+       if (batch->program_in_use) {
+#if PROGRAM_NO_OPTI
+               glUseProgram(0);
+#endif
+               batch->program_in_use = false;
+       }
+}
+
+#if TRUST_NO_ONE
+  #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(batch->interface, name); assert(uniform);
+#else
+  #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(batch->interface, name);
+#endif
+
+void GWN_batch_uniform_1ui(Gwn_Batch* batch, const char* name, int value)
+{
+       GET_UNIFORM
+       glUniform1ui(uniform->location, value);
+}
+
+void GWN_batch_uniform_1i(Gwn_Batch* batch, const char* name, int value)
+{
+       GET_UNIFORM
+       glUniform1i(uniform->location, value);
+}
+
+void GWN_batch_uniform_1b(Gwn_Batch* batch, const char* name, bool value)
+{
+       GET_UNIFORM
+       glUniform1i(uniform->location, value ? GL_TRUE : GL_FALSE);
+}
+
+void GWN_batch_uniform_2f(Gwn_Batch* batch, const char* name, float x, float y)
+{
+       GET_UNIFORM
+       glUniform2f(uniform->location, x, y);
+}
+
+void GWN_batch_uniform_3f(Gwn_Batch* batch, const char* name, float x, float y, float z)
+{
+       GET_UNIFORM
+       glUniform3f(uniform->location, x, y, z);
+}
+
+void GWN_batch_uniform_4f(Gwn_Batch* batch, const char* name, float x, float y, float z, float w)
+{
+       GET_UNIFORM
+       glUniform4f(uniform->location, x, y, z, w);
+}
+
+void GWN_batch_uniform_1f(Gwn_Batch* batch, const char* name, float x)
+{
+       GET_UNIFORM
+       glUniform1f(uniform->location, x);
+}
+
+void GWN_batch_uniform_2fv(Gwn_Batch* batch, const char* name, const float data[2])
+{
+       GET_UNIFORM
+       glUniform2fv(uniform->location, 1, data);
+}
+
+void GWN_batch_uniform_3fv(Gwn_Batch* batch, const char* name, const float data[3])
+{
+       GET_UNIFORM
+       glUniform3fv(uniform->location, 1, data);
+}
+
+void GWN_batch_uniform_4fv(Gwn_Batch* batch, const char* name, const float data[4])
+{
+       GET_UNIFORM
+       glUniform4fv(uniform->location, 1, data);
+}
+
+void GWN_batch_uniform_2fv_array(Gwn_Batch* batch, const char* name, const int len, const float *data)
+{
+       GET_UNIFORM
+       glUniform2fv(uniform->location, len, data);
+}
+
+void GWN_batch_uniform_4fv_array(Gwn_Batch* batch, const char* name, const int len, const float *data)
+{
+       GET_UNIFORM
+       glUniform4fv(uniform->location, len, data);
+}
+
+void GWN_batch_uniform_mat4(Gwn_Batch* batch, const char* name, const float data[4][4])
+{
+       GET_UNIFORM
+       glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (const float *)data);
+}
+
+static void primitive_restart_enable(const Gwn_IndexBuf *el)
+{
+       // TODO(fclem) Replace by GL_PRIMITIVE_RESTART_FIXED_INDEX when we have ogl 4.3
+       glEnable(GL_PRIMITIVE_RESTART);
+       GLuint restart_index = (GLuint)0xFFFFFFFF;
+
+#if GWN_TRACK_INDEX_RANGE
+       if (el->index_type == GWN_INDEX_U8)
+               restart_index = (GLuint)0xFF;
+       else if (el->index_type == GWN_INDEX_U16)
+               restart_index = (GLuint)0xFFFF;
+#endif
+
+       glPrimitiveRestartIndex(restart_index);
+}
+
+static void primitive_restart_disable(void)
+{
+       glDisable(GL_PRIMITIVE_RESTART);
+}
+
+void GWN_batch_draw(Gwn_Batch* batch)
+{
+#if TRUST_NO_ONE
+       assert(batch->phase == GWN_BATCH_READY_TO_DRAW);
+       assert(batch->verts[0]->vbo_id != 0);
+#endif
+       GWN_batch_program_use_begin(batch);
+       GPU_matrix_bind(batch->interface); // external call.
+
+       GWN_batch_draw_range_ex(batch, 0, 0, false);
+
+       GWN_batch_program_use_end(batch);
+}
+
+void GWN_batch_draw_range_ex(Gwn_Batch* batch, int v_first, int v_count, bool force_instance)
+{
+#if TRUST_NO_ONE
+       assert(!(force_instance && (batch->inst == NULL)) || v_count > 0); // we cannot infer length if force_instance
+#endif
+       const bool do_instance = (force_instance || batch->inst);
+
+       // If using offset drawing, use the default VAO and redo bindings.
+       if (v_first != 0 && (do_instance || batch->elem)) {
+               glBindVertexArray(GWN_vao_default());
+               batch_update_program_bindings(batch, v_first);
+       }
+       else {
+               glBindVertexArray(batch->vao_id);
+       }
+
+       if (do_instance) {
+               /* Infer length if vertex count is not given */
+               if (v_count == 0) {
+                       v_count = batch->inst->vertex_len;
+               }
+
+               if (batch->elem) {
+                       const Gwn_IndexBuf* el = batch->elem;
+
+                       if (el->use_prim_restart) {
+                               primitive_restart_enable(el);
+                       }
+#if GWN_TRACK_INDEX_RANGE
+                       glDrawElementsInstancedBaseVertex(batch->gl_prim_type,
+                                                         el->index_len,
+                                                         el->gl_index_type,
+                                                         0,
+                                                         v_count,
+                                                         el->base_index);
+#else
+                       glDrawElementsInstanced(batch->gl_prim_type, el->index_len, GL_UNSIGNED_INT, 0, v_count);
+#endif
+                       if (el->use_prim_restart) {
+                               primitive_restart_disable();
+                       }
+               }
+               else {
+                       glDrawArraysInstanced(batch->gl_prim_type, 0, batch->verts[0]->vertex_len, v_count);
+               }
+       }
+       else {
+               /* Infer length if vertex count is not given */
+               if (v_count == 0) {
+                       v_count = (batch->elem) ? batch->elem->index_len : batch->verts[0]->vertex_len;
+               }
+
+               if (batch->elem) {
+                       const Gwn_IndexBuf* el = batch->elem;
+
+                       if (el->use_prim_restart) {
+                               primitive_restart_enable(el);
+                       }
+
+#if GWN_TRACK_INDEX_RANGE
+                       if (el->base_index) {
+                               glDrawRangeElementsBaseVertex(batch->gl_prim_type,
+                                                             el->min_index,
+                                                             el->max_index,
+                                                             v_count,
+                                                             el->gl_index_type,
+                                                             0,
+                                                             el->base_index);
+                       }
+                       else {
+                               glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, 0);
+                       }
+#else
+                       glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, 0);
+#endif
+                       if (el->use_prim_restart) {
+                               primitive_restart_disable();
+                       }
+               }
+               else {
+                       glDrawArrays(batch->gl_prim_type, v_first, v_count);
+               }
+       }
+
+       /* Performance hog if you are drawing with the same vao multiple time.
+        * Only activate for debugging. */
+       // glBindVertexArray(0);
+}
+
+/* just draw some vertices and let shader place them where we want. */
+void GWN_draw_primitive(Gwn_PrimType prim_type, int v_count)
+       {
+       /* we cannot draw without vao ... annoying ... */
+       glBindVertexArray(GWN_vao_default());
+
+       GLenum type = convert_prim_type_to_gl(prim_type);
+       glDrawArrays(type, 0, v_count);
+
+       /* Performance hog if you are drawing with the same vao multiple time.
+        * Only activate for debugging.*/
+       // glBindVertexArray(0);
+       }
+
+
 /* -------------------------------------------------------------------- */
 /** \name Utilities
  * \{ */
@@ -67,4 +674,4 @@ void gpu_batch_exit(void)
        gpu_batch_presets_exit();
 }
 
-/** \} */
+/** \} */
\ No newline at end of file
similarity index 92%
rename from intern/gawain/gawain/gwn_batch_private.h
rename to source/blender/gpu/intern/gpu_batch_private.h
index e7d42ff024963440ee991b871b4cfe06f35e8465..1e72bae503fd6a62fe26d00f01ac8ff264028ca6 100644 (file)
 extern "C" {
 #endif
 
-#include "gwn_batch.h"
-#include "gwn_context.h"
-#include "gwn_shader_interface.h"
+#include "GPU_batch.h"
+#include "GPU_context.h"
+#include "GPU_shader_interface.h"
 
 void gwn_batch_remove_interface_ref(Gwn_Batch*, const Gwn_ShaderInterface*);
-void gwn_batch_vao_cache_clear(Gwn_Batch*);
 
 void gwn_context_add_batch(Gwn_Context*, Gwn_Batch*);
 void gwn_context_remove_batch(Gwn_Context*, Gwn_Batch*);
similarity index 98%
rename from intern/gawain/src/gwn_buffer_id.cpp
rename to source/blender/gpu/intern/gpu_buffer_id.cpp
index 2c267682f65fa708440e3ea29df45f76d9cb0e60..0c442f687a08aa14f7fa8fe890c6dd93e2fa7242 100644 (file)
@@ -29,7 +29,8 @@
  * Gawain buffer IDs
  */
 
-#include "gwn_buffer_id.h"
+#include "GPU_buffer_id.h"
+
 #include <mutex>
 #include <vector>
 
similarity index 99%
rename from intern/gawain/src/gwn_element.c
rename to source/blender/gpu/intern/gpu_element.c
index a8c99f20860795b807d1d9ee5898a699ed817aac..596530a6ff4bc67206b37e4c91ce600f3e0320b1 100644 (file)
@@ -29,8 +29,9 @@
  * Gawain element list (AKA index buffer)
  */
 
-#include "gwn_element.h"
-#include "gwn_buffer_id.h"
+#include "GPU_element.h"
+#include "GPU_buffer_id.h"
+
 #include <stdlib.h>
 
 #define KEEP_SINGLE_COPY 1
index 5f22b7f9279c5f6783039dcc24bceaa3b23ed61a..661594faf394bb09bf4f2a258c0ed282fb9415c3 100644 (file)
  * 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.
+ * The Original Code is Copyright (C) 2016 by Mike Erwin.
  * All rights reserved.
  *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Mike Erwin
+ * Contributor(s): Blender Foundation
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#include "GPU_immediate.h"
-#include "GPU_matrix.h"
+/** \file blender/gpu/intern/gwn_immediate.c
+ *  \ingroup gpu
+ *
+ * Gawain immediate mode work-alike
+ */
+
 #include "UI_resources.h"
-#include "BLI_utildefines.h"
 
+#include "GPU_attr_binding.h"
+#include "GPU_buffer_id.h"
+#include "GPU_immediate.h"
+#include "GPU_vertex_array_id.h"
+
+#include "gpu_attr_binding_private.h"
+#include "gpu_primitive_private.h"
 #include "gpu_shader_private.h"
+#include "gpu_vertex_format_private.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+/* necessary functions from matrix API */
+extern void GPU_matrix_bind(const Gwn_ShaderInterface*);
+extern bool GPU_matrix_dirty_get(void);
+
+typedef struct {
+       /* TODO: organize this struct by frequency of change (run-time) */
+
+       Gwn_Batch* batch;
+       Gwn_Context* context;
+
+       /* current draw call */
+       GLubyte* buffer_data;
+       uint buffer_offset;
+       uint buffer_bytes_mapped;
+       uint vertex_len;
+       bool strict_vertex_len;
+       Gwn_PrimType prim_type;
+
+       Gwn_VertFormat vertex_format;
+
+       /* current vertex */
+       uint vertex_idx;
+       GLubyte* vertex_data;
+       uint16_t unassigned_attrib_bits; /* which attributes of current vertex have not been given values? */
+
+       GLuint vbo_id;
+       GLuint vao_id;
+
+       GLuint bound_program;
+       const Gwn_ShaderInterface* shader_interface;
+       Gwn_AttrBinding attrib_binding;
+       uint16_t prev_enabled_attrib_bits; /* <-- only affects this VAO, so we're ok */
+} Immediate;
+
+/* size of internal buffer -- make this adjustable? */
+#define IMM_BUFFER_SIZE (4 * 1024 * 1024)
+
+static bool initialized = false;
+static Immediate imm;
+
+void immInit(void)
+{
+#if TRUST_NO_ONE
+       assert(!initialized);
+#endif
+       memset(&imm, 0, sizeof(Immediate));
+
+       imm.vbo_id = GWN_buf_id_alloc();
+       glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id);
+       glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW);
+
+       imm.prim_type = GWN_PRIM_NONE;
+       imm.strict_vertex_len = true;
+
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+       initialized = true;
+}
+
+void immActivate(void)
+{
+#if TRUST_NO_ONE
+       assert(initialized);
+       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we're not between a Begin/End pair */
+       assert(imm.vao_id == 0);
+#endif
+       imm.vao_id = GWN_vao_alloc();
+       imm.context = GWN_context_active_get();
+}
+
+void immDeactivate(void)
+{
+#if TRUST_NO_ONE
+       assert(initialized);
+       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we're not between a Begin/End pair */
+       assert(imm.vao_id != 0);
+#endif
+       GWN_vao_free(imm.vao_id, imm.context);
+       imm.vao_id = 0;
+       imm.prev_enabled_attrib_bits = 0;
+}
+
+void immDestroy(void)
+{
+       GWN_buf_id_free(imm.vbo_id);
+       initialized = false;
+}
+
+Gwn_VertFormat* immVertexFormat(void)
+{
+       GWN_vertformat_clear(&imm.vertex_format);
+       return &imm.vertex_format;
+}
+
+void immBindProgram(GLuint program, const Gwn_ShaderInterface* shaderface)
+{
+#if TRUST_NO_ONE
+       assert(imm.bound_program == 0);
+       assert(glIsProgram(program));
+#endif
+
+       imm.bound_program = program;
+       imm.shader_interface = shaderface;
+
+       if (!imm.vertex_format.packed)
+               VertexFormat_pack(&imm.vertex_format);
+
+       glUseProgram(program);
+       get_attrib_locations(&imm.vertex_format, &imm.attrib_binding, shaderface);
+       GPU_matrix_bind(shaderface);
+}
 
 void immBindBuiltinProgram(GPUBuiltinShader shader_id)
 {
@@ -38,6 +161,718 @@ void immBindBuiltinProgram(GPUBuiltinShader shader_id)
        immBindProgram(shader->program, shader->interface);
 }
 
+void immUnbindProgram(void)
+{
+#if TRUST_NO_ONE
+       assert(imm.bound_program != 0);
+#endif
+#if PROGRAM_NO_OPTI
+       glUseProgram(0);
+#endif
+       imm.bound_program = 0;
+}
+
+#if TRUST_NO_ONE
+static bool vertex_count_makes_sense_for_primitive(uint vertex_len, Gwn_PrimType prim_type)
+{
+       /* does vertex_len make sense for this primitive type? */
+       if (vertex_len == 0) {
+               return false;
+       }
+
+       switch (prim_type) {
+               case GWN_PRIM_POINTS:
+                       return true;
+               case GWN_PRIM_LINES:
+                       return vertex_len % 2 == 0;
+               case GWN_PRIM_LINE_STRIP:
+               case GWN_PRIM_LINE_LOOP:
+                       return vertex_len >= 2;
+               case GWN_PRIM_LINE_STRIP_ADJ:
+                       return vertex_len >= 4;
+               case GWN_PRIM_TRIS:
+                       return vertex_len % 3 == 0;
+               case GWN_PRIM_TRI_STRIP:
+               case GWN_PRIM_TRI_FAN:
+                       return vertex_len >= 3;
+               default:
+                       return false;
+       }
+}
+#endif
+
+void immBegin(Gwn_PrimType prim_type, uint vertex_len)
+{
+#if TRUST_NO_ONE
+       assert(initialized);
+       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we haven't already begun */
+       assert(vertex_count_makes_sense_for_primitive(vertex_len, prim_type));
+#endif
+       imm.prim_type = prim_type;
+       imm.vertex_len = vertex_len;
+       imm.vertex_idx = 0;
+       imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
+
+       /* how many bytes do we need for this draw call? */
+       const uint bytes_needed = vertex_buffer_size(&imm.vertex_format, vertex_len);
+
+#if TRUST_NO_ONE
+       assert(bytes_needed <= IMM_BUFFER_SIZE);
+#endif
+
+       glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id);
+
+       /* does the current buffer have enough room? */
+       const uint available_bytes = IMM_BUFFER_SIZE - imm.buffer_offset;
+       /* ensure vertex data is aligned */
+       const uint pre_padding = padding(imm.buffer_offset, imm.vertex_format.stride); /* might waste a little space, but it's safe */
+       if ((bytes_needed + pre_padding) <= available_bytes) {
+               imm.buffer_offset += pre_padding;
+       }
+       else {
+               /* orphan this buffer & start with a fresh one */
+               /* this method works on all platforms, old & new */
+               glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW);
+
+               imm.buffer_offset = 0;
+       }
+
+/*     printf("mapping %u to %u\n", imm.buffer_offset, imm.buffer_offset + bytes_needed - 1); */
+
+       imm.buffer_data = glMapBufferRange(GL_ARRAY_BUFFER, imm.buffer_offset, bytes_needed,
+                                          GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | (imm.strict_vertex_len ? 0 : GL_MAP_FLUSH_EXPLICIT_BIT));
+
+#if TRUST_NO_ONE
+       assert(imm.buffer_data != NULL);
+#endif
+
+       imm.buffer_bytes_mapped = bytes_needed;
+       imm.vertex_data = imm.buffer_data;
+}
+
+void immBeginAtMost(Gwn_PrimType prim_type, uint vertex_len)
+{
+#if TRUST_NO_ONE
+       assert(vertex_len > 0);
+#endif
+
+       imm.strict_vertex_len = false;
+       immBegin(prim_type, vertex_len);
+}
+
+
+Gwn_Batch* immBeginBatch(Gwn_PrimType prim_type, uint vertex_len)
+{
+#if TRUST_NO_ONE
+       assert(initialized);
+       assert(imm.prim_type == GWN_PRIM_NONE); /* make sure we haven't already begun */
+       assert(vertex_count_makes_sense_for_primitive(vertex_len, prim_type));
+#endif
+       imm.prim_type = prim_type;
+       imm.vertex_len = vertex_len;
+       imm.vertex_idx = 0;
+       imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
+
+       Gwn_VertBuf* verts = GWN_vertbuf_create_with_format(&imm.vertex_format);
+       GWN_vertbuf_data_alloc(verts, vertex_len);
+
+       imm.buffer_bytes_mapped = GWN_vertbuf_size_get(verts);
+       imm.vertex_data = verts->data;
+
+       imm.batch = GWN_batch_create_ex(prim_type, verts, NULL, GWN_BATCH_OWNS_VBO);
+       imm.batch->phase = GWN_BATCH_BUILDING;
+
+       return imm.batch;
+}
+
+Gwn_Batch* immBeginBatchAtMost(Gwn_PrimType prim_type, uint vertex_len)
+{
+       imm.strict_vertex_len = false;
+       return immBeginBatch(prim_type, vertex_len);
+}
+
+static void immDrawSetup(void)
+{
+       /* set up VAO -- can be done during Begin or End really */
+       glBindVertexArray(imm.vao_id);
+
+       /* enable/disable vertex attribs as needed */
+       if (imm.attrib_binding.enabled_bits != imm.prev_enabled_attrib_bits) {
+               for (uint loc = 0; loc < GWN_VERT_ATTR_MAX_LEN; ++loc) {
+                       bool is_enabled = imm.attrib_binding.enabled_bits & (1 << loc);
+                       bool was_enabled = imm.prev_enabled_attrib_bits & (1 << loc);
+
+                       if (is_enabled && !was_enabled) {
+                               glEnableVertexAttribArray(loc);
+                       }
+                       else if (was_enabled && !is_enabled) {
+                               glDisableVertexAttribArray(loc);
+                       }
+               }
+
+               imm.prev_enabled_attrib_bits = imm.attrib_binding.enabled_bits;
+       }
+
+       const uint stride = imm.vertex_format.stride;
+
+       for (uint a_idx = 0; a_idx < imm.vertex_format.attr_len; ++a_idx) {
+               const Gwn_VertAttr* a = imm.vertex_format.attribs + a_idx;
+
+               const uint offset = imm.buffer_offset + a->offset;
+               const GLvoid* pointer = (const GLubyte*)0 + offset;
+
+               const uint loc = read_attrib_location(&imm.attrib_binding, a_idx);
+
+               switch (a->fetch_mode) {
+                       case GWN_FETCH_FLOAT:
+                       case GWN_FETCH_INT_TO_FLOAT:
+                               glVertexAttribPointer(loc, a->comp_len, a->gl_comp_type, GL_FALSE, stride, pointer);
+                               break;
+                       case GWN_FETCH_INT_TO_FLOAT_UNIT:
+                               glVertexAttribPointer(loc, a->comp_len, a->gl_comp_type, GL_TRUE, stride, pointer);
+                               break;
+                       case GWN_FETCH_INT:
+                               glVertexAttribIPointer(loc, a->comp_len, a->gl_comp_type, stride, pointer);
+               }
+       }
+
+       if (GPU_matrix_dirty_get()) {
+               GPU_matrix_bind(imm.shader_interface);
+       }
+}
+
+void immEnd(void)
+{
+#if TRUST_NO_ONE
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+
+       uint buffer_bytes_used;
+       if (imm.strict_vertex_len) {
+#if TRUST_NO_ONE
+               assert(imm.vertex_idx == imm.vertex_len); /* with all vertices defined */
+#endif
+               buffer_bytes_used = imm.buffer_bytes_mapped;
+       }
+       else {
+#if TRUST_NO_ONE
+               assert(imm.vertex_idx <= imm.vertex_len);
+#endif
+               if (imm.vertex_idx == imm.vertex_len) {
+                       buffer_bytes_used = imm.buffer_bytes_mapped;
+               }
+               else {
+#if TRUST_NO_ONE
+                       assert(imm.vertex_idx == 0 || vertex_count_makes_sense_for_primitive(imm.vertex_idx, imm.prim_type));
+#endif
+                       imm.vertex_len = imm.vertex_idx;
+                       buffer_bytes_used = vertex_buffer_size(&imm.vertex_format, imm.vertex_len);
+                       /* unused buffer bytes are available to the next immBegin */
+               }
+               /* tell OpenGL what range was modified so it doesn't copy the whole mapped range */
+               glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, buffer_bytes_used);
+       }
+
+       if (imm.batch) {
+               if (buffer_bytes_used != imm.buffer_bytes_mapped) {
+                       GWN_vertbuf_data_resize(imm.batch->verts[0], imm.vertex_len);
+                       /* TODO: resize only if vertex count is much smaller */
+               }
+               GWN_batch_program_set(imm.batch, imm.bound_program, imm.shader_interface);
+               imm.batch->phase = GWN_BATCH_READY_TO_DRAW;
+               imm.batch = NULL; /* don't free, batch belongs to caller */
+       }
+       else {
+               glUnmapBuffer(GL_ARRAY_BUFFER);
+               if (imm.vertex_len > 0) {
+                       immDrawSetup();
+                       glDrawArrays(convert_prim_type_to_gl(imm.prim_type), 0, imm.vertex_len);
+               }
+               glBindBuffer(GL_ARRAY_BUFFER, 0);
+               glBindVertexArray(0);
+               /* prep for next immBegin */
+               imm.buffer_offset += buffer_bytes_used;
+       }
+
+       /* prep for next immBegin */
+       imm.prim_type = GWN_PRIM_NONE;
+       imm.strict_vertex_len = true;
+}
+
+static void setAttribValueBit(uint attrib_id)
+{
+       uint16_t mask = 1 << attrib_id;
+#if TRUST_NO_ONE
+       assert(imm.unassigned_attrib_bits & mask); /* not already set */
+#endif
+       imm.unassigned_attrib_bits &= ~mask;
+}
+
+
+/* --- generic attribute functions --- */
+
+void immAttrib1f(uint attrib_id, float x)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_F32);
+       assert(attrib->comp_len == 1);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       float* data = (float*)(imm.vertex_data + attrib->offset);
+/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
+
+       data[0] = x;
+}
+
+void immAttrib2f(uint attrib_id, float x, float y)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_F32);
+       assert(attrib->comp_len == 2);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       float* data = (float*)(imm.vertex_data + attrib->offset);
+/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
+
+       data[0] = x;
+       data[1] = y;
+}
+
+void immAttrib3f(uint attrib_id, float x, float y, float z)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_F32);
+       assert(attrib->comp_len == 3);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       float* data = (float*)(imm.vertex_data + attrib->offset);
+/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
+
+       data[0] = x;
+       data[1] = y;
+       data[2] = z;
+}
+
+void immAttrib4f(uint attrib_id, float x, float y, float z, float w)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_F32);
+       assert(attrib->comp_len == 4);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       float* data = (float*)(imm.vertex_data + attrib->offset);
+/*     printf("%s %td %p\n", __FUNCTION__, (GLubyte*)data - imm.buffer_data, data); */
+
+       data[0] = x;
+       data[1] = y;
+       data[2] = z;
+       data[3] = w;
+}
+
+void immAttrib1u(uint attrib_id, uint x)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_U32);
+       assert(attrib->comp_len == 1);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       uint* data = (uint*)(imm.vertex_data + attrib->offset);
+
+       data[0] = x;
+}
+
+void immAttrib2i(uint attrib_id, int x, int y)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_I32);
+       assert(attrib->comp_len == 2);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       int* data = (int*)(imm.vertex_data + attrib->offset);
+
+       data[0] = x;
+       data[1] = y;
+}
+
+void immAttrib2s(uint attrib_id, short x, short y)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_I16);
+       assert(attrib->comp_len == 2);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       short* data = (short*)(imm.vertex_data + attrib->offset);
+
+       data[0] = x;
+       data[1] = y;
+}
+
+void immAttrib2fv(uint attrib_id, const float data[2])
+{
+       immAttrib2f(attrib_id, data[0], data[1]);
+}
+
+void immAttrib3fv(uint attrib_id, const float data[3])
+{
+       immAttrib3f(attrib_id, data[0], data[1], data[2]);
+}
+
+void immAttrib4fv(uint attrib_id, const float data[4])
+{
+       immAttrib4f(attrib_id, data[0], data[1], data[2], data[3]);
+}
+
+void immAttrib3ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_U8);
+       assert(attrib->comp_len == 3);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       GLubyte* data = imm.vertex_data + attrib->offset;
+/*     printf("%s %td %p\n", __FUNCTION__, data - imm.buffer_data, data); */
+
+       data[0] = r;
+       data[1] = g;
+       data[2] = b;
+}
+
+void immAttrib4ub(uint attrib_id, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
+{
+       Gwn_VertAttr* attrib = imm.vertex_format.attribs + attrib_id;
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(attrib->comp_type == GWN_COMP_U8);
+       assert(attrib->comp_len == 4);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+
+       GLubyte* data = imm.vertex_data + attrib->offset;
+/*     printf("%s %td %p\n", __FUNCTION__, data - imm.buffer_data, data); */
+
+       data[0] = r;
+       data[1] = g;
+       data[2] = b;
+       data[3] = a;
+}
+
+void immAttrib3ubv(uint attrib_id, const unsigned char data[3])
+{
+       immAttrib3ub(attrib_id, data[0], data[1], data[2]);
+}
+
+void immAttrib4ubv(uint attrib_id, const unsigned char data[4])
+{
+       immAttrib4ub(attrib_id, data[0], data[1], data[2], data[3]);
+}
+
+void immSkipAttrib(uint attrib_id)
+{
+#if TRUST_NO_ONE
+       assert(attrib_id < imm.vertex_format.attr_len);
+       assert(imm.vertex_idx < imm.vertex_len);
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+#endif
+       setAttribValueBit(attrib_id);
+}
+
+static void immEndVertex(void) /* and move on to the next vertex */
+{
+#if TRUST_NO_ONE
+       assert(imm.prim_type != GWN_PRIM_NONE); /* make sure we're between a Begin/End pair */
+       assert(imm.vertex_idx < imm.vertex_len);
+#endif
+
+       /* have all attribs been assigned values?
+        * if not, copy value from previous vertex */
+       if (imm.unassigned_attrib_bits) {
+#if TRUST_NO_ONE
+               assert(imm.vertex_idx > 0); /* first vertex must have all attribs specified */
+#endif
+               for (uint a_idx = 0; a_idx < imm.vertex_format.attr_len; ++a_idx) {
+                       if ((imm.unassigned_attrib_bits >> a_idx) & 1) {
+                               const Gwn_VertAttr* a = imm.vertex_format.attribs + a_idx;
+
+/*                             printf("copying %s from vertex %u to %u\n", a->name, imm.vertex_idx - 1, imm.vertex_idx); */
+
+                               GLubyte* data = imm.vertex_data + a->offset;
+                               memcpy(data, data - imm.vertex_format.stride, a->sz);
+                               /* TODO: consolidate copy of adjacent attributes */
+                       }
+               }
+       }
+
+       imm.vertex_idx++;
+       imm.vertex_data += imm.vertex_format.stride;
+       imm.unassigned_attrib_bits = imm.attrib_binding.enabled_bits;
+}
+
+void immVertex2f(uint attrib_id, float x, float y)
+{
+       immAttrib2f(attrib_id, x, y);
+       immEndVertex();
+}
+
+void immVertex3f(uint attrib_id, float x, float y, float z)
+{
+       immAttrib3f(attrib_id, x, y, z);
+       immEndVertex();
+}
+
+void immVertex4f(uint attrib_id, float x, float y, float z, float w)
+{
+       immAttrib4f(attrib_id, x, y, z, w);
+       immEndVertex();
+}
+
+void immVertex2i(uint attrib_id, int x, int y)
+{
+       immAttrib2i(attrib_id, x, y);
+       immEndVertex();
+}
+
+void immVertex2s(uint attrib_id, short x, short y)
+{
+       immAttrib2s(attrib_id, x, y);
+       immEndVertex();
+}
+
+void immVertex2fv(uint attrib_id, const float data[2])
+{
+       immAttrib2f(attrib_id, data[0], data[1]);
+       immEndVertex();
+}
+
+void immVertex3fv(uint attrib_id, const float data[3])
+{
+       immAttrib3f(attrib_id, data[0], data[1], data[2]);
+       immEndVertex();
+}
+
+void immVertex2iv(uint attrib_id, const int data[2])
+{
+       immAttrib2i(attrib_id, data[0], data[1]);
+       immEndVertex();
+}
+
+
+/* --- generic uniform functions --- */
+
+#if 0
+  #if TRUST_NO_ONE
+    #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); assert(uniform);
+  #else
+    #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name);
+  #endif
+#else
+       /* NOTE: It is possible to have uniform fully optimized out from the shader.
+        *       In this case we can't assert failure or allow NULL-pointer dereference.
+        * TODO(sergey): How can we detect existing-but-optimized-out uniform but still
+        *               catch typos in uniform names passed to immUniform*() functions? */
+  #define GET_UNIFORM const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform(imm.shader_interface, name); if (uniform == NULL) return;
+#endif
+
+void immUniform1f(const char* name, float x)
+{
+       GET_UNIFORM
+       glUniform1f(uniform->location, x);
+}
+
+void immUniform2f(const char* name, float x, float y)
+{
+       GET_UNIFORM
+       glUniform2f(uniform->location, x, y);
+}
+
+void immUniform2fv(const char* name, const float data[2])
+{
+       GET_UNIFORM
+       glUniform2fv(uniform->location, 1, data);
+}
+
+void immUniform3f(const char* name, float x, float y, float z)
+{
+       GET_UNIFORM
+       glUniform3f(uniform->location, x, y, z);
+}
+
+void immUniform3fv(const char* name, const float data[3])
+{
+       GET_UNIFORM
+       glUniform3fv(uniform->location, 1, data);
+}
+
+/* can increase this limit or move to another file */
+#define MAX_UNIFORM_NAME_LEN 60
+
+void immUniformArray3fv(const char* bare_name, const float *data, int count)
+{
+       /* look up "name[0]" when given "name" */
+       const size_t len = strlen(bare_name);
+#if TRUST_NO_ONE
+       assert(len <= MAX_UNIFORM_NAME_LEN);
+#endif
+       char name[MAX_UNIFORM_NAME_LEN];
+       strcpy(name, bare_name);
+       name[len + 0] = '[';
+       name[len + 1] = '0';
+       name[len + 2] = ']';
+       name[len + 3] = '\0';
+
+       GET_UNIFORM
+       glUniform3fv(uniform->location, count, data);
+}
+
+void immUniform4f(const char* name, float x, float y, float z, float w)
+{
+       GET_UNIFORM
+       glUniform4f(uniform->location, x, y, z, w);
+}
+
+void immUniform4fv(const char* name, const float data[4])
+{
+       GET_UNIFORM
+       glUniform4fv(uniform->location, 1, data);
+}
+
+void immUniformArray4fv(const char* bare_name, const float *data, int count)
+{
+       /* look up "name[0]" when given "name" */
+       const size_t len = strlen(bare_name);
+#if TRUST_NO_ONE
+       assert(len <= MAX_UNIFORM_NAME_LEN);
+#endif
+       char name[MAX_UNIFORM_NAME_LEN];
+       strcpy(name, bare_name);
+       name[len + 0] = '[';
+       name[len + 1] = '0';
+       name[len + 2] = ']';
+       name[len + 3] = '\0';
+
+       GET_UNIFORM
+       glUniform4fv(uniform->location, count, data);
+}
+
+void immUniformMatrix4fv(const char* name, const float data[4][4])
+{
+       GET_UNIFORM
+       glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (float *)data);
+}
+
+void immUniform1i(const char* name, int x)
+{
+       GET_UNIFORM
+       glUniform1i(uniform->location, x);
+}
+
+void immUniform4iv(const char* name, const int data[4])
+{
+       GET_UNIFORM
+       glUniform4iv(uniform->location, 1, data);
+}
+
+/* --- convenience functions for setting "uniform vec4 color" --- */
+
+void immUniformColor4f(float r, float g, float b, float a)
+{
+       const Gwn_ShaderInput* uniform = GWN_shaderinterface_uniform_builtin(imm.shader_interface, GWN_UNIFORM_COLOR);
+#if TRUST_NO_ONE
+       assert(uniform != NULL);
+#endif
+       glUniform4f(uniform->location, r, g, b, a);
+}
+
+void immUniformColor4fv(const float rgba[4])
+{
+       immUniformColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
+}
+
+void immUniformColor3f(float r, float g, float b)
+{
+       immUniformColor4f(r, g, b, 1.0f);
+}
+
+void immUniformColor3fv(const float rgb[3])
+{
+       immUniformColor4f(rgb[0], rgb[1], rgb[2], 1.0f);
+}
+
+void immUniformColor3fvAlpha(const float rgb[3], float a)
+{
+       immUniformColor4f(rgb[0], rgb[1], rgb[2], a);
+}
+
+/* TODO: v-- treat as sRGB? --v */
+
+void immUniformColor3ub(unsigned char r, unsigned char g, unsigned char b)
+{
+       const float scale = 1.0f / 255.0f;
+       immUniformColor4f(scale * r, scale * g, scale * b, 1.0f);
+}
+
+void immUniformColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
+{
+       const float scale = 1.0f / 255.0f;
+       immUniformColor4f(scale * r, scale * g, scale * b, scale * a);
+}
+
+void immUniformColor3ubv(const unsigned char rgb[3])
+{
+       immUniformColor3ub(rgb[0], rgb[1], rgb[2]);
+}
+
+void immUniformColor3ubvAlpha(const unsigned char rgb[3], unsigned char alpha)
+{
+       immUniformColor4ub(rgb[0], rgb[1], rgb[2], alpha);
+}
+
+void immUniformColor4ubv(const unsigned char rgba[4])
+{
+       immUniformColor4ub(rgba[0], rgba[1], rgba[2], rgba[3]);
+}
+
 void immUniformThemeColor(int color_id)
 {
        float color[4];
index 30672af9c029926ea9917a8e91d9195b55a6528d..4b2fb1b8e8a4560907bd68eac694b80bc944fbb0 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
-/** \file source/blender/gpu/intern/gpu_immediate_util.c
+/** \file blender/gpu/intern/gwn_imm_util.c
  *  \ingroup gpu
+ *
+ * Gawain immediate mode drawing utilities
  */
 
 #include <stdio.h>
@@ -66,6 +68,72 @@ static const int cube_line_index[12][2] = {
        {6, 7},
 };
 
+void immRectf(uint pos, float x1, float y1, float x2, float y2)
+{
+       immBegin(GWN_PRIM_TRI_FAN, 4);
+       immVertex2f(pos, x1, y1);
+       immVertex2f(pos, x2, y1);
+       immVertex2f(pos, x2, y2);
+       immVertex2f(pos, x1, y2);
+       immEnd();
+}
+
+void immRecti(uint pos, int x1, int y1, int x2, int y2)
+{
+       immBegin(GWN_PRIM_TRI_FAN, 4);
+       immVertex2i(pos, x1, y1);
+       immVertex2i(pos, x2, y1);
+       immVertex2i(pos, x2, y2);
+       immVertex2i(pos, x1, y2);
+       immEnd();
+}
+
+void immRectf_fast_with_color(uint pos, uint col, float x1, float y1, float x2, float y2, const float color[4])
+{
+       immAttrib4fv(col, color);
+       immVertex2f(pos, x1, y1);
+       immAttrib4fv(col, color);
+       immVertex2f(pos, x2, y1);
+       immAttrib4fv(col, color);
+       immVertex2f(pos, x2, y2);
+
+       immAttrib4fv(col, color);
+       immVertex2f(pos, x1, y1);
+       immAttrib4fv(col, color);
+       immVertex2f(pos, x2, y2);
+       immAttrib4fv(col, color);
+       immVertex2f(pos, x1, y2);
+}
+
+void immRecti_fast_with_color(uint pos, uint col, int x1, int y1, int x2, int y2, const float color[4])
+{
+       immAttrib4fv(col, color);
+       immVertex2i(pos, x1, y1);
+       immAttrib4fv(col, color);
+       immVertex2i(pos, x2, y1);
+       immAttrib4fv(col, color);
+       immVertex2i(pos, x2, y2);
+
+       immAttrib4fv(col, color);
+       immVertex2i(pos, x1, y1);
+       immAttrib4fv(col, color);
+       immVertex2i(pos, x2, y2);
+       immAttrib4fv(col, color);
+       immVertex2i(pos, x1, y2);
+}
+
+#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])
+{
+       Gwn_VertFormat *format = immVertexFormat();
+       uint pos = add_attrib(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+       immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+       immUniformColor4fv(color);
+       immRecti(pos, x1, y1, x2, y2);
+       immUnbindProgram();
+}
+#endif
+
 /**
  * Pack color into 3 bytes
  *
index 2af1375a6208650410e533b34bc1cd0466296c87..13c6fbea1c6406fca075ca2c495fc76c1fa4a074 100644 (file)
@@ -29,7 +29,7 @@
  *  \ingroup gpu
  */
 
-#include "../../../intern/gawain/gawain/gwn_shader_interface.h"
+#include "GPU_shader_interface.h"
 
 #define SUPPRESS_GENERIC_MATRIX_API
 #define USE_GPU_PY_MATRIX_API  /* only so values are declared */
similarity index 97%
rename from intern/gawain/src/gwn_primitive.c
rename to source/blender/gpu/intern/gpu_primitive.c
index bec638a4972867d3954f8203984c2a99e0da60cc..0f0c28c05dc7a248aa9c861ea778d0453ff2efbf 100644 (file)
@@ -29,8 +29,8 @@
  * Gawain geometric primitives
  */
 
-#include "gwn_primitive.h"
-#include "gwn_primitive_private.h"
+#include "GPU_primitive.h"
+#include "gpu_primitive_private.h"
 
 Gwn_PrimClass GWN_primtype_class(Gwn_PrimType prim_type)
 {
similarity index 99%
rename from intern/gawain/src/gwn_shader_interface.c
rename to source/blender/gpu/intern/gpu_shader_interface.c
index 997d5215d5b135599dcbe1f0ca7c881f9a0ccfaa..56b25726a84c0a9c87c0003b670b875d88e6b527 100644 (file)
@@ -29,9 +29,9 @@
  * Gawain shader interface (C --> GLSL)
  */
 
-#include "gwn_batch_private.h"
-#include "gwn_shader_interface.h"
-#include "gwn_vertex_array_id.h"
+#include "gpu_batch_private.h"
+#include "GPU_shader_interface.h"
+#include "GPU_vertex_array_id.h"
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
index de5439c56386fe37c839a0bdba73af128c2ff1e4..bf54d269fb5af46633eb974fc767f09a711ae7f5 100644 (file)
@@ -26,7 +26,7 @@
 #define __GPU_SHADER_PRIVATE_H__
 
 #include "GPU_glew.h"
-#include "gawain/gwn_shader_interface.h"
+#include "GPU_shader_interface.h"
 
 struct GPUShader {
        GLuint program;  /* handle for full program (links shader stages below) */
similarity index 98%
rename from intern/gawain/src/gwn_vertex_array_id.cpp
rename to source/blender/gpu/intern/gpu_vertex_array_id.cpp
index 04470bf68446edea908e668dfc0c5ef14db8047c..de5be15ec19b2b0063c80157abdff6823d0f0f10 100644 (file)
@@ -34,9 +34,9 @@
  * - free can be called from any thread
  */
 
-#include "gwn_batch_private.h"
-#include "gwn_vertex_array_id.h"
-#include "gwn_context.h"
+#include "gpu_batch_private.h"
+#include "GPU_vertex_array_id.h"
+#include "GPU_context.h"
 #include <vector>
 #include <string.h>
 #include <pthread.h>
similarity index 98%
rename from intern/gawain/src/gwn_vertex_buffer.c
rename to source/blender/gpu/intern/gpu_vertex_buffer.c
index c3440b25da248b0535523c5efbfec6798bea67b4..32f3d4940153d8aee1723b3b3c76252d90609429 100644 (file)
@@ -29,9 +29,9 @@
  * Gawain vertex buffer
  */
 
-#include "gwn_vertex_buffer.h"
-#include "gwn_buffer_id.h"
-#include "gwn_vertex_format_private.h"
+#include "GPU_vertex_buffer.h"
+#include "GPU_buffer_id.h"
+#include "gpu_vertex_format_private.h"
 #include <stdlib.h>
 #include <string.h>
 
similarity index 99%
rename from intern/gawain/src/gwn_vertex_format.c
rename to source/blender/gpu/intern/gpu_vertex_format.c
index 41179ae21eb5f92eb0292ddbe5a0995b9423cea6..bd9f92505645fc3d44a0db7b5fbbd4fbf6fd63b6 100644 (file)
@@ -29,8 +29,8 @@
  * Gawain vertex format
  */
 
-#include "gwn_vertex_format.h"
-#include "gwn_vertex_format_private.h"
+#include "GPU_vertex_format.h"
+#include "gpu_vertex_format_private.h"
 #include <stddef.h>
 #include <string.h>
 
index d79ef070649c0b24ddae67adeda459e46e3ccdf8..1f7a1297448947dba383f31e1b8524a198763051 100644 (file)
@@ -27,8 +27,8 @@
 
 #include <Python.h>
 
-#include "gawain/gwn_batch.h"
-#include "gawain/gwn_vertex_format.h"
+#include "GPU_batch.h"
+#include "GPU_vertex_format.h"
 
 #include "gwn_py_api.h"
 #include "gwn_py_types.h"
index bdf0be9f7e1612b1b8f8876b61cd36e1fe600cee..04c50ac0784c137f6558cfe81e992a41e56a4166 100644 (file)
@@ -27,8 +27,8 @@
 
 #include <Python.h>
 
-#include "gawain/gwn_batch.h"
-#include "gawain/gwn_vertex_format.h"
+#include "GPU_batch.h"
+#include "GPU_vertex_format.h"
 
 #include "BLI_math.h"
 
index d3fef51e9e96d059eedd864de56e8e49f0220c3c..8f921d7850a0549c94779725157c5bc855fe9b87 100644 (file)
@@ -37,6 +37,7 @@ set(INC
        ../nodes
        ../physics
        ../draw
+       ../gpu
        ../../../intern/atomic
        ../../../intern/guardedalloc
        ../../../intern/mikktspace
index 82595527d30dbf5341a4a0137f29bfa5deceb163..af8746a4734890e8be6a6d7d17145d4ae5966635 100644 (file)
@@ -97,7 +97,7 @@
 
 #include "../../../windowmanager/WM_api.h" /* XXX */
 #include "../../../windowmanager/wm_window.h" /* XXX */
-#include "../../../intern/gawain/gawain/gwn_context.h"
+#include "GPU_context.h"
 
 #ifdef WITH_FREESTYLE
 #  include "FRS_freestyle.h"
index d1a7f4ffea1214fd50a8915bbdb97c1cf46c6f54..00e7f77569b35d50c42eee406156dc7b81473cfd 100644 (file)
@@ -69,7 +69,7 @@
 #include "GPU_matrix.h"
 #include "GPU_immediate.h"
 #include "GPU_immediate_util.h"
-#include "GPU_batch.h"
+#include "GPU_context.h"
 #include "GPU_init_exit.h"
 
 #include "DNA_scene_types.h"
index f55fc5703f40c104d559868f6469fa9f477f99ba..669480bf0989b6242c675745f4b287cdf97bb030 100644 (file)
 #include "GPU_immediate.h"
 #include "GPU_material.h"
 #include "GPU_texture.h"
+#include "GPU_context.h"
 #include "BLF_api.h"
 
 #include "UI_resources.h"
 
-#include "../../../intern/gawain/gawain/gwn_context.h"
-
 /* for assert */
 #ifndef NDEBUG
 #  include "BLI_threads.h"