コード例 #1
0
	ComPtr<ID3D11InputLayout> D3DPrimitivesArrayProvider::create_input_layout(D3DProgramObjectProvider *program)
	{
		DataBuffer shader_bytecode = program->get_shader_bytecode(shadertype_vertex);

		std::vector<D3D11_INPUT_ELEMENT_DESC> elements;
		for (std::map<int, D3DProgramObjectProvider::AttributeBinding>::iterator it = program->attribute_bindings.begin(); it != program->attribute_bindings.end(); ++it)
		{
			int attrib_location = it->first;
			if (attrib_location < (int)attributes_data.size() && attributes_set[attrib_location])
			{
				D3D11_INPUT_ELEMENT_DESC desc;
				desc.SemanticName = it->second.semantic_name.c_str();
				desc.SemanticIndex = it->second.semantic_index;
				desc.Format = to_d3d_format(attributes_data[attrib_location], attributes_normalize[attrib_location]);
				desc.InputSlot = attrib_location;
				desc.AlignedByteOffset = attributes_data[attrib_location].offset;
				desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
				desc.InstanceDataStepRate = 0;
				elements.push_back(desc);
			}
		}

		ComPtr<ID3D11InputLayout> input_layout;
		HRESULT result = device->CreateInputLayout(&elements[0], elements.size(), shader_bytecode.get_data(), shader_bytecode.get_size(), input_layout.output_variable());
		D3DTarget::throw_if_failed("CreateInputLayout failed", result);
		return input_layout;
	}
コード例 #2
0
void D3DTextureProvider::create_3d(int width, int height, int depth, int array_size, TextureFormat texture_format, int levels)
{
	D3D11_TEXTURE3D_DESC texture_desc;
	texture_desc.Width = width;
	texture_desc.Height = height;
	texture_desc.MipLevels = levels;
	texture_desc.Depth = depth;
	texture_desc.Format = to_d3d_format(texture_format);
	texture_desc.Usage = D3D11_USAGE_DEFAULT;
	texture_desc.CPUAccessFlags = 0;
	texture_desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;

	UINT bind_flags_with_compute = 0;
	UINT bind_flags_without_compute = 0;

	if (PixelBuffer::is_compressed(texture_format))
	{
		bind_flags_without_compute = D3D11_BIND_SHADER_RESOURCE;
	}
	else
	{
		bind_flags_without_compute = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
		bind_flags_with_compute = bind_flags_without_compute | D3D11_BIND_UNORDERED_ACCESS;

		texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
	}

	texture_desc.BindFlags = bind_flags_with_compute;

	HRESULT result = data->handles.front()->device->CreateTexture3D(&texture_desc, 0, (ID3D11Texture3D **) (data->handles.front()->texture.output_variable()));
	if (result == E_INVALIDARG && bind_flags_with_compute != bind_flags_without_compute)
	{
		texture_desc.BindFlags = bind_flags_without_compute;
		result = data->handles.front()->device->CreateTexture3D(&texture_desc, 0, (ID3D11Texture3D **) (data->handles.front()->texture.output_variable()));
	}

	D3DTarget::throw_if_failed("ID3D11Device.CreateTexture3D failed", result);
}
コード例 #3
0
void D3DGraphicContextProvider::draw_primitives_elements_instanced(PrimitivesType type, int count, ElementArrayBufferProvider *array_provider, VertexAttributeDataType indices_type, void *offset, int instance_count)
{
	set_primitives_elements(array_provider);
	apply_input_layout();
	window->get_device_context()->IASetPrimitiveTopology(to_d3d_primitive_topology(type));
	window->get_device_context()->IASetIndexBuffer(current_element_array_provider->get_buffer(window->get_device()), to_d3d_format(indices_type), 0);
	window->validate_context();
	window->get_device_context()->DrawIndexedInstanced(count, instance_count, to_d3d_index_location(indices_type, reinterpret_cast<UINT>(offset)), 0, 0);
	reset_primitives_elements();
}
コード例 #4
0
void D3DGraphicContextProvider::draw_primitives_elements(PrimitivesType type, int count, VertexAttributeDataType indices_type, size_t offset)
{
	apply_input_layout();
	window->get_device_context()->IASetPrimitiveTopology(to_d3d_primitive_topology(type));
	window->get_device_context()->IASetIndexBuffer(current_element_array_provider->get_buffer(window->get_device()), to_d3d_format(indices_type), 0);
	window->validate_context();
	window->get_device_context()->DrawIndexed(count, to_d3d_index_location(indices_type, offset), 0);
}
コード例 #5
0
void D3DTextureProvider::create_2d(int width, int height, int depth, int array_size, TextureFormat texture_format, int levels)
{
	D3D11_TEXTURE2D_DESC texture_desc;
	texture_desc.Width = width;
	texture_desc.Height = height;
	texture_desc.MipLevels = levels;
	texture_desc.Format = to_d3d_format(texture_format);
	texture_desc.SampleDesc.Count = 1;
	texture_desc.SampleDesc.Quality = 0;
	texture_desc.Usage = D3D11_USAGE_DEFAULT;
	texture_desc.CPUAccessFlags = 0;
	texture_desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;

	if (data->texture_dimensions == texture_cube)
	{
		texture_desc.ArraySize = 6;
		texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
	}
	else if (data->texture_dimensions == texture_cube_array)
	{
		texture_desc.ArraySize = 6 * array_size;
		texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
	}
	else
	{
		texture_desc.ArraySize = array_size;
	}

	UINT bind_flags_with_compute = 0;
	UINT bind_flags_without_compute = 0;

	if (is_stencil_or_depth_format(texture_format))
	{
		texture_desc.MipLevels = 1;

		bind_flags_without_compute = D3D11_BIND_DEPTH_STENCIL;
		bind_flags_with_compute = bind_flags_without_compute;
	}
	else if (PixelBuffer::is_compressed(texture_format))
	{
		bind_flags_without_compute = D3D11_BIND_SHADER_RESOURCE;
		bind_flags_with_compute = bind_flags_without_compute;
	}
	else
	{
		bind_flags_without_compute = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
		bind_flags_with_compute = bind_flags_without_compute | D3D11_BIND_UNORDERED_ACCESS;

		texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_GENERATE_MIPS;
	}

	texture_desc.BindFlags = bind_flags_with_compute;

	HRESULT result = data->handles.front()->device->CreateTexture2D(&texture_desc, 0, (ID3D11Texture2D **) (data->handles.front()->texture.output_variable()));
	if (result == E_INVALIDARG && bind_flags_with_compute != bind_flags_without_compute)
	{
		texture_desc.BindFlags = bind_flags_without_compute;
		result = data->handles.front()->device->CreateTexture2D(&texture_desc, 0, (ID3D11Texture2D **) (data->handles.front()->texture.output_variable()));
	}

	D3DTarget::throw_if_failed("ID3D11Device.CreateTexture2D failed", result);
}