Пример #1
0
ID3D10Effect *GutLoadFXShaderDX10(const char *filename)
{
    //DWORD dwShaderFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
    //DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
	DWORD dwShaderFlags = 0;

#if defined( DEBUG ) || defined( _DEBUG )
	dwShaderFlags |= D3D10_SHADER_DEBUG;
#endif

	ID3D10Blob	*pErrorMessage = NULL;
	ID3D10Effect *pFXShader = NULL;

	char filename_fullpath[128];
	sprintf(filename_fullpath, "%s%s", GutGetShaderPath(), filename);

	if ( D3D_OK!=D3DX10CreateEffectFromFile( 
						filename_fullpath, g_pHLSL_Macros, NULL, 
						"fx_4_0", dwShaderFlags, 0, 
						g_pd3dDevice, NULL, NULL, 
						&pFXShader, &pErrorMessage, NULL) )
	{
		if ( pErrorMessage )
		{
			printf("Failed to compile %s : %s\n", pErrorMessage->GetBufferPointer());
		}
	}

	SAFE_RELEASE(pErrorMessage);
	
	return pFXShader;
}
Пример #2
0
GLuint _LoadGLSLShader(const char *filename, GLenum type)
{
	char filename_fullpath[256];
	sprintf(filename_fullpath, "%s%s", GutGetShaderPath(), filename);

	GLuint shader = glCreateShader(type);

	unsigned int len = 0;
	const GLchar *code = (const GLchar *)GutLoadFileStream(filename, &len);
	GLint size = len;
	glShaderSource(shader, 1, &code, &size);
	glCompileShader(shader);

	GLint result;
	glGetShaderiv(shader, GL_COMPILE_STATUS, &result);

	if ( GL_TRUE!=result )
	{
		GLchar pMessage[2048];
		GLsizei msgLen = 1023;

		glGetShaderInfoLog(shader, size, &msgLen, pMessage);

		printf("%s compile error\n", filename);
		printf("%s\n", pMessage);

		glDeleteShader(shader);
		shader = 0;
	}

	GutReleaseFileStream(code);

	return shader;
}
Пример #3
0
// 载入Pixel Shader
// file = HLSL shader file
// entry = pixel shader entry point
// profile = shader version
ID3D10PixelShader * GutLoadPixelShaderDX10_HLSL(const char *filename, const char *entry, const char *profile)
{
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;

#if defined( DEBUG ) || defined( _DEBUG )
	dwShaderFlags |= D3D10_SHADER_DEBUG;
#endif

	ID3D10PixelShader *pShader = NULL;
    ID3D10Blob	*pBuf = NULL;
	ID3D10Blob	*pErrorMessage = NULL;

	char filename_fullpath[128];
	sprintf(filename_fullpath, "%s%s", GutGetShaderPath(), filename);

	if ( D3D_OK==D3DX10CompileFromFile(filename_fullpath, g_pHLSL_Macros, NULL, entry, profile, dwShaderFlags, NULL, NULL, &pBuf, &pErrorMessage, NULL) )
	{
		g_pd3dDevice->CreatePixelShader( (DWORD*) pBuf->GetBufferPointer(), pBuf->GetBufferSize(), &pShader);
	}
	else
	{
		if ( pErrorMessage )
		{
			printf("Failed to compile %s : %s\n", pErrorMessage->GetBufferPointer());
		}
	}

	SAFE_RELEASE(pErrorMessage);
	SAFE_RELEASE(pBuf);
	
	return pShader;
}
Пример #4
0
// 載入OpenGL ARB Fragment Program規格的組合語言
GLuint GutLoadFragmentProgramOpenGL_ASM(const char *filename)
{
	char filename_fullpath[256];
	sprintf(filename_fullpath, "%s%s", GutGetShaderPath(), filename);

	unsigned int size = 0;
	// 讀入檔案
	unsigned char *buffer = (unsigned char *) GutLoadBinaryStream(filename_fullpath, &size);
	if ( buffer==NULL )
	{
		return 0;
	}

	GLuint shader_id = 0;
	// 產生一個shader物件
	glGenProgramsARB(1, &shader_id);
	// 使用新的shader物件, 並把它設定成fragment program物件
    glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader_id );
	// 把組合語言指令載入shader物件中
	glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, size, buffer);
	// 如果Shader中出現了任何錯誤
	if ( GL_INVALID_OPERATION == glGetError() )
	{
		// Find the error position
		GLint errPos;
		glGetIntegerv( GL_PROGRAM_ERROR_POSITION_ARB, &errPos );
		// errors and warnings string.
		GLubyte *errString = (GLubyte *) glGetString(GL_PROGRAM_ERROR_STRING_ARB);
		fprintf( stderr, "error at position: %d\n%s\n", errPos, errString );
		// 讀取失敗, 釋放shader物件
		glDeleteProgramsARB(1, &shader_id);
		shader_id = 0;
	}
	// 把載入檔案的記憶體釋放
	GutReleaseBinaryStream(buffer);
	// shader_id代表新的shader物件
	return shader_id;
}