Get the latest Blender, older versions, or experimental builds.
Stay up-to-date with the new features in the latest Blender releases.
Access production assets and knowledge from the open movies.
Documentation on the usage and features in Blender.
Latest development updates, by Blender developers.
Guidelines, release notes and development docs.
A platform to collect and share results of the Blender Benchmark.
The yearly event that brings the community together.
Support core development with a monthly contribution.
Perform a single donation with more payment options available.
// Gawain vertex attribute binding
//
// This code is part of the Gawain library, with modifications
// specific to integration with Blender.
// Copyright 2016 Mike Erwin
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "attrib_binding.h"
#include "attrib_binding_private.h"
#include <stddef.h>
#if MAX_VERTEX_ATTRIBS != 16
#error "attrib binding code assumes MAX_VERTEX_ATTRIBS = 16"
#endif
void AttribBinding_clear(AttribBinding* binding)
{
binding->loc_bits = 0;
binding->enabled_bits = 0;
}
unsigned read_attrib_location(const AttribBinding* binding, unsigned a_idx)
#if TRUST_NO_ONE
assert(a_idx < MAX_VERTEX_ATTRIBS);
assert(binding->enabled_bits & (1 << a_idx));
return (binding->loc_bits >> (4 * a_idx)) & 0xF;
static void write_attrib_location(AttribBinding* binding, unsigned a_idx, unsigned location)
assert(location < MAX_VERTEX_ATTRIBS);
const unsigned shift = 4 * a_idx;
const uint64_t mask = ((uint64_t)0xF) << shift;
// overwrite this attrib's previous location
binding->loc_bits = (binding->loc_bits & ~mask) | (location << shift);
// mark this attrib as enabled
binding->enabled_bits |= 1 << a_idx;
void get_attrib_locations(const VertexFormat* format, AttribBinding* binding, const ShaderInterface* shaderface)
AttribBinding_clear(binding);
for (unsigned a_idx = 0; a_idx < format->attrib_ct; ++a_idx)
const Attrib* a = format->attribs + a_idx;
for (unsigned n_idx = 0; n_idx < a->name_ct; ++n_idx)
const ShaderInput* input = ShaderInterface_attrib(shaderface, a->name[n_idx]);
assert(input != NULL);
// TODO: make this a recoverable runtime error? indicates mismatch between vertex format and program
write_attrib_location(binding, a_idx, input->location);