GraphicsComponent::GraphicsComponent(const GraphicsComponentData& rData) : BaseGraphicsComponent(static_cast<BaseGraphicsComponentData>(rData))
{

    m_rotation = rData.rotation;

    m_animControl.load(rData.animationFileName);
    m_texTileSize = m_animControl.getTexTileSize();

    m_sprite.setOrigin(m_texTileSize.x/2.0f, m_texTileSize.y/2.0f);
    m_sprite.setTexture(*game.getTextureAllocator().request(getTexName()), false);

    sf::Vector2f scale;
    if(rData.dimensions != sf::Vector2f(0,0))
    {
        scale.x = rData.dimensions.x/m_texTileSize.x;
        scale.y = rData.dimensions.y/m_texTileSize.y;
    }
    else
        scale = sf::Vector2f(1,1);

    m_sprite.setScale(scale);
    m_sprite.setColor(rData.color);

    setPosition(b2Vec2(rData.position.x, rData.position.y));
    m_animControl.setState(rData.animState);
}
//insert a texture piece into the atlas
LLGLuint LLTextureAtlas::insertSubTexture(const LLImageRaw* raw_image, S16 slot_col, S16 slot_row)
{
	S32 w = raw_image->getWidth() ;
	S32 h = raw_image->getHeight() ;
	if(w < 8 || w > sMaxSubTextureSize || h < 8 || h > sMaxSubTextureSize)
	{
		//size overflow
		return 0 ;
	}

	BOOL res = gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getTexName());
	if (!res) llwarns << "bindTexture failed" << llendl;
	stop_glerror();

	GLint xoffset = sSlotSize * slot_col ;
	GLint yoffset = sSlotSize * slot_row ;

	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, TRUE);
	glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, 
						w, h, mFormatPrimary, mFormatType, raw_image->getData());
	
	return getTexName();
}
//insert a texture piece into the atlas
LLGLuint LLTextureAtlas::insertSubTexture(LLImageGL* source_gl_tex, S32 discard_level, const LLImageRaw* raw_image, S16 slot_col, S16 slot_row)
{
	if(!getTexName())
	{
		return 0 ;
	}

	S32 w = raw_image->getWidth() ;
	S32 h = raw_image->getHeight() ;
	if(w < 8 || w > sMaxSubTextureSize || h < 8 || h > sMaxSubTextureSize)
	{
		//size overflow
		return 0 ;
	}

	BOOL res = gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getTexName());
	if (!res) 
	{
		llwarns << "bindTexture failed" << llendl;
	}
	
	GLint xoffset = sSlotSize * slot_col ;
	GLint yoffset = sSlotSize * slot_row ;

	if(!source_gl_tex->preAddToAtlas(discard_level, raw_image))
	{
		return 0 ;
	}

	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, TRUE);
	glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, w, h,
						mGLTexturep->getPrimaryFormat(), mGLTexturep->getFormatType(), raw_image->getData());
	
	source_gl_tex->postAddToAtlas() ;
	return getTexName();
}
Beispiel #4
0
static void loadBspGeometry(Bsp *bsp, void *faceData, int32_t faceSize, void *edgeData, int32_t edgeSize,
		void *ledgeData, int32_t ledgeSize){

	bsp->numFaces = faceSize / sizeof(FaceDef);
	bsp->faces = malloc(sizeof(Face)*bsp->numFaces);
	FaceDef *faces = malloc(faceSize);
	memcpy(faces, faceData, faceSize);

	EdgeDef *edges = malloc(edgeSize);
	memcpy(edges, edgeData, edgeSize);

	int32_t *ledges = malloc(ledgeSize);
	memcpy(ledges, ledgeData, ledgeSize);

	for(int i=0; i < bsp->numFaces; i++){
		// Read all verts from edge data into a vert data structure
		// that is more suitable for GL rendering
		Face *face = &bsp->faces[i];
		face->numVerts = faces[i].edgeNum;
		face->verts = malloc(sizeof(Vert)*face->numVerts);
		TexInfoDef *texInfo = getTexInfo(bsp, faces[i].texinfoId);
		face->texture = getTexture(bsp, texInfo->texId);
		face->glId = 0;
		// If face is a trigger or clip skip loading it's verts
		// TODO make somekind of stack or vector to store faces so we don't bother
		// allocating useless memory
		if(strcmp("trigger", getTexName(face->texture)) == 0 || strcmp("clip", getTexName(face->texture)) == 0){
			continue;
		}
		for(int edge=0; edge < faces[i].edgeNum; edge++){
			int32_t edgeIndex = ledges[edge+faces[i].edgeId];
			vec3Float verts[2];
			// if edgeIndex is negative flip v0 and v1
			if(edgeIndex < 0){
				edgeIndex = -edgeIndex;
				verts[0] = getVert(bsp, edges[edgeIndex].vert1);
				verts[1] = getVert(bsp, edges[edgeIndex].vert0);
			} else {
				verts[0] = getVert(bsp, edges[edgeIndex].vert0);
				verts[1] = getVert(bsp, edges[edgeIndex].vert1);
			}

			face->verts[edge].normal = getPlane(bsp, faces[i].planeId)->normal;

			// Negate y and flip y & z so it's oriented properly
			face->verts[edge].position.x = verts[0].x;
			face->verts[edge].position.y = verts[0].z;
			face->verts[edge].position.z = -verts[0].y;

			// compute s and t coordinate for texture mapping
			face->verts[edge].texCoord.x = (vec3FDot(&verts[0], &texInfo->vecS) + texInfo->distS) / getTexWidth(face->texture);
			face->verts[edge].texCoord.y = (vec3FDot(&verts[0], &texInfo->vecT) + texInfo->distT) / getTexHeight(face->texture);
		}

		// Now that we have loaded all vertex data for this face
		// We can generate a vbo for it
		glGenBuffers(1, &face->glId);
		glBindBuffer(GL_ARRAY_BUFFER, face->glId);
		glBufferData(GL_ARRAY_BUFFER, sizeof(Vert)*face->numVerts, &face->verts[0], GL_STATIC_DRAW);
	}

	free(faces);
	free(edges);
	free(ledges);
}
void LLCubeMap::setReflection (void)
{
	gGL.getTexUnit(mTextureStage)->bindManual(LLTexUnit::TT_CUBE_MAP, getTexName());
	mImages[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC);
	mImages[0]->setAddressMode(LLTexUnit::TAM_CLAMP);
}