Ejemplo n.º 1
0
		bool GLSL_Shader::loadShaders(const char* vertexShaderName, const char* pixelShaderName)
		{
			if (glCreateProgram == NULL)
				throw SnowSim::Exceptions::NotSupportedException("glCreateProgram is not support by your graphics card!");
			if (glLinkProgram == NULL)
				throw SnowSim::Exceptions::NotSupportedException("glLinkProgram is not support by your graphics card!");

			// delete previously loaded shaders
			unloadShaders();

			// create program
			program = glCreateProgram();

			// create vertex shader
			if(!createVertexShader(vertexShaderName))
				return false;

			// create pixel shader
			if(!createPixelShader(pixelShaderName))
				return false;

			glLinkProgram(program);
			shaderLoaded = true;

			return shaderLoaded;
		}
Ejemplo n.º 2
0
  bool GPUContextDX9::initialize()
  {
    _window = DX9Window::create();
    if( _window == NULL )
    {
      DX9WARN << "Could not create offscreen window.";
      return false;
    }

    HWND windowHandle = _window->getWindowHandle();

    _direct3D = Direct3DCreate9( D3D_SDK_VERSION );
    if( _direct3D == NULL )
    {
      DX9WARN << "Could not create Direct3D interface.";
      return false;
    }

    D3DPRESENT_PARAMETERS deviceDesc;
    ZeroMemory( &deviceDesc, sizeof(deviceDesc) );

    deviceDesc.Windowed = TRUE;
    deviceDesc.SwapEffect = D3DSWAPEFFECT_DISCARD;
    deviceDesc.BackBufferFormat = D3DFMT_UNKNOWN;
    deviceDesc.EnableAutoDepthStencil = FALSE;
    deviceDesc.AutoDepthStencilFormat = D3DFMT_D24S8;

    HRESULT result = _direct3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle,
      D3DCREATE_HARDWARE_VERTEXPROCESSING, &deviceDesc, &_device );
    if( FAILED(result) )
    {
      DX9WARN << "Could not create Direct3D device.";
      return false;
    }

    // create vertex buffer
    static const int kMaxVertexCount = 64;

    result = _device->CreateVertexBuffer(
      kMaxVertexCount*sizeof(DX9Vertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &_vertexBuffer, NULL );
    DX9AssertResult( result, "CreateVertexBuffer failed" );

    result = _device->CreateVertexDeclaration( kDX9VertexElements, &_vertexDecl );
    DX9AssertResult( result, "CreateVertexDeclaration failed" );


    // TIM: set up initial state
    result = _device->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
    GPUAssert( !FAILED(result), "SetRenderState failed" );

    _passthroughVertexShader = createVertexShader( kPassthroughVertexShaderSource );
    _passthroughPixelShader = createPixelShader( kPassthroughPixelShaderSource );

    for( size_t i = 0; i < kMaximumOutputCount; i++ )
      _boundOutputs[i] = NULL;
    for( size_t t = 0; t < kMaximumSamplerCount; t++ )
      _boundTextures[t] = NULL;

    return true;
  }
Ejemplo n.º 3
0
D3D11Shader::D3D11Shader( D3D11Window* iWin, VertexType iVertexType, char* vShaderFilename, char* vShaderFcnName,
              char* pxShaderFilename, char* pxShaderFcnName )
{
  win = iWin ;
  vertexType = iVertexType ;
  if( !loadHLSLBlob( &vblob, vShaderFilename, vShaderFcnName, VERTEX_SHADER_MODEL_5 ) )
    error( "Couldn't load shader %s, %s()", vShaderFilename, vShaderFcnName ) ;
  createVertexShader( &vblob, &vsh ) ;

  if( !loadHLSLBlob( &pxblob, pxShaderFilename, pxShaderFcnName, PIXEL_SHADER_MODEL_5 ) )
    error( "Couldn't load shader %s, %s()", pxShaderFilename, pxShaderFcnName ) ;
  createPixelShader( &pxblob, &psh ) ;
  SAFE_RELEASE( pxblob ) ; // I don't need this one anymore
}
Ejemplo n.º 4
0
	Shader *RendererDevice::createShader(ShaderType type, const void *buffer, size_t bufferSize)
	{
		PROFILE;
		switch (type)
		{
		case ShaderType::SHADERTYPE_VERTEX:
			return createVertexShader(buffer, bufferSize, deviceData->device);
		case ShaderType::SHADERTYPE_PIXEL:
			return createPixelShader(buffer, bufferSize, deviceData->device);
		default:
			LOG_ERROR("[D3D11 ERROR] Shader is invalid!");
			return NULL;
		}
	}
void CD3D9ShaderMaterialRenderer::init(s32& outMaterialTypeNr,
		const c8* vertexShaderProgram, const c8* pixelShaderProgram)
{
	outMaterialTypeNr = -1;

	// create vertex shader
	if (!createVertexShader(vertexShaderProgram))
		return;

	// create pixel shader
	if (!createPixelShader(pixelShaderProgram))
		return;

	// register myself as new material
	outMaterialTypeNr = Driver->addMaterialRenderer(this);
}
void COpenGLShaderMaterialRenderer::init(s32& outMaterialTypeNr, const c8* vertexShaderProgram,
	const c8* pixelShaderProgram, E_VERTEX_TYPE type)
{
	outMaterialTypeNr = -1;

	// create vertex shader
	if (!createVertexShader(vertexShaderProgram))
		return;

	// create pixel shader
	if (!createPixelShader(pixelShaderProgram))
		return;

	// register as a new material
	outMaterialTypeNr = Driver->addMaterialRenderer(this);
}
Ejemplo n.º 7
0
bool ShaderClass::InitShader(ID3D11Device* pDevice, WCHAR* vFileName, WCHAR* pFileName, WCHAR* gFileName, D3D11_INPUT_ELEMENT_DESC *vertexDesc, int numElements)
{
	bool result;

	// Initialize the vertex shader
	result = createVertexShaderAndInputLayout(pDevice, vFileName, "VSMain", vertexDesc, numElements);
	if (!result)
	{
		return false;
	}

	if (gFileName)
	{
		// Init Geometry Shader
		result = createGeometryShader(pDevice, gFileName, "GSMain");
		if (!result)
		{
			return false;
		}
	}

	if (pFileName)
	{
		// Initialie Pixel shader
		result = createPixelShader(pDevice, pFileName, "PSMain");
		if (!result)
		{
			return false;
		}
	}
	
	

	result = createConstantBuffer(pDevice, sizeof(MatrixBufferType), &mMatrixBuffer, D3D11_BIND_CONSTANT_BUFFER);
	if (!result)
	{
		return false;
	}

	return true;
}
Ejemplo n.º 8
0
bool TerrainShaderClass::InitShader(ID3D11Device* pDevice, WCHAR* vFileName, WCHAR* pFileName, WCHAR* gFileName)
{
	bool result;

	D3D11_INPUT_ELEMENT_DESC polygonLayout[6];/* =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }
		
	};*/

	// Create the vertex input layout description.
	// This setup needs to match the VertexType stucture in the ModelClass and in the shader.
	polygonLayout[0].SemanticName = "POSITION";
	polygonLayout[0].SemanticIndex = 0;
	polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	polygonLayout[0].InputSlot = 0;
	polygonLayout[0].AlignedByteOffset = 0;
	polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[0].InstanceDataStepRate = 0;

	polygonLayout[1].SemanticName = "TEXCOORD";
	polygonLayout[1].SemanticIndex = 0;
	polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
	polygonLayout[1].InputSlot = 0;
	polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[1].InstanceDataStepRate = 0;

	polygonLayout[2].SemanticName = "NORMAL";
	polygonLayout[2].SemanticIndex = 0;
	polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	polygonLayout[2].InputSlot = 0;
	polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[2].InstanceDataStepRate = 0;


	polygonLayout[3].SemanticName = "TEXCOORD";
	polygonLayout[3].SemanticIndex = 1;
	polygonLayout[3].Format = DXGI_FORMAT_R32G32_FLOAT;
	polygonLayout[3].InputSlot = 0;
	polygonLayout[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[3].InstanceDataStepRate = 0;

	polygonLayout[4].SemanticName = "TANGENT";
	polygonLayout[4].SemanticIndex = 0;
	polygonLayout[4].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	polygonLayout[4].InputSlot = 0;
	polygonLayout[4].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[4].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[4].InstanceDataStepRate = 0;

	polygonLayout[5].SemanticName = "BINORMAL";
	polygonLayout[5].SemanticIndex = 0;
	polygonLayout[5].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	polygonLayout[5].InputSlot = 0;
	polygonLayout[5].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[5].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[5].InstanceDataStepRate = 0;



	// Get a count of the elements in the layout.
	int numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);

	result = ShaderClass::InitShader(pDevice, vFileName, pFileName, gFileName, polygonLayout, numElements);
	if (!result)
	{
		return false;
	}

	result = createSamplerState(pDevice, &mSampleState);
	if (!result)
	{
		return false;
	}

	// Deferred init
	result = createConstantBuffer(pDevice, sizeof(TerrainCBufferType), &mLightBuffer, D3D11_BIND_CONSTANT_BUFFER);
	if (!result)
	{
		return false;
	}

	result = createPixelShader(pDevice, L"data/shaders/DeferredTerrainPixelShader.hlsl", "PSMain", &mDeferredPS);
	if (!result)
	{
		return false;
	}



	// Shadow Init
	result = createConstantBuffer(pDevice, sizeof(ShadowBuffer), &mShadowBuffer, D3D11_BIND_CONSTANT_BUFFER);
	if (!result)
	{
		return false;
	}

	result = createVertexShader(pDevice, L"data/shaders/ShadowDeferredVS.hlsl", "VSMain", &mShadowDeferredVS);
	if (!result)
	{
		return false;
	}

	result = createGeometryShader(pDevice, L"data/shaders/ShadowDeferredGS.hlsl", "GSMain", &mShadowDeferredGS);
	if (!result)
		return false;


	result = createPixelShader(pDevice, L"data/shaders/ShadowDeferredPS.hlsl", "PSMain", &mShadowDeferredPS);
	if (!result)
	{
		return false;
	}

	D3D11_SAMPLER_DESC samplerDesc;
	// Create a texture sampler state description.
	samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;//D3D11_FILTER_ANISOTROPIC;
	samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
	samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
	samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
	samplerDesc.MipLODBias = 0.0f;
	samplerDesc.MaxAnisotropy = 1;
	samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
	samplerDesc.BorderColor[0] = 0;
	samplerDesc.BorderColor[1] = 0;
	samplerDesc.BorderColor[2] = 0;
	samplerDesc.BorderColor[3] = 0;
	samplerDesc.MinLOD = 0;
	samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

	result = createSamplerState(pDevice, &mPointSampleState, &samplerDesc);
	if (!result)
	{
		return false;
	}
	return true;
}
Ejemplo n.º 9
0
void ShaderManagerDX::createShaders()
{
	createVertexShader();
	createPixelShader();
}