void RsTextureWinGL::Render( RsTextureRenderable *pRenderable )
{
	// Cache the current render target
	RsRenderTarget *pRenderTarget = pRenderable->m_pRenderTarget;

	// Set the shader
	RsShaderWinGL *pShader = (RsShaderWinGL*)pRenderable->m_pShader;

	RsPrimitiveWinGL* pPrimitives = (RsPrimitiveWinGL*) pRenderable->m_primitive;

	if( pPrimitives->m_primitiveType == 1 )
	{
		int a=0;
		a++;
	}

	// Cache the camera
	const RsCamera &camera = pRenderTarget->GetCamera();

	const MtMatrix4& m4Projection = camera.GetViewProjection();
	const MtMatrix4& m4World      = MtMatrix4::m_identity;
	MtMatrix4 m4WorldViewScreen   = m4World * m4Projection;

	pShader->SetCamera( camera );
	pShader->SetTechnique( "RsShaderT2" );
	pShader->SetMatrix( RsHandles_WorldViewScreen, m4WorldViewScreen );

	for( BtU32 i=0; i<7; i++ )
	{
		glDisableVertexAttribArray( i );
	}

	// Cache the texture
	RsTextureWinGL* pTexture = (RsTextureWinGL*)pRenderable->m_pTexture;

	// Set the texture
	pTexture->SetTexture();

	// Set vertex arrays
	BtU32 stride = sizeof(RsVertex3);

	// Cache the vertex buffer
	BtU32 vertexBuffer = RsImplWinGL::GetVertexBuffer();

	// Get the size
	BtU32 dataSize = pPrimitives->m_numVertex * stride;

	// bind VBO in order to use
	glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer );
	
	GLenum error;
	error = glGetError();
	(void)error;

	// upload data to VBO
	glBufferData(GL_ARRAY_BUFFER, dataSize, pRenderable->m_pVertex, GL_DYNAMIC_DRAW);
	error = glGetError();
	(void)error;

	/*
	struct RsVertex3
	{
	MtVector3		m_v3Position;
	MtVector3		m_v3Normal;
	BtU32			m_colour;
	MtVector2		m_v2UV;
	MtVector2		m_v2UV2;
	};
	*/

	BtU32 offset = 0;
	
	glEnableVertexAttribArray( 0 );
	glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, stride, GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( MtVector3 );

	glEnableVertexAttribArray( 1 );
	glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, stride, GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( MtVector3 );

	glEnableVertexAttribArray( 4 );
	glVertexAttribPointer( 4, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( BtU32 );

	glEnableVertexAttribArray( 5);
	glVertexAttribPointer( 5, 2, GL_FLOAT, GL_FALSE, stride,  GL_BUFFER_OFFSET( offset ) );
	offset += sizeof( MtVector2 );

	// Draw the primitives
	pShader->Draw( pRenderable->m_primitive );
}
Example #2
0
void SgMeshWinGL::Render( SgMeshRenderable *pRenderable )
{
	RsSceneWinGL* pScene = (RsSceneWinGL*)m_pNode->m_pFileData->m_pScene;

	// Cache each material block
	BaMaterialBlockFileData* pMaterialBlock = pRenderable->m_pMaterialBlock;

	// Cache the material
	RsMaterialWinGL* pMaterial = (RsMaterialWinGL*) pMaterialBlock->m_pMaterial;

	// Set the vertex buffer
	pScene->pVertexBuffer( pMaterial->GetVertexType() )->SetStream();

	// Set the index stream
	pScene->pIndexBuffer()->SetIndices();

	// Cache the effect
	RsShaderWinGL* pShader = (RsShaderWinGL*)pRenderable->m_pShader;

	// Render the blend shape
	if( m_pNode->pBlendShape() != BtNull )
	{
		SgBlendShapeImpl* pBlendShape = (SgBlendShapeImpl*)  m_pNode->pBlendShape();
		(void)pBlendShape;
	}

	// Cache the current render target
	RsRenderTarget* pRenderTarget = pRenderable->m_pRenderTarget;

	// Cache the camera
	const RsCamera &camera = pRenderTarget->GetCamera();

	const MtMatrix4 &m4ViewScreen = pRenderTarget->GetCamera().GetViewProjection();
	const MtMatrix4 &m4World      = m_pNode->m_pFileData->m_m4World;
	const MtMatrix4 &m4View	      = camera.GetView();
	MtMatrix4 m4WorldViewScreen   = m4World * m4ViewScreen;
	MtMatrix4 m4WorldView		  = m4World * m4View;

	// Cache the technique
	const BtChar* pTechnique = pMaterial->GetTechniqueName();

	if(strstr(pTechnique, "Projected"))
	{
		int a = 0;
		a++;
	}
	if( strstr( pTechnique, "RsShaderZLT" ) )
	{
		int a=0;
		a++;
	}

	// Set the technique
	pShader->SetTechnique( pTechnique );
	pShader->SetMatrix( RsHandles_WorldViewScreen, m4WorldViewScreen );
	pShader->SetMatrix( RsHandles_WorldViewInverseTranspose, m4WorldView.GetInverse().GetTranspose() );
	pShader->SetMatrix( RsHandles_ViewInverseTranspose, m4View.GetInverse().GetTranspose() );
	pShader->SetMatrix( RsHandles_World, m4World );
	pShader->SetMaterial(pMaterial);
	
	// Ensure we have a material
	BtAssert( pMaterial != BtNull );

	// Loop through the materials
	for( BtU32 nRenderBlock=pMaterialBlock->m_nStartRenderBlock; nRenderBlock<pMaterialBlock->m_nEndRenderBlock; nRenderBlock++ )
	{
		// Cache each render block
		BaRenderBlockFileData* pRenderBlock = pScene->pRenderBlock( nRenderBlock );

		// Loop through the materials
		for( BtU32 nPrimitiveBlock=pRenderBlock->m_nStartPrimitiveBlock; nPrimitiveBlock<pRenderBlock->m_nEndPrimitiveBlock; nPrimitiveBlock++ )
		{
			// Cache each primitive block
			RsIndexedPrimitiveWinGL* pPrimitiveBlock = pScene->pPrimitiveBlock( nPrimitiveBlock );

			// Draw the primitives using the effect
			pShader->Draw( pPrimitiveBlock );
		}
	}
}