Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Erwin <significant.bit@gmail.com>2016-08-04 22:36:20 +0300
committerMike Erwin <significant.bit@gmail.com>2016-08-04 22:36:20 +0300
commit797f1896fa023c0404965b987a7334448857c665 (patch)
treee7c0c3f9e49faba388039ec1a51e6a83d29a6144 /source/blender/gpu/GPU_immediate.h
parent42d816a3d9d63acfc8ef609bc16eb95d44cd75d7 (diff)
OpenGL: immediate mode work-alike
Introducing an immediate mode drawing API that works with modern GL 3.2 core profile. I wrote and tested this using a core context on Mac. This is part of the Gawain library which is Apache 2 licensed. Be very careful not to pull other Blender code into these files. Modifications for the Blender integration: - prefix filenames to match rest of Blender’s GPU libs - include GPU_glew.h instead of <OpenGL/gl3.h> - disable thread-local vars until we figure out how best to do this
Diffstat (limited to 'source/blender/gpu/GPU_immediate.h')
-rw-r--r--source/blender/gpu/GPU_immediate.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h
new file mode 100644
index 00000000000..aeed133645c
--- /dev/null
+++ b/source/blender/gpu/GPU_immediate.h
@@ -0,0 +1,67 @@
+
+// Gawain immediate mode work-alike, take 2
+//
+// This code is part of the Gawain library, with modifications
+// specific to integration with Blender.
+//
+// Copyright 2016 Mike Erwin
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+
+#pragma once
+
+#include "GPU_glew.h"
+#include <stdbool.h>
+
+#define PER_THREAD
+// #define PER_THREAD __thread
+// MSVC uses __declspec(thread) for C code
+
+#define MAX_VERTEX_ATTRIBS 16
+
+#define TRUST_NO_ONE 1
+
+typedef enum {
+ KEEP_FLOAT,
+ KEEP_INT,
+ NORMALIZE_INT_TO_FLOAT, // 127 (ubyte) -> 0.5 (and so on for other int types)
+ CONVERT_INT_TO_FLOAT // 127 (any int type) -> 127.0
+} VertexFetchMode;
+
+typedef struct {
+ GLenum comp_type;
+ unsigned comp_ct; // 1 to 4
+ unsigned sz; // size in bytes, 1 to 16
+ unsigned offset; // from beginning of vertex, in bytes
+ VertexFetchMode fetch_mode;
+ char* name; // TODO: shared allocation of all names within a VertexFormat
+} Attrib;
+
+typedef struct {
+ unsigned attrib_ct; // 0 to 16 (MAX_VERTEX_ATTRIBS)
+ unsigned stride; // stride in bytes, 1 to 256
+ bool packed;
+ Attrib attribs[MAX_VERTEX_ATTRIBS]; // TODO: variable-size attribs array
+} VertexFormat;
+
+void clear_VertexFormat(VertexFormat*);
+unsigned add_attrib(VertexFormat*, const char* name, GLenum comp_type, unsigned comp_ct, VertexFetchMode);
+void pack(VertexFormat*);
+// unsigned attrib_idx(const VertexFormat*, const char* name);
+void bind_attrib_locations(const VertexFormat*, GLuint program);
+
+extern PER_THREAD VertexFormat immVertexFormat; // so we don't have to copy or pass around
+
+void immInit(void);
+void immDestroy(void);
+
+void immBegin(GLenum primitive, unsigned vertex_ct);
+void immEnd(void);
+
+void immAttrib1f(unsigned attrib_id, float x);
+void immAttrib3f(unsigned attrib_id, float x, float y, float z);
+
+void immEndVertex(void); // and move on to the next vertex