diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-11-14 05:18:51 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-11-14 05:18:51 +0300 |
commit | ffc26fc5a89c3e2e4477d9df92876a6b730b5590 (patch) | |
tree | eff15e8524938e8a5cfa23970498338f4eaccfc1 /source/blender/gpu/gawain | |
parent | 1dbe26f76ced8f9824dde78c5985cc26b844f5bd (diff) |
Gawain: add support for 10_10_10 vertex format
Most useful for packed normals, which take 1/3 the space of float32 normals.
2-bit alpha|w component is ignored for now.
Batch API can use these now, will add support to immediate mode API if desired.
Enabling on Windows first. Will enable on all platforms after we switch Blender to core profile.
Diffstat (limited to 'source/blender/gpu/gawain')
-rw-r--r-- | source/blender/gpu/gawain/vertex_format.c | 41 | ||||
-rw-r--r-- | source/blender/gpu/gawain/vertex_format.h | 17 |
2 files changed, 57 insertions, 1 deletions
diff --git a/source/blender/gpu/gawain/vertex_format.c b/source/blender/gpu/gawain/vertex_format.c index 894785551d3..671b979a810 100644 --- a/source/blender/gpu/gawain/vertex_format.c +++ b/source/blender/gpu/gawain/vertex_format.c @@ -135,7 +135,11 @@ unsigned add_attrib(VertexFormat* format, const char* name, VertexCompType comp_ attrib->name = copy_attrib_name(format, name); attrib->comp_type = comp_type; +#if USE_10_10_10 + attrib->comp_ct = (comp_type == COMP_I10) ? 4 : comp_ct; // system needs 10_10_10_2 to be 4 or BGRA +#else attrib->comp_ct = comp_ct; +#endif attrib->sz = attrib_sz(attrib); attrib->offset = 0; // offsets & stride are calculated later (during pack) attrib->fetch_mode = fetch_mode; @@ -203,3 +207,40 @@ void VertexFormat_pack(VertexFormat* format) format->stride = offset + end_padding; format->packed = true; } + + +#if USE_10_10_10 + +// OpenGL ES packs in a different order as desktop GL but component conversion is the same. +// Of the code here, only struct PackedNormal needs to change. + +#define SIGNED_INT_10_MAX 511 +#define SIGNED_INT_10_MIN -512 + +static int clampi(int x, int min_allowed, int max_allowed) + { +#if TRUST_NO_ONE + assert(min_allowed <= max_allowed); +#endif + + if (x < min_allowed) + return min_allowed; + else if (x > max_allowed) + return max_allowed; + else + return x; + } + +static int quantize(float x) + { + int qx = x * 511.0f; + return clampi(qx, SIGNED_INT_10_MIN, SIGNED_INT_10_MAX); + } + +PackedNormal convert_i10_v3(const float data[3]) + { + PackedNormal n = { .x = quantize(data[0]), .y = quantize(data[1]), .z = quantize(data[2]) }; + return n; + } + +#endif // USE_10_10_10 diff --git a/source/blender/gpu/gawain/vertex_format.h b/source/blender/gpu/gawain/vertex_format.h index 8bf20d54894..66477b0cfc7 100644 --- a/source/blender/gpu/gawain/vertex_format.h +++ b/source/blender/gpu/gawain/vertex_format.h @@ -17,7 +17,7 @@ #define AVG_VERTEX_ATTRIB_NAME_LEN 5 #define VERTEX_ATTRIB_NAMES_BUFFER_LEN ((AVG_VERTEX_ATTRIB_NAME_LEN + 1) * MAX_VERTEX_ATTRIBS) -#define USE_10_10_10 0 +#define USE_10_10_10 defined(_WIN32) // (GLEW_VERSION_3_3 || GLEW_ARB_vertex_type_2_10_10_10_rev) // ^-- this is only guaranteed on Windows right now, will be true on all platforms soon @@ -66,6 +66,21 @@ void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src); unsigned add_attrib(VertexFormat*, const char* name, VertexCompType, unsigned comp_ct, VertexFetchMode); +// format conversion + +#if USE_10_10_10 + +typedef struct { + int x : 10; + int y : 10; + int z : 10; + int w : 2; // ignored for our purposes +} PackedNormal; + +PackedNormal convert_i10_v3(const float data[3]); + +#endif // USE_10_10_10 + // for internal use void VertexFormat_pack(VertexFormat*); unsigned padding(unsigned offset, unsigned alignment); |