#include "Gos.pch"
#include "Graphics.h"

GosVertexShader* (*GosVertexShader::CreateFromMemory)(DWORD *, DWORD * ) = VertexShader::CreateFromMemory;

GosVertexShader* VertexShader::CreateFromMemory(DWORD *pDeclaration, DWORD *pFunction )
{
	LOG_API("VertexShader::CreateFromMemory");
	DWORD Handle;
	HRESULT rc;
	rc = Graphics::D3DDevice()->CreateVertexShader( pDeclaration, pFunction, &Handle, 0 );
	if( FAILED(rc) )
		STOP(("Failed to create D3D Vertex Shader"));

	VertexShader *pVertexShader = new VertexShader( Handle );
	if( !pVertexShader )
		STOP(("Failed to create Vertex Shader Object"));

	return (GosVertexShader *)pVertexShader;
}

VertexShader::VertexShader( DWORD Handle )
{
	m_Handle = Handle;
}

DWORD VertexShader::GetDeclaration( DWORD *pBuffer )
{
	DWORD Size;
	HRESULT rc;
	rc = Graphics::D3DDevice()->GetVertexShaderDeclaration( m_Handle, pBuffer, &Size );
	STOP(("Failed to get D3D Vertex Shader Declaration"));
	return Size;
}


DWORD VertexShader::GetFunction( DWORD *pBuffer )
{
	DWORD Size;
	HRESULT rc;
	rc = Graphics::D3DDevice()->GetVertexShaderFunction( m_Handle, pBuffer, &Size );
	STOP(("Failed to get D3D Vertex Shader function"));
	return Size;
}

VertexShader::~VertexShader()
{
	HRESULT rc;
	rc = Graphics::D3DDevice()->DeleteVertexShader( m_Handle );
	if( FAILED(rc) )
		STOP(("Failed to delete D3D Vertex Shader"));
}

GosVertexShader::~GosVertexShader()
{
	;
}
