-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(WIP) tr2: use hybrid OpenGL/DirectX rendering
- Loading branch information
Showing
44 changed files
with
992 additions
and
1,611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
#ifdef OGL33C | ||
out vec2 vertTexCoords; | ||
#else | ||
varying vec2 vertTexCoords; | ||
#endif | ||
|
||
layout(location = 0) in vec2 inPosition; | ||
|
||
void main(void) { | ||
vertTexCoords = inPosition; | ||
gl_Position = vec4(vertTexCoords * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0); | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
uniform sampler2D tex0; | ||
uniform sampler1D pal0; | ||
uniform bool paletteEnabled; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
#define TEXTURE2D texture | ||
#define TEXTURE1D texture | ||
|
||
in vec2 vertTexCoords; | ||
out vec4 outColor; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#define TEXTURE2D texture2D | ||
#define TEXTURE1D texture1D | ||
|
||
varying vec2 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
if (paletteEnabled) { | ||
float paletteIndex = TEXTURE2D(tex0, vertTexCoords).r; | ||
OUTCOLOR = TEXTURE1D(pal0, paletteIndex); | ||
} else { | ||
OUTCOLOR = TEXTURE2D(tex0, vertTexCoords); | ||
} | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
layout(location = 0) in vec3 inPosition; | ||
layout(location = 1) in vec3 inTexCoords; | ||
layout(location = 2) in vec4 inColor; | ||
|
||
uniform mat4 matProjection; | ||
uniform mat4 matModelView; | ||
|
||
#ifdef OGL33C | ||
out vec4 vertColor; | ||
out vec3 vertTexCoords; | ||
#else | ||
varying vec4 vertColor; | ||
varying vec3 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
gl_Position = matProjection * matModelView * vec4(inPosition, 1); | ||
vertColor = inColor / 255.0; | ||
vertTexCoords = inTexCoords; | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
uniform sampler2D tex0; | ||
uniform bool texturingEnabled; | ||
uniform bool smoothingEnabled; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
#define TEXTURESIZE textureSize | ||
#define TEXTURE texture | ||
#define TEXELFETCH texelFetch | ||
|
||
in vec4 vertColor; | ||
in vec3 vertTexCoords; | ||
out vec4 OUTCOLOR; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#define TEXTURESIZE textureSize2D | ||
#define TEXELFETCH texelFetch2D | ||
#define TEXTURE texture2D | ||
|
||
varying vec4 vertColor; | ||
varying vec3 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
OUTCOLOR = vertColor; | ||
|
||
if (texturingEnabled) { | ||
#if defined(GL_EXT_gpu_shader4) || defined(OGL33C) | ||
if (smoothingEnabled) { | ||
// do not use smoothing for chroma key | ||
ivec2 size = TEXTURESIZE(tex0, 0); | ||
int tx = int((vertTexCoords.x / vertTexCoords.z) * size.x) % size.x; | ||
int ty = int((vertTexCoords.y / vertTexCoords.z) * size.y) % size.y; | ||
vec4 texel = TEXELFETCH(tex0, ivec2(tx, ty), 0); | ||
if (texel.a == 0.0) { | ||
discard; | ||
} | ||
} | ||
#endif | ||
|
||
vec4 texColor = TEXTURE(tex0, vertTexCoords.xy / vertTexCoords.z); | ||
if (texColor.a == 0.0) { | ||
discard; | ||
} | ||
|
||
OUTCOLOR = vec4(OUTCOLOR.rgb * texColor.rgb, texColor.a); | ||
} | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifdef VERTEX | ||
// Vertex shader | ||
|
||
layout(location = 0) in vec2 inPosition; | ||
|
||
#ifdef OGL33C | ||
out vec2 vertTexCoords; | ||
#else | ||
varying vec2 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
vertTexCoords = inPosition; | ||
gl_Position = vec4(vertTexCoords * vec2(2.0, 2.0) + vec2(-1.0, -1.0), 0.0, 1.0); | ||
} | ||
|
||
#else | ||
// Fragment shader | ||
|
||
uniform sampler2D tex0; | ||
|
||
#ifdef OGL33C | ||
#define OUTCOLOR outColor | ||
#define TEXTURE texture | ||
|
||
in vec2 vertTexCoords; | ||
out vec4 OUTCOLOR; | ||
#else | ||
#define OUTCOLOR gl_FragColor | ||
#define TEXTURE texture2D | ||
|
||
varying vec2 vertTexCoords; | ||
#endif | ||
|
||
void main(void) { | ||
OUTCOLOR = TEXTURE(tex0, vertTexCoords); | ||
} | ||
#endif // VERTEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "game/shell.h" | ||
#include "log.h" | ||
#include "memory.h" | ||
|
||
static void M_ShowFatalError(const char *const message) | ||
{ | ||
LOG_ERROR("%s", message); | ||
SDL_Window *const window = Shell_GetWindow(); | ||
SDL_ShowSimpleMessageBox( | ||
SDL_MESSAGEBOX_ERROR, "Tomb Raider Error", message, window); | ||
Shell_Terminate(1); | ||
} | ||
|
||
void Shell_Terminate(int32_t exit_code) | ||
{ | ||
Shell_Shutdown(); | ||
|
||
SDL_Window *const window = Shell_GetWindow(); | ||
if (window != NULL) { | ||
SDL_DestroyWindow(window); | ||
} | ||
SDL_Quit(); | ||
exit(exit_code); | ||
} | ||
|
||
void Shell_ExitSystem(const char *message) | ||
{ | ||
M_ShowFatalError(message); | ||
Shell_Shutdown(); | ||
} | ||
|
||
void Shell_ExitSystemFmt(const char *fmt, ...) | ||
{ | ||
va_list va; | ||
va_start(va, fmt); | ||
int32_t size = vsnprintf(NULL, 0, fmt, va) + 1; | ||
char *message = Memory_Alloc(size); | ||
va_end(va); | ||
|
||
va_start(va, fmt); | ||
vsnprintf(message, size, fmt, va); | ||
va_end(va); | ||
|
||
Shell_ExitSystem(message); | ||
|
||
Memory_FreePointer(&message); | ||
} | ||
|
||
int32_t Shell_GetCurrentDisplayWidth(void) | ||
{ | ||
SDL_DisplayMode dm; | ||
SDL_GetCurrentDisplayMode(0, &dm); | ||
return dm.w; | ||
} | ||
|
||
int32_t Shell_GetCurrentDisplayHeight(void) | ||
{ | ||
SDL_DisplayMode dm; | ||
SDL_GetCurrentDisplayMode(0, &dm); | ||
return dm.h; | ||
} |
Oops, something went wrong.