forked from notaz/mesa
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CafeGLSLCompiler.h
88 lines (79 loc) · 3.36 KB
/
CafeGLSLCompiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <stdint.h>
#if defined(__WUT__) || defined(__WIIU__)
#include <gx2/shaders.h>
#include <coreinit/dynload.h>
#include <coreinit/debug.h>
#define GLSL_COMPILER_CAFE_RPL // use compiler as rpl
#endif
#ifdef GLSL_COMPILER_CAFE_RPL
inline OSDynLoad_Module s_glslCompilerModule = nullptr;
#endif
enum GLSL_COMPILER_FLAG
{
// reserved for future use
GLSL_COMPILER_FLAG_NONE = 0,
GLSL_COMPILER_FLAG_GENERATE_DISASSEMBLY = 1 << 0, // write disassembly to stderr
GLSL_COMPILER_FLAG_PRINT_DISASSEMBLY_TO_STDERR = 1 << 0,
};
inline GX2VertexShader* (*GLSL_CompileVertexShader)(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags);
inline GX2PixelShader* (*GLSL_CompilePixelShader)(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags);
inline void (*GLSL_FreeVertexShader)(GX2VertexShader* shader);
inline void (*GLSL_FreePixelShader)(GX2PixelShader* shader);
inline void (*__GLSL_DestroyGLSLCompiler)();
#ifndef GLSL_COMPILER_CAFE_RPL
extern "C"
{
void InitGLSLCompiler();
void DestroyGLSLCompiler();
GX2VertexShader* CompileVertexShader(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags);
GX2PixelShader* CompilePixelShader(const char* shaderSource, char* infoLogOut, int infoLogMaxLength, GLSL_COMPILER_FLAG flags);
void FreeVertexShader(GX2VertexShader* shader);
void FreePixelShader(GX2PixelShader* shader);
};
#endif
static inline bool GLSL_Init()
{
void (*_InitGLSLCompiler)() = nullptr;
#if defined(__WUT__) || defined(__WIIU__)
if (s_glslCompilerModule != nullptr)
return false;
OSDynLoad_Error r = OSDynLoad_Acquire("glslcompiler", &s_glslCompilerModule);
if(r != OS_DYNLOAD_OK) // try alternate path
r = OSDynLoad_Acquire("~/wiiu/libs/glslcompiler.rpl", &s_glslCompilerModule);
if (r != OS_DYNLOAD_OK)
{
OSReport("glslcompiler.rpl not found\n");
return false;
}
// find exports
OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "InitGLSLCompiler", (void**)&_InitGLSLCompiler);
OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "CompileVertexShader", (void**)&GLSL_CompileVertexShader);
OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "CompilePixelShader", (void**)&GLSL_CompilePixelShader);
OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "FreeVertexShader", (void**)&GLSL_FreeVertexShader);
OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "FreePixelShader", (void**)&GLSL_FreePixelShader);
OSDynLoad_FindExport(s_glslCompilerModule, OS_DYNLOAD_EXPORT_FUNC, "DestroyGLSLCompiler", (void**)&__GLSL_DestroyGLSLCompiler);
#else
_InitGLSLCompiler = InitGLSLCompiler;
GLSL_CompileVertexShader = CompileVertexShader;
GLSL_CompilePixelShader = CompilePixelShader;
GLSL_FreeVertexShader = FreeVertexShader;
GLSL_FreePixelShader = FreePixelShader;
__GLSL_DestroyGLSLCompiler = DestroyGLSLCompiler;
#endif
_InitGLSLCompiler();
return true;
}
static inline bool GLSL_Shutdown()
{
#ifdef GLSL_COMPILER_CAFE_RPL
if (s_glslCompilerModule == nullptr)
return false;
__GLSL_DestroyGLSLCompiler();
OSDynLoad_Release(s_glslCompilerModule);
s_glslCompilerModule = nullptr;
#else
__GLSL_DestroyGLSLCompiler();
#endif
return true;
}