lovr.graphics.getSystemLimits;

This commit is contained in:
bjorn 2017-03-31 04:22:18 -07:00
parent 49a63bb084
commit a04e5013ad
3 changed files with 53 additions and 9 deletions

View File

@ -406,6 +406,17 @@ int l_lovrGraphicsGetDimensions(lua_State* L) {
return 2;
}
int l_lovrGraphicsGetSystemLimits(lua_State* L) {
lua_newtable(L);
lua_pushnumber(L, lovrGraphicsGetSystemLimit(LIMIT_POINT_SIZE));
lua_setfield(L, -2, "pointsize");
lua_pushinteger(L, lovrGraphicsGetSystemLimit(LIMIT_TEXTURE_SIZE));
lua_setfield(L, -2, "texturesize");
lua_pushinteger(L, lovrGraphicsGetSystemLimit(LIMIT_TEXTURE_MSAA));
lua_setfield(L, -2, "texturemsaa");
return 1;
}
// Transforms
int l_lovrGraphicsPush(lua_State* L) {
@ -800,6 +811,7 @@ const luaL_Reg lovrGraphics[] = {
{ "getWidth", l_lovrGraphicsGetWidth },
{ "getHeight", l_lovrGraphicsGetHeight },
{ "getDimensions", l_lovrGraphicsGetDimensions },
{ "getSystemLimits", l_lovrGraphicsGetSystemLimits },
{ "newFont", l_lovrGraphicsNewFont },
{ "newMesh", l_lovrGraphicsNewMesh },
{ "newModel", l_lovrGraphicsNewModel },

View File

@ -14,23 +14,36 @@ static GraphicsState state;
// Base
void lovrGraphicsInit() {
for (int i = 0; i < MAX_CANVASES; i++) {
state.canvases[i] = malloc(sizeof(CanvasState));
}
state.defaultShader = lovrShaderCreate(lovrDefaultVertexShader, lovrDefaultFragmentShader);
state.skyboxShader = lovrShaderCreate(lovrSkyboxVertexShader, lovrSkyboxFragmentShader);
int uniformId = lovrShaderGetUniformId(state.skyboxShader, "cube");
lovrShaderSendInt(state.skyboxShader, uniformId, 1);
state.fullscreenShader = lovrShaderCreate(lovrNoopVertexShader, lovrDefaultFragmentShader);
// Allocations
state.activeFont = NULL;
state.defaultFont = NULL;
state.activeTexture = NULL;
state.defaultTexture = lovrTextureCreate(lovrTextureDataGetBlank(1, 1, 0xff, FORMAT_RGBA));
glGenBuffers(1, &state.shapeBuffer);
glGenBuffers(1, &state.shapeIndexBuffer);
glGenVertexArrays(1, &state.shapeArray);
vec_init(&state.shapeData);
vec_init(&state.shapeIndices);
for (int i = 0; i < MAX_CANVASES; i++) {
state.canvases[i] = malloc(sizeof(CanvasState));
}
// Objects
state.defaultShader = lovrShaderCreate(lovrDefaultVertexShader, lovrDefaultFragmentShader);
state.skyboxShader = lovrShaderCreate(lovrSkyboxVertexShader, lovrSkyboxFragmentShader);
int uniformId = lovrShaderGetUniformId(state.skyboxShader, "cube");
lovrShaderSendInt(state.skyboxShader, uniformId, 1);
state.fullscreenShader = lovrShaderCreate(lovrNoopVertexShader, lovrDefaultFragmentShader);
state.defaultTexture = lovrTextureCreate(lovrTextureDataGetBlank(1, 1, 0xff, FORMAT_RGBA));
// System Limits
float pointSizes[2];
glGetFloatv(GL_POINT_SIZE_RANGE, pointSizes);
state.maxPointSize = pointSizes[1];
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &state.maxTextureSize);
glGetIntegerv(GL_MAX_SAMPLES, &state.maxTextureMSAA);
// State
state.depthTest = -1;
lovrGraphicsReset();
atexit(lovrGraphicsDestroy);
@ -378,6 +391,15 @@ int lovrGraphicsGetHeight() {
return height;
}
float lovrGraphicsGetSystemLimit(GraphicsLimit limit) {
switch (limit) {
case LIMIT_POINT_SIZE: return state.maxPointSize;
case LIMIT_TEXTURE_SIZE: return state.maxTextureSize;
case LIMIT_TEXTURE_MSAA: return state.maxTextureMSAA;
default: error("Unknown limit %d\n", limit);
}
}
void lovrGraphicsPushCanvas() {
if (++state.canvas >= MAX_CANVASES) {
error("Canvas overflow");

View File

@ -47,6 +47,12 @@ typedef enum {
COMPARE_GREATER = GL_GREATER
} CompareMode;
typedef enum {
LIMIT_POINT_SIZE,
LIMIT_TEXTURE_SIZE,
LIMIT_TEXTURE_MSAA
} GraphicsLimit;
typedef struct {
int x;
int y;
@ -90,6 +96,9 @@ typedef struct {
PolygonWinding polygonWinding;
CompareMode depthTest;
int isWireframe;
float maxPointSize;
int maxTextureSize;
int maxTextureMSAA;
} GraphicsState;
// Base
@ -137,6 +146,7 @@ int lovrGraphicsIsWireframe();
void lovrGraphicsSetWireframe(int wireframe);
int lovrGraphicsGetWidth();
int lovrGraphicsGetHeight();
float lovrGraphicsGetSystemLimit(GraphicsLimit limit);
void lovrGraphicsPushCanvas();
void lovrGraphicsPopCanvas();
void lovrGraphicsSetViewport(int x, int y, int w, int h);