Exemple #1
0
void ShaderEffect_Impl::create_primitives_array(GraphicContext &gc, const ShaderEffectDescription_Impl *description)
{
	prim_array = PrimitivesArray(gc);
	
	int index = 0;
	for (auto it = description->attributes.begin(); it != description->attributes.end(); ++it, index++)
	{
		if (it->second.attribute_type == ShaderEffectDescription_Impl::attribute_type_buffer)
		{
			VertexArrayBuffer buffer = it->second.buffer;
			prim_array.set_attributes(index, buffer, it->second.size, it->second.type, it->second.offset, it->second.stride, it->second.normalize);
			attributes.push_back(buffer);

			num_vertices = description->draw_count;
		}
		else if (it->second.attribute_type == ShaderEffectDescription_Impl::attribute_type_screen_quad)
		{
			Vec4f screen_quad[6] =
			{
				Vec4f(-1.0f,-1.0f, 0.0f, 1.0f),
				Vec4f( 1.0f,-1.0f, 0.0f, 1.0f),
				Vec4f(-1.0f, 1.0f, 0.0f, 1.0f),
				Vec4f( 1.0f, 1.0f, 0.0f, 1.0f),
				Vec4f( 1.0f,-1.0f, 0.0f, 1.0f),
				Vec4f(-1.0f, 1.0f, 0.0f, 1.0f)
			};
			VertexArrayVector<Vec4f> gpu_screen_quad(gc, screen_quad, 6);
			prim_array.set_attributes(index, gpu_screen_quad);
			attributes.push_back(gpu_screen_quad);

			num_vertices = 6;
		}
		else if (it->second.attribute_type == ShaderEffectDescription_Impl::attribute_type_uv_quad)
		{
			Vec4f uv_quad[6] =
			{
				Vec4f( 0.0f, 0.0f, 0.0f, 1.0f),
				Vec4f( 1.0f, 0.0f, 0.0f, 1.0f),
				Vec4f( 0.0f, 1.0f, 0.0f, 1.0f),
				Vec4f( 1.0f, 1.0f, 0.0f, 1.0f),
				Vec4f( 1.0f, 0.0f, 0.0f, 1.0f),
				Vec4f( 0.0f, 1.0f, 0.0f, 1.0f)
			};
			VertexArrayVector<Vec4f> gpu_uv_quad(gc, uv_quad, 6);
			prim_array.set_attributes(index, gpu_uv_quad);
			attributes.push_back(gpu_uv_quad);

			num_vertices = 6;
		}
	}
}
	void GL3GraphicContextProvider::set_primitives_array(const PrimitivesArray &primitives_array)
	{
		GL3PrimitivesArrayProvider *prim_array = static_cast<GL3PrimitivesArrayProvider *>(primitives_array.get_provider());

		OpenGL::set_active(this);
		glBindVertexArray(prim_array->handle);
	}
void D3DGraphicContextProvider::set_primitives_array(const PrimitivesArray &primitives_array)
{
	reset_primitives_array();
	current_prim_array_provider = static_cast<D3DPrimitivesArrayProvider *>(primitives_array.get_provider());
	std::vector<ID3D11Buffer*> buffers;
	std::vector<UINT> strides, offsets;
	current_prim_array_provider->get_vertex_buffers(buffers, strides, offsets);
	if (!buffers.empty())
		window->get_device_context()->IASetVertexBuffers(0, buffers.size(), &buffers[0], &strides[0], &offsets[0]);
}
Exemple #4
0
VertexArrayVector<Type> ModelLOD::upload_vector(GraphicContext &gc, PrimitivesArray &primitives_array, int index, const std::vector<Type> &vec, bool normalize)
{
	if (!vec.empty())
	{
		VertexArrayVector<Type> buffer(gc, vec);
		primitives_array.set_attributes(index, buffer, normalize);
		return buffer;
	}
	else
	{
		return VertexArrayVector<Type>();
	}
}
bool D3DGraphicContextProvider::is_primitives_array_owner(const PrimitivesArray &primitives_array)
{
	D3DPrimitivesArrayProvider *array_provider = static_cast<D3DPrimitivesArrayProvider *>(primitives_array.get_provider());
	if (array_provider)
		return array_provider->get_device() == window->get_device();
	else
		return false;
}
	bool GL3GraphicContextProvider::is_primitives_array_owner(const PrimitivesArray &prim_array)
	{
		GL3PrimitivesArrayProvider *prim_array_provider = dynamic_cast<GL3PrimitivesArrayProvider *>(prim_array.get_provider());
		if (prim_array_provider)
			return prim_array_provider->get_gc_provider() == this;
		else
			return false;
	}
	void GL1GraphicContextProvider::set_primitives_array(const PrimitivesArray &primitives_array)
	{
		GL1PrimitivesArrayProvider * prim_array = static_cast<GL1PrimitivesArrayProvider *>(primitives_array.get_provider());
		if (prim_arrays_set)
			reset_primitives_array();
		set_active();
		prim_arrays_set = true;

		num_set_tex_arrays = 0;

		for (size_t attribute_index = 0; attribute_index < prim_array->attributes.size(); attribute_index++)
		{
			if (!prim_array->attribute_set[attribute_index])
				continue;

			const PrimitivesArrayProvider::VertexData &attribute = prim_array->attributes[attribute_index];

			GL1VertexArrayBufferProvider *vertex_array_ptr = static_cast<GL1VertexArrayBufferProvider *>(attribute.array_provider);
			if (!vertex_array_ptr)
				throw Exception("Invalid BindBuffer Provider");

			const char *data_ptr = ((const char *)vertex_array_ptr->get_data()) + attribute.offset;

			switch (attribute_index)
			{
			case 0: // POSITION
				glEnableClientState(GL_VERTEX_ARRAY);
				glVertexPointer(attribute.size, OpenGL::to_enum(attribute.type), attribute.stride, data_ptr);
				break;
			case 1: // COLOR
				glEnableClientState(GL_COLOR_ARRAY);
				glColorPointer(attribute.size, OpenGL::to_enum(attribute.type), attribute.stride, data_ptr);

				break;
			case 2: // TEXTURE
				primitives_array_texture = attribute;
				primitives_array_texture_set = true;
				break;
			case 3: // TEXINDEX
				primitives_array_texindex = attribute;
				primitives_array_texindex_set = true;
				break;
			case 4: // NORMAL
				glEnableClientState(GL_NORMAL_ARRAY);
				glNormalPointer(OpenGL::to_enum(attribute.type), attribute.stride, data_ptr);
				break;
			}
		}
	}