From a04e5013adb28d3db840ff9ca7ee2404577abf75 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 31 Mar 2017 04:22:18 -0700 Subject: [PATCH] lovr.graphics.getSystemLimits; --- src/api/graphics.c | 12 ++++++++++++ src/graphics/graphics.c | 40 +++++++++++++++++++++++++++++++--------- src/graphics/graphics.h | 10 ++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/api/graphics.c b/src/api/graphics.c index 043db7c1..d6fd6a37 100644 --- a/src/api/graphics.c +++ b/src/api/graphics.c @@ -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 }, diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index d931404d..9923a2a6 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -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"); diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h index 45c315b5..1873e194 100644 --- a/src/graphics/graphics.h +++ b/src/graphics/graphics.h @@ -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);