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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user