• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ VertexDecl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中VertexDecl的典型用法代码示例。如果您正苦于以下问题:C++ VertexDecl类的具体用法?C++ VertexDecl怎么用?C++ VertexDecl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VertexDecl类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: read

	int32_t read(bx::ReaderI* _reader, VertexDecl& _decl, bx::Error* _err)
	{
		BX_ERROR_SCOPE(_err);

		int32_t total = 0;

		uint8_t numAttrs;
		total += bx::read(_reader, numAttrs, _err);

		uint16_t stride;
		total += bx::read(_reader, stride, _err);

		if (!_err->isOk() )
		{
			return total;
		}

		_decl.begin();

		for (uint32_t ii = 0; ii < numAttrs; ++ii)
		{
			uint16_t offset;
			total += bx::read(_reader, offset, _err);

			uint16_t attribId = 0;
			total += bx::read(_reader, attribId, _err);

			uint8_t num;
			total += bx::read(_reader, num, _err);

			uint16_t attribTypeId;
			total += bx::read(_reader, attribTypeId, _err);

			bool normalized;
			total += bx::read(_reader, normalized, _err);

			bool asInt;
			total += bx::read(_reader, asInt, _err);

			if (!_err->isOk() )
			{
				return total;
			}

			Attrib::Enum     attr = idToAttrib(attribId);
			AttribType::Enum type = idToAttribType(attribTypeId);
			if (Attrib::Count     != attr
			&&  AttribType::Count != type)
			{
				_decl.add(attr, num, type, normalized, asInt);
				_decl.m_offset[attr] = offset;
			}
		}

		_decl.end();
		_decl.m_stride = stride;

		return total;
	}
开发者ID:MikePopoloski,项目名称:bgfx,代码行数:59,代码来源:vertexdecl.cpp


示例2: sizeof

void Model_Sonic::evaluatePrimitive(Primitive &primitive) {
	/* Create the actual IBO and VBO structures. */

	if (primitive.invalid || primitive.indices.empty() || primitive.vertices.empty())
		return;

	// Create the index buffer

	primitive.indexBuffer.setSize(primitive.indices.size(), sizeof(uint16), GL_UNSIGNED_SHORT);

	uint16 *indices = (uint16 *) primitive.indexBuffer.getData();
	memcpy(indices, &primitive.indices[0], primitive.indices.size() * sizeof(uint16));

	// Create vertex buffer

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VCOLOR   , 4, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VTCOORD  , 2, GL_FLOAT));

	primitive.vertexBuffer.setVertexDeclInterleave(primitive.vertices.size(), vertexDecl);

	float *vData = (float *) primitive.vertexBuffer.getData();
	for (PrimitiveVertices::const_iterator v = primitive.vertices.begin(); v != primitive.vertices.end(); ++v) {
		/* To get the absolute position of the vertex, transform it by the absolute
		 * position of its base node. Use an identity matrix as a fallback. */

		// TODO: For some primitives, we need to calculate the weighted average of several matrices
		Common::TransformationMatrix matrix;
		if (!v->nodes.empty() && v->nodes[0].node)
			matrix = v->nodes[0].node->getAsolutePosition();

		const Common::Vector3 pos = matrix * v->vertex;

		*vData++ = pos[0];
		*vData++ = pos[1];
		*vData++ = pos[2];

		*vData++ = v->normal[0];
		*vData++ = v->normal[1];
		*vData++ = v->normal[2];

		*vData++ = v->color[0];
		*vData++ = v->color[1];
		*vData++ = v->color[2];
		*vData++ = v->color[3];

		*vData++ = v->texCoord[0];
		*vData++ = v->texCoord[1];
	}

}
开发者ID:Glyth,项目名称:xoreos,代码行数:54,代码来源:model_sonic.cpp


示例3: write

	int32_t write(bx::WriterI* _writer, const VertexDecl& _decl, bx::Error* _err)
	{
		BX_ERROR_SCOPE(_err);

		int32_t total = 0;
		uint8_t numAttrs = 0;

		for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
		{
			numAttrs += UINT16_MAX == _decl.m_attributes[attr] ? 0 : 1;
		}

		total += bx::write(_writer, numAttrs, _err);
		total += bx::write(_writer, _decl.m_stride, _err);

		for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
		{
			if (UINT16_MAX != _decl.m_attributes[attr])
			{
				uint8_t num;
				AttribType::Enum type;
				bool normalized;
				bool asInt;
				_decl.decode(Attrib::Enum(attr), num, type, normalized, asInt);
				total += bx::write(_writer, _decl.m_offset[attr], _err);
				total += bx::write(_writer, s_attribToId[attr].id, _err);
				total += bx::write(_writer, num, _err);
				total += bx::write(_writer, s_attribTypeToId[type].id, _err);
				total += bx::write(_writer, normalized, _err);
				total += bx::write(_writer, asInt, _err);
			}
		}

		return total;
	}
开发者ID:MikePopoloski,项目名称:bgfx,代码行数:35,代码来源:vertexdecl.cpp


示例4: dump

	void dump(const VertexDecl& _decl)
	{
		if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
		{
			dbgPrintf("vertexdecl %08x (%08x), stride %d\n"
				, _decl.m_hash
				, bx::hashMurmur2A(_decl.m_attributes)
				, _decl.m_stride
				);

			for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
			{
				if (UINT16_MAX != _decl.m_attributes[attr])
				{
					uint8_t num;
					AttribType::Enum type;
					bool normalized;
					bool asInt;
					_decl.decode(Attrib::Enum(attr), num, type, normalized, asInt);

					dbgPrintf("\tattr %d - %s, num %d, type %d, norm %d, asint %d, offset %d\n"
						, attr
						, getAttribName(Attrib::Enum(attr) )
						, num
						, type
						, normalized
						, asInt
						, _decl.m_offset[attr]
					);
				}
			}
		}
	}
开发者ID:nikoxd123,项目名称:Torque6,代码行数:33,代码来源:vertexdecl.cpp


示例5: write

	int32_t write(bx::WriterI* _writer, const VertexDecl& _decl)
	{
		int32_t total = 0;
		uint8_t numAttrs = 0;

		for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
		{
			numAttrs += 0xff == _decl.m_attributes[attr] ? 0 : 1;
		}

		total += bx::write(_writer, numAttrs);
		total += bx::write(_writer, _decl.m_stride);

		for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
		{
			if (0xff != _decl.m_attributes[attr])
			{
				uint8_t num;
				AttribType::Enum type;
				bool normalized;
				bool asInt;
				_decl.decode(Attrib::Enum(attr), num, type, normalized, asInt);
				total += bx::write(_writer, _decl.m_offset[attr]);
				total += bx::write(_writer, s_attribToId[attr].id);
				total += bx::write(_writer, num);
				total += bx::write(_writer, s_attribTypeToId[type].id);
				total += bx::write(_writer, normalized);
				total += bx::write(_writer, asInt);
			}
		}

		return total;
	}
开发者ID:Akaito,项目名称:bgfx,代码行数:33,代码来源:vertexdecl.cpp


示例6: read

	int32_t read(bx::ReaderI* _reader, VertexDecl& _decl)
	{
		int32_t total = 0;

		uint8_t numAttrs;
		total += bx::read(_reader, numAttrs);

		uint16_t stride;
		total += bx::read(_reader, stride);

		_decl.begin();

		for (uint32_t ii = 0; ii < numAttrs; ++ii)
		{
			uint16_t offset;
			total += bx::read(_reader, offset);

			uint16_t attribId = 0;
			total += bx::read(_reader, attribId);

			uint8_t num;
			total += bx::read(_reader, num);

			uint16_t attribTypeId;
			total += bx::read(_reader, attribTypeId);

			bool normalized;
			total += bx::read(_reader, normalized);

			bool asInt;
			total += bx::read(_reader, asInt);

			Attrib::Enum     attr = idToAttrib(attribId);
			AttribType::Enum type = idToAttribType(attribTypeId);
			if (Attrib::Count     != attr
			&&  AttribType::Count != type)
			{
				_decl.add(attr, num, type, normalized, asInt);
				_decl.m_offset[attr] = offset;
			}
		}

		_decl.end();
		_decl.m_stride = stride;

		return total;
	}
开发者ID:nikoxd123,项目名称:Torque6,代码行数:47,代码来源:vertexdecl.cpp


示例7: evaluateTextures


//.........这里部分代码省略.........
	std::vector<TexturePaintLayer> layers;
	layers.resize(layersCount);

	for (uint32 l = 0; l < layersCount; l++) {
		ctx.mdb->seek(ctx.offRawData + layersOffset + l * 52);

		layers[l].hasTexture = ctx.mdb->readByte() == 1;
		if (!layers[l].hasTexture)
			continue;

		ctx.mdb->skip(3); // Unknown
		ctx.mdb->skip(4); // Offset to material

		layers[l].texture = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

		uint32 weightsOffset, weightsCount;
		Model::readArrayDef(*ctx.mdb, weightsOffset, weightsCount);

		ctx.mdb->seek(ctx.offRawData + weightsOffset);
		layers[l].weights.resize(weightsCount);

		for (std::vector<float>::iterator w = layers[l].weights.begin(); w != layers[l].weights.end(); ++w)
			*w = ctx.mdb->readIEEEFloatLE();
	}

	std::vector<Common::UString> textures;
	textures.push_back(lightMapName);

	evaluateTextures(1, textures, 0, tVertsCount, dayNightLightMaps, lightMapName);

	loadTextures(textures);

	size_t texCount = textures.size();

	// Read vertices

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	for (uint t = 0; t < texCount; t++)
		vertexDecl.push_back(VertexAttrib(VTCOORD + t, 2, GL_FLOAT));

	_vertexBuffer.setVertexDeclLinear(vertexCount, vertexDecl);

	// Read vertex position
	ctx.mdb->seek(ctx.offRawData + vertexOffset);
	float *v = reinterpret_cast<float *>(_vertexBuffer.getData(0));
	for (uint32 i = 0; i < vertexCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read vertex normals
	assert(normalsCount == vertexCount);
	ctx.mdb->seek(ctx.offRawData + normalsOffset);
	v = reinterpret_cast<float *>(_vertexBuffer.getData(1));
	for (uint32 i = 0; i < normalsCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read texture coordinates
	for (uint t = 0; t < texCount; t++) {

		ctx.mdb->seek(ctx.offRawData + tVertsOffset[t]);
		v = reinterpret_cast<float *>(_vertexBuffer.getData(2 + t));
		for (uint32 i = 0; i < tVertsCount[t]; i++) {
			if (i < tVertsCount[t]) {
				*v++ = ctx.mdb->readIEEEFloatLE();
				*v++ = ctx.mdb->readIEEEFloatLE();
			} else {
				*v++ = 0.0f;
				*v++ = 0.0f;
			}
		}
	}


	// Read faces

	_indexBuffer.setSize(facesCount * 3, sizeof(uint32), GL_UNSIGNED_INT);

	ctx.mdb->seek(ctx.offRawData + facesOffset);
	uint32 *f = reinterpret_cast<uint32 *>(_indexBuffer.getData());
	for (uint32 i = 0; i < facesCount; i++) {
		// Vertex indices
		*f++ = ctx.mdb->readUint32LE();
		*f++ = ctx.mdb->readUint32LE();
		*f++ = ctx.mdb->readUint32LE();

		ctx.mdb->skip(68); // Unknown
	}

	createBound();

	ctx.mdb->seek(endPos);
}
开发者ID:clone2727,项目名称:xoreos,代码行数:101,代码来源:model_witcher.cpp


示例8: readTextures


//.........这里部分代码省略.........
	uint32 biNormalsOffset, biNormalsCount;
	Model::readArrayDef(*ctx.mdb, biNormalsOffset, biNormalsCount);

	uint32 tVertsOffset[4], tVertsCount[4];
	for (uint t = 0; t < 4; t++)
		Model::readArrayDef(*ctx.mdb, tVertsOffset[t], tVertsCount[t]);

	uint32 unknownOffset, unknownCount;
	Model::readArrayDef(*ctx.mdb, unknownOffset, unknownCount);

	uint32 facesOffset, facesCount;
	Model::readArrayDef(*ctx.mdb, facesOffset, facesCount);

	if (ctx.fileVersion == 133)
		ctx.offTexData = ctx.mdb->readUint32LE();


	if ((vertexCount == 0) || (facesCount == 0)) {
		ctx.mdb->seek(endPos);
		return;
	}

	std::vector<Common::UString> textures;
	readTextures(ctx, textures);

	evaluateTextures(4, textures, texture, tVertsCount, dayNightLightMaps, lightMapName);

	loadTextures(textures);

	size_t texCount = textures.size();

	// Read vertices

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	for (uint t = 0; t < texCount; t++)
		vertexDecl.push_back(VertexAttrib(VTCOORD + t, 2, GL_FLOAT));

	_vertexBuffer.setVertexDeclLinear(vertexCount, vertexDecl);

	// Read vertex position
	ctx.mdb->seek(ctx.offRawData + vertexOffset);
	float *v = reinterpret_cast<float *>(_vertexBuffer.getData(0));
	for (uint32 i = 0; i < vertexCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read vertex normals
	assert(normalsCount == vertexCount);
	ctx.mdb->seek(ctx.offRawData + normalsOffset);
	v = reinterpret_cast<float *>(_vertexBuffer.getData(1));
	for (uint32 i = 0; i < normalsCount; i++) {
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
	}

	// Read texture coordinates
	for (uint t = 0; t < texCount; t++) {

		ctx.mdb->seek(ctx.offRawData + tVertsOffset[t]);
		v = reinterpret_cast<float *>(_vertexBuffer.getData(2 + t));
开发者ID:clone2727,项目名称:xoreos,代码行数:67,代码来源:model_witcher.cpp


示例9: vertexUnpack

	void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index)
	{
		if (!_decl.has(_attr) )
		{
			bx::memSet(_output, 0, 4*sizeof(float) );
			return;
		}

		uint32_t stride = _decl.getStride();
		uint8_t* data = (uint8_t*)_data + _index*stride + _decl.getOffset(_attr);

		uint8_t num;
		AttribType::Enum type;
		bool normalized;
		bool asInt;
		_decl.decode(_attr, num, type, normalized, asInt);

		switch (type)
		{
		default:
		case AttribType::Uint8:
			{
				uint8_t* packed = (uint8_t*)data;
				if (asInt)
				{
					switch (num)
					{
					default: *_output++ = (float(*packed++) - 128.0f)*1.0f/127.0f; BX_FALLTHROUGH;
					case 3:  *_output++ = (float(*packed++) - 128.0f)*1.0f/127.0f; BX_FALLTHROUGH;
					case 2:  *_output++ = (float(*packed++) - 128.0f)*1.0f/127.0f; BX_FALLTHROUGH;
					case 1:  *_output++ = (float(*packed++) - 128.0f)*1.0f/127.0f;
					}
				}
				else
				{
					switch (num)
					{
					default: *_output++ = float(*packed++)*1.0f/255.0f; BX_FALLTHROUGH;
					case 3:  *_output++ = float(*packed++)*1.0f/255.0f; BX_FALLTHROUGH;
					case 2:  *_output++ = float(*packed++)*1.0f/255.0f; BX_FALLTHROUGH;
					case 1:  *_output++ = float(*packed++)*1.0f/255.0f;
					}
				}
			}
			break;

		case AttribType::Uint10:
			{
				uint32_t packed = *(uint32_t*)data;
				if (asInt)
				{
					switch (num)
					{
					default: BX_FALLTHROUGH;
					case 3: *_output++ = (float(packed & 0x3ff) - 512.0f)*1.0f/511.0f; packed >>= 10; BX_FALLTHROUGH;
					case 2: *_output++ = (float(packed & 0x3ff) - 512.0f)*1.0f/511.0f; packed >>= 10; BX_FALLTHROUGH;
					case 1: *_output++ = (float(packed & 0x3ff) - 512.0f)*1.0f/511.0f;
					}
				}
				else
				{
					switch (num)
					{
					default: BX_FALLTHROUGH;
					case 3: *_output++ = float(packed & 0x3ff)*1.0f/1023.0f; packed >>= 10; BX_FALLTHROUGH;
					case 2: *_output++ = float(packed & 0x3ff)*1.0f/1023.0f; packed >>= 10; BX_FALLTHROUGH;
					case 1: *_output++ = float(packed & 0x3ff)*1.0f/1023.0f;
					}
				}
			}
			break;

		case AttribType::Int16:
			{
				int16_t* packed = (int16_t*)data;
				if (asInt)
				{
					switch (num)
					{
					default: *_output++ = float(*packed++)*1.0f/32767.0f; BX_FALLTHROUGH;
					case 3:  *_output++ = float(*packed++)*1.0f/32767.0f; BX_FALLTHROUGH;
					case 2:  *_output++ = float(*packed++)*1.0f/32767.0f; BX_FALLTHROUGH;
					case 1:  *_output++ = float(*packed++)*1.0f/32767.0f;
					}
				}
				else
				{
					switch (num)
					{
					default: *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; BX_FALLTHROUGH;
					case 3:  *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; BX_FALLTHROUGH;
					case 2:  *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f; BX_FALLTHROUGH;
					case 1:  *_output++ = (float(*packed++) + 32768.0f)*1.0f/65535.0f;
					}
				}
			}
			break;

		case AttribType::Half:
			{
//.........这里部分代码省略.........
开发者ID:MikePopoloski,项目名称:bgfx,代码行数:101,代码来源:vertexdecl.cpp


示例10: vertexPack

	void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index)
	{
		if (!_decl.has(_attr) )
		{
			return;
		}

		uint32_t stride = _decl.getStride();
		uint8_t* data = (uint8_t*)_data + _index*stride + _decl.getOffset(_attr);

		uint8_t num;
		AttribType::Enum type;
		bool normalized;
		bool asInt;
		_decl.decode(_attr, num, type, normalized, asInt);

		switch (type)
		{
		default:
		case AttribType::Uint8:
			{
				uint8_t* packed = (uint8_t*)data;
				if (_inputNormalized)
				{
					if (asInt)
					{
						switch (num)
						{
						default: *packed++ = uint8_t(*_input++ * 127.0f + 128.0f); BX_FALLTHROUGH;
						case 3:  *packed++ = uint8_t(*_input++ * 127.0f + 128.0f); BX_FALLTHROUGH;
						case 2:  *packed++ = uint8_t(*_input++ * 127.0f + 128.0f); BX_FALLTHROUGH;
						case 1:  *packed++ = uint8_t(*_input++ * 127.0f + 128.0f);
						}
					}
					else
					{
						switch (num)
						{
						default: *packed++ = uint8_t(*_input++ * 255.0f); BX_FALLTHROUGH;
						case 3:  *packed++ = uint8_t(*_input++ * 255.0f); BX_FALLTHROUGH;
						case 2:  *packed++ = uint8_t(*_input++ * 255.0f); BX_FALLTHROUGH;
						case 1:  *packed++ = uint8_t(*_input++ * 255.0f);
						}
					}
				}
				else
				{
					switch (num)
					{
					default: *packed++ = uint8_t(*_input++); BX_FALLTHROUGH;
					case 3:  *packed++ = uint8_t(*_input++); BX_FALLTHROUGH;
					case 2:  *packed++ = uint8_t(*_input++); BX_FALLTHROUGH;
					case 1:  *packed++ = uint8_t(*_input++);
					}
				}
			}
			break;

		case AttribType::Uint10:
			{
				uint32_t packed = 0;
				if (_inputNormalized)
				{
					if (asInt)
					{
						switch (num)
						{
						default: BX_FALLTHROUGH;
						case 3:                packed |= uint32_t(*_input++ * 511.0f + 512.0f); BX_FALLTHROUGH;
						case 2: packed <<= 10; packed |= uint32_t(*_input++ * 511.0f + 512.0f); BX_FALLTHROUGH;
						case 1: packed <<= 10; packed |= uint32_t(*_input++ * 511.0f + 512.0f);
						}
					}
					else
					{
						switch (num)
						{
						default: BX_FALLTHROUGH;
						case 3:                packed |= uint32_t(*_input++ * 1023.0f); BX_FALLTHROUGH;
						case 2: packed <<= 10; packed |= uint32_t(*_input++ * 1023.0f); BX_FALLTHROUGH;
						case 1: packed <<= 10; packed |= uint32_t(*_input++ * 1023.0f);
						}
					}
				}
				else
				{
					switch (num)
					{
					default: BX_FALLTHROUGH;
					case 3:                packed |= uint32_t(*_input++); BX_FALLTHROUGH;
					case 2: packed <<= 10; packed |= uint32_t(*_input++); BX_FALLTHROUGH;
					case 1: packed <<= 10; packed |= uint32_t(*_input++);
					}
				}
				*(uint32_t*)data = packed;
			}
			break;

		case AttribType::Int16:
			{
//.........这里部分代码省略.........
开发者ID:MikePopoloski,项目名称:bgfx,代码行数:101,代码来源:vertexdecl.cpp


示例11: wrong


//.........这里部分代码省略.........
	if (ctx.kotor2)
		ctx.mdl->skip(8);

	uint32 offNodeData = ctx.mdl->readUint32LE();

	ctx.mdl->skip(4);

	if ((offOffVertsCount < 1) || (vertexCount == 0) || (facesCount == 0))
		return;

	uint32 endPos = ctx.mdl->pos();

	if (textureCount > 2) {
		warning("Model_KotOR::readMesh(): textureCount > 2 (%d)", textureCount);
		textureCount = 2;
	}

	if ((textureCount > 0) && !ctx.texture.empty())
		textures[0] = ctx.texture;

	textures.resize(textureCount);
	loadTextures(textures);


	// Read vertices (interleaved)

	GLsizei vpsize = 3;
	GLsizei vnsize = 3;
	GLsizei vtsize = 2;
	uint32 vertexSize = (vpsize + vnsize + vtsize * textureCount) * sizeof(float);
	_vertexBuffer.setSize(vertexCount, vertexSize);

	float *vertexData = (float *) _vertexBuffer.getData();
	VertexDecl vertexDecl;

	VertexAttrib vp;
	vp.index = VPOSITION;
	vp.size = vpsize;
	vp.type = GL_FLOAT;
	vp.stride = vertexSize;
	vp.pointer = vertexData;
	vertexDecl.push_back(vp);

	VertexAttrib vn;
	vn.index = VNORMAL;
	vn.size = vnsize;
	vn.type = GL_FLOAT;
	vn.stride = vertexSize;
	vn.pointer = vertexData + vpsize;
	vertexDecl.push_back(vn);

	for (uint16 t = 0; t < textureCount; t++) {
		VertexAttrib vt;
		vt.index = VTCOORD + t;
		vt.size = vtsize;
		vt.type = GL_FLOAT;
		vt.stride = vertexSize;
		vt.pointer = vertexData + vpsize + vnsize + vtsize * t;
		vertexDecl.push_back(vt);
	}

	_vertexBuffer.setVertexDecl(vertexDecl);

	float *v = vertexData;
	for (uint32 i = 0; i < vertexCount; i++) {
		// Position
开发者ID:cc9cii,项目名称:xoreos,代码行数:67,代码来源:model_kotor.cpp


示例12: vertexConvert

	void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num)
	{
		if (_destDecl.m_hash == _srcDecl.m_hash)
		{
			memcpy(_destData, _srcData, _srcDecl.getSize(_num) );
			return;
		}

		struct ConvertOp
		{
			enum Enum
			{
				Set,
				Copy,
				Convert,
			};

			Attrib::Enum attr;
			Enum op;
			uint32_t src;
			uint32_t dest;
			uint32_t size;
		};

		ConvertOp convertOp[Attrib::Count];
		uint32_t numOps = 0;

		for (uint32_t ii = 0; ii < Attrib::Count; ++ii)
		{
			Attrib::Enum attr = (Attrib::Enum)ii;

			if (_destDecl.has(attr) )
			{
				ConvertOp& cop = convertOp[numOps];
				cop.attr = attr;
				cop.dest = _destDecl.getOffset(attr);

				uint8_t num;
				AttribType::Enum type;
				bool normalized;
				bool asInt;
				_destDecl.decode(attr, num, type, normalized, asInt);
				cop.size = (*s_attribTypeSize[0])[type][num-1];

				if (_srcDecl.has(attr) )
				{
					cop.src = _srcDecl.getOffset(attr);
					cop.op = _destDecl.m_attributes[attr] == _srcDecl.m_attributes[attr] ? ConvertOp::Copy : ConvertOp::Convert;
				}
				else
				{
					cop.op = ConvertOp::Set;
				}

				++numOps;
			}
		}

		if (0 < numOps)
		{
			const uint8_t* src = (const uint8_t*)_srcData;
			uint32_t srcStride = _srcDecl.getStride();

			uint8_t* dest = (uint8_t*)_destData;
			uint32_t destStride = _destDecl.getStride();

			float unpacked[4];

			for (uint32_t ii = 0; ii < _num; ++ii)
			{
				for (uint32_t jj = 0; jj < numOps; ++jj)
				{
					const ConvertOp& cop = convertOp[jj];

					switch (cop.op)
					{
					case ConvertOp::Set:
						memset(dest + cop.dest, 0, cop.size);
						break;

					case ConvertOp::Copy:
						memcpy(dest + cop.dest, src + cop.src, cop.size);
						break;

					case ConvertOp::Convert:
						vertexUnpack(unpacked, cop.attr, _srcDecl, src);
						vertexPack(unpacked, true, cop.attr, _destDecl, dest);
						break;
					}
				}

				src += srcStride;
				dest += destStride;
			}
		}
	}
开发者ID:Akaito,项目名称:bgfx,代码行数:96,代码来源:vertexdecl.cpp


示例13: signature

bool ModelNode_NWN2::loadSkin(Model_NWN2::ParserContext &ctx) {
	uint32 tag = ctx.mdb->readUint32BE();
	if (tag != kSkinID)
		throw Common::Exception("Invalid skin packet signature (%s)", Common::debugTag(tag).c_str());

	uint32 packetSize = ctx.mdb->readUint32LE();

	_name = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

	// Skipping lower level of detail models
	if (_name.endsWith("_L01") || _name.endsWith("_L02"))
		return false;

	Common::UString skeletonName = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

	Common::UString diffuseMap = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);
	Common::UString normalMap  = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);
	                _tintMap   = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);
	Common::UString glowMap    = Common::readStringFixed(*ctx.mdb, Common::kEncodingASCII, 32);

	_diffuse [0] = ctx.mdb->readIEEEFloatLE();
	_diffuse [1] = ctx.mdb->readIEEEFloatLE();
	_diffuse [2] = ctx.mdb->readIEEEFloatLE();
	_specular[0] = ctx.mdb->readIEEEFloatLE();
	_specular[1] = ctx.mdb->readIEEEFloatLE();
	_specular[2] = ctx.mdb->readIEEEFloatLE();

	float  specularPower = ctx.mdb->readIEEEFloatLE();
	float  specularValue = ctx.mdb->readIEEEFloatLE();
	uint32 textureFlags  = ctx.mdb->readUint32LE();

	uint32 vertexCount = ctx.mdb->readUint32LE();
	uint32 facesCount  = ctx.mdb->readUint32LE();

	if ((vertexCount == 0) || (facesCount == 0))
		return false;

	std::vector<Common::UString> textures;
	textures.push_back(diffuseMap);

	loadTextures(textures);

	// Read vertices (interleaved)

	VertexDecl vertexDecl;

	vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VNORMAL  , 3, GL_FLOAT));
	vertexDecl.push_back(VertexAttrib(VTCOORD  , 3, GL_FLOAT));

	if (!_tintMap.empty())
		vertexDecl.push_back(VertexAttrib(VTCOORD + 1, 3, GL_FLOAT));

	_vertexBuffer.setVertexDeclInterleave(vertexCount, vertexDecl);

	float *v = (float *) _vertexBuffer.getData();
	for (uint32 i = 0; i < vertexCount; i++) {
		// Position
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();

		// Normal
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();

		ctx.mdb->skip(4 * 4); // Bone weights
		ctx.mdb->skip(4 * 1); // Bone indices
		ctx.mdb->skip(3 * 4); // Tangent
		ctx.mdb->skip(3 * 4); // Binormal

		// TexCoords
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();
		*v++ = ctx.mdb->readIEEEFloatLE();

		// TintMap TexCoords
		if (!_tintMap.empty()) {
			v[0] = v[-3];
			v[1] = v[-2];
			v[2] = v[-1];
			v += 3;
		}

		ctx.mdb->skip(4); // Bone count
	}


	// Read faces

	_indexBuffer.setSize(facesCount * 3, sizeof(uint16), GL_UNSIGNED_SHORT);

	uint16 *f = (uint16 *) _indexBuffer.getData();
	for (uint32 i = 0; i < facesCount * 3; i++)
		f[i] = ctx.mdb->readUint16LE();

	createBound();

	_render = true;
//.........这里部分代码省略.........
开发者ID:Glyth,项目名称:xoreos,代码行数:101,代码来源:model_nwn2.cpp



注:本文中的VertexDecl类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ VertexDeclaration类代码示例发布时间:2022-05-31
下一篇:
C++ VertexData类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap