1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-02 20:43:35 +00:00

Use unsigned chars for color mask;

This commit is contained in:
bjorn 2016-09-28 19:38:58 -07:00
parent ccd0b5374e
commit a24bdcf98a
4 changed files with 13 additions and 12 deletions

View file

@ -103,15 +103,15 @@ void lovrGraphicsSetBackgroundColor(float r, float g, float b, float a) {
glClearColor(r / 255, g / 255, b / 255, a / 255); glClearColor(r / 255, g / 255, b / 255, a / 255);
} }
void lovrGraphicsGetColorMask(char* r, char* g, char* b, char* a) { void lovrGraphicsGetColorMask(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {
char mask = state.colorMask; unsigned char mask = state.colorMask;
*r = mask & 0x1; *r = mask & 0x1;
*g = mask & 0x2; *g = mask & 0x2;
*b = mask & 0x4; *b = mask & 0x4;
*a = mask & 0x8; *a = mask & 0x8;
} }
void lovrGraphicsSetColorMask(char r, char g, char b, char a) { void lovrGraphicsSetColorMask(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
state.colorMask = ((r & 1) << 0) | ((g & 1) << 1) | ((b & 1) << 2) | ((a & 1) << 3); state.colorMask = ((r & 1) << 0) | ((g & 1) << 1) | ((b & 1) << 2) | ((a & 1) << 3);
glColorMask(r, g, b, a); glColorMask(r, g, b, a);
} }

View file

@ -14,7 +14,7 @@ typedef struct {
mat4 lastTransform; mat4 lastTransform;
mat4 projection; mat4 projection;
mat4 lastProjection; mat4 lastProjection;
char colorMask; unsigned char colorMask;
} GraphicsState; } GraphicsState;
#endif #endif
@ -25,8 +25,8 @@ void lovrGraphicsPresent();
void lovrGraphicsPrepare(); void lovrGraphicsPrepare();
void lovrGraphicsGetBackgroundColor(float* r, float* g, float* b, float* a); void lovrGraphicsGetBackgroundColor(float* r, float* g, float* b, float* a);
void lovrGraphicsSetBackgroundColor(float r, float g, float b, float a); void lovrGraphicsSetBackgroundColor(float r, float g, float b, float a);
void lovrGraphicsGetColorMask(char* r, char* g, char* b, char* a); void lovrGraphicsGetColorMask(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a);
void lovrGraphicsSetColorMask(char r, char g, char b, char a); void lovrGraphicsSetColorMask(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
Shader* lovrGraphicsGetShader(); Shader* lovrGraphicsGetShader();
void lovrGraphicsSetShader(Shader* shader); void lovrGraphicsSetShader(Shader* shader);
void lovrGraphicsSetProjection(float near, float far, float fov); void lovrGraphicsSetProjection(float near, float far, float fov);

View file

@ -11,6 +11,7 @@ const char* lovrShaderVertexPrefix = ""
const char* lovrShaderFragmentPrefix = "" const char* lovrShaderFragmentPrefix = ""
"#version 150 \n" "#version 150 \n"
"uniform vec4 lovrColor; \n"
"out vec4 color;" "out vec4 color;"
""; "";
@ -22,7 +23,7 @@ const char* lovrDefaultVertexShader = ""
const char* lovrDefaultFragmentShader = "" const char* lovrDefaultFragmentShader = ""
"void main() { \n" "void main() { \n"
" color = vec4(1.0); \n" " color = lovrColor; \n"
"}" "}"
""; "";

View file

@ -89,7 +89,7 @@ int l_lovrGraphicsSetBackgroundColor(lua_State* L) {
} }
int l_lovrGraphicsGetColorMask(lua_State* L) { int l_lovrGraphicsGetColorMask(lua_State* L) {
char r, g, b, a; unsigned char r, g, b, a;
lovrGraphicsGetColorMask(&r, &g, &b, &a); lovrGraphicsGetColorMask(&r, &g, &b, &a);
lua_pushboolean(L, r); lua_pushboolean(L, r);
lua_pushboolean(L, g); lua_pushboolean(L, g);
@ -104,10 +104,10 @@ int l_lovrGraphicsSetColorMask(lua_State* L) {
return 0; return 0;
} }
char r = lua_toboolean(L, 1); unsigned char r = lua_toboolean(L, 1);
char g = lua_toboolean(L, 2); unsigned char g = lua_toboolean(L, 2);
char b = lua_toboolean(L, 3); unsigned char b = lua_toboolean(L, 3);
char a = lua_toboolean(L, 4); unsigned char a = lua_toboolean(L, 4);
lovrGraphicsSetColorMask(r, g, b, a); lovrGraphicsSetColorMask(r, g, b, a);
return 0; return 0;