void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
{
	vertex_stride = _vtx_decl.stride;
	memset(m_elems, 0, sizeof(m_elems));

	m_elems[m_num_elems].SemanticName = "POSITION";
	m_elems[m_num_elems].AlignedByteOffset = 0;
	m_elems[m_num_elems].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	++m_num_elems;

	for (int i = 0; i < 3; i++)
	{
		if (_vtx_decl.normal_offset[i] > 0)
		{
			m_elems[m_num_elems].SemanticName = "NORMAL";
			m_elems[m_num_elems].SemanticIndex = i;
			m_elems[m_num_elems].AlignedByteOffset = _vtx_decl.normal_offset[i];
			m_elems[m_num_elems].Format = VarToD3D(_vtx_decl.normal_gl_type, _vtx_decl.normal_gl_size);
			m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
			++m_num_elems;
		}
	}

	for (int i = 0; i < 2; i++)
	{
		if (_vtx_decl.color_offset[i] > 0)
		{
			m_elems[m_num_elems].SemanticName = "COLOR";
			m_elems[m_num_elems].SemanticIndex = i;
			m_elems[m_num_elems].AlignedByteOffset = _vtx_decl.color_offset[i];
			m_elems[m_num_elems].Format = VarToD3D(_vtx_decl.color_gl_type, 4);
			m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
			++m_num_elems;
		}
	}

	for (int i = 0; i < 8; i++)
	{
		if (_vtx_decl.texcoord_offset[i] > 0)
		{
			m_elems[m_num_elems].SemanticName = "TEXCOORD";
			m_elems[m_num_elems].SemanticIndex = i;
			m_elems[m_num_elems].AlignedByteOffset = _vtx_decl.texcoord_offset[i];
			m_elems[m_num_elems].Format = VarToD3D(_vtx_decl.texcoord_gl_type[i], _vtx_decl.texcoord_size[i]);
			m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
			++m_num_elems;
		}
	}

	if (_vtx_decl.posmtx_offset != -1)
	{
		m_elems[m_num_elems].SemanticName = "BLENDINDICES";
		m_elems[m_num_elems].AlignedByteOffset = _vtx_decl.posmtx_offset;
		m_elems[m_num_elems].Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
		++m_num_elems;
	}
}
Ejemplo n.º 2
0
D3D12_INPUT_ELEMENT_DESC D3DVertexFormat::GetInputElementDescFromAttributeFormat(const AttributeFormat* format, const char* semantic_name, unsigned int semantic_index) const
{
	D3D12_INPUT_ELEMENT_DESC desc = {};

	desc.AlignedByteOffset = format->offset;
	desc.Format = VarToD3D(format->type, format->components);
	desc.InputSlot = 0;
	desc.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
	desc.SemanticName = semantic_name;
	desc.SemanticIndex = semantic_index;

	return desc;
}
Ejemplo n.º 3
0
void D3DVertexFormat::AddInputElementDescFromAttributeFormatIfValid(const AttributeFormat* format, const char* semantic_name, unsigned int semantic_index)
{
	if (!format->enable)
	{
		return;
	}

	D3D12_INPUT_ELEMENT_DESC desc = {};

	desc.AlignedByteOffset = format->offset;
	desc.Format = VarToD3D(format->type, format->components, format->integer);
	desc.InputSlot = 0;
	desc.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
	desc.SemanticName = semantic_name;
	desc.SemanticIndex = semantic_index;

	m_elems[m_num_elems] = desc;
	++m_num_elems;
}
Ejemplo n.º 4
0
void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
{
	vertex_stride = _vtx_decl.stride;
	memset(m_elems, 0, sizeof(m_elems));
	const AttributeFormat* format = &_vtx_decl.position;

	if (format->enable)
	{
		m_elems[m_num_elems].SemanticName = "POSITION";
		m_elems[m_num_elems].AlignedByteOffset = format->offset;
		m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
		m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
		++m_num_elems;
	}

	for (int i = 0; i < 3; i++)
	{
		format = &_vtx_decl.normals[i];
		if (format->enable)
		{
			m_elems[m_num_elems].SemanticName = "NORMAL";
			m_elems[m_num_elems].SemanticIndex = i;
			m_elems[m_num_elems].AlignedByteOffset = format->offset;
			m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
			m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
			++m_num_elems;
		}
	}

	for (int i = 0; i < 2; i++)
	{
		format = &_vtx_decl.colors[i];
		if (format->enable)
		{
			m_elems[m_num_elems].SemanticName = "COLOR";
			m_elems[m_num_elems].SemanticIndex = i;
			m_elems[m_num_elems].AlignedByteOffset = format->offset;
			m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
			m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
			++m_num_elems;
		}
	}

	for (int i = 0; i < 8; i++)
	{
		format = &_vtx_decl.texcoords[i];
		if (format->enable)
		{
			m_elems[m_num_elems].SemanticName = "TEXCOORD";
			m_elems[m_num_elems].SemanticIndex = i;
			m_elems[m_num_elems].AlignedByteOffset = format->offset;
			m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
			m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
			++m_num_elems;
		}
	}

	format = &_vtx_decl.posmtx;
	if (format->enable)
	{
		m_elems[m_num_elems].SemanticName = "BLENDINDICES";
		m_elems[m_num_elems].AlignedByteOffset = format->offset;
		m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
		m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
		++m_num_elems;
	}
}
Ejemplo n.º 5
0
D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration &_vtx_decl) : d3d_decl(nullptr)
{
	vtx_decl = _vtx_decl;
	memset(m_elements, 0, sizeof(m_elements));

	// There's only one stream and it's 0, so the above memset takes care of that - no need to set Stream.
	// Same for method.
	const AttributeFormat* format = &vtx_decl.position;
	int elem_idx = 0;
	if (format->enable)
	{
		// So, here we go. First position:		
		m_elements[elem_idx].Offset = format->offset;
		m_elements[elem_idx].Type = VarToD3D(format->type, format->components);
		m_elements[elem_idx].Usage = D3DDECLUSAGE_POSITION;
		++elem_idx;
	}

	for (int i = 0; i < 3; i++)
	{
		format = &vtx_decl.normals[i];
		if (format->enable)
		{
			m_elements[elem_idx].Offset = format->offset;
			m_elements[elem_idx].Type = VarToD3D(format->type, format->components);
			m_elements[elem_idx].Usage = D3DDECLUSAGE_NORMAL;
			m_elements[elem_idx].UsageIndex = i;
			++elem_idx;
		}
	}

	for (int i = 0; i < 2; i++)
	{
		format = &vtx_decl.colors[i];
		if (format->enable)
		{
			m_elements[elem_idx].Offset = format->offset;
			m_elements[elem_idx].Type = VarToD3D(format->type, 4);
			m_elements[elem_idx].Usage = D3DDECLUSAGE_COLOR;
			m_elements[elem_idx].UsageIndex = i;
			++elem_idx;
		}
	}

	for (int i = 0; i < 8; i++)
	{
		format = &vtx_decl.texcoords[i];
		if (format->enable)
		{
			m_elements[elem_idx].Offset = format->offset;
			m_elements[elem_idx].Type = VarToD3D(format->type, format->components);
			m_elements[elem_idx].Usage = D3DDECLUSAGE_TEXCOORD;
			m_elements[elem_idx].UsageIndex = i;
			++elem_idx;
		}
	}

	if (vtx_decl.posmtx.enable)
	{
		m_elements[elem_idx].Offset = vtx_decl.posmtx.offset;
		m_elements[elem_idx].Usage = D3DDECLUSAGE_BLENDINDICES;
		m_elements[elem_idx].Type = D3DDECLTYPE_D3DCOLOR;
		m_elements[elem_idx].UsageIndex = 0;
		++elem_idx;
	}

	// End marker
	m_elements[elem_idx].Stream = 0xff;
	m_elements[elem_idx].Type = D3DDECLTYPE_UNUSED;
	++elem_idx;
	m_num_elements = elem_idx;
}
Ejemplo n.º 6
0
D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration &_vtx_decl)
    : m_num_elems(0), m_layout12( {}), m_elems()
{
    this->vtx_decl = _vtx_decl;
    memset(m_elems, 0, sizeof(m_elems));
    const AttributeFormat* format = &_vtx_decl.position;

    if (format->enable)
    {
        m_elems[m_num_elems].SemanticName = "POSITION";
        m_elems[m_num_elems].AlignedByteOffset = format->offset;
        m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
        m_elems[m_num_elems].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
        ++m_num_elems;
    }

    for (int i = 0; i < 3; i++)
    {
        format = &_vtx_decl.normals[i];
        if (format->enable)
        {
            m_elems[m_num_elems].SemanticName = "NORMAL";
            m_elems[m_num_elems].SemanticIndex = i;
            m_elems[m_num_elems].AlignedByteOffset = format->offset;
            m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
            m_elems[m_num_elems].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
            ++m_num_elems;
        }
    }

    for (int i = 0; i < 2; i++)
    {
        format = &_vtx_decl.colors[i];
        if (format->enable)
        {
            m_elems[m_num_elems].SemanticName = "COLOR";
            m_elems[m_num_elems].SemanticIndex = i;
            m_elems[m_num_elems].AlignedByteOffset = format->offset;
            m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
            m_elems[m_num_elems].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
            ++m_num_elems;
        }
    }

    for (int i = 0; i < 8; i++)
    {
        format = &_vtx_decl.texcoords[i];
        if (format->enable)
        {
            m_elems[m_num_elems].SemanticName = "TEXCOORD";
            m_elems[m_num_elems].SemanticIndex = i;
            m_elems[m_num_elems].AlignedByteOffset = format->offset;
            m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
            m_elems[m_num_elems].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
            ++m_num_elems;
        }
    }

    format = &_vtx_decl.posmtx;
    if (format->enable)
    {
        m_elems[m_num_elems].SemanticName = "BLENDINDICES";
        m_elems[m_num_elems].AlignedByteOffset = format->offset;
        m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
        m_elems[m_num_elems].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
        ++m_num_elems;
    }

    m_layout12.NumElements = m_num_elems;
    m_layout12.pInputElementDescs = m_elems;
}