2016-07-09 05:27:34 +00:00
|
|
|
#include "glfw.h"
|
2016-07-07 07:04:24 +00:00
|
|
|
#include "graphics.h"
|
2016-07-09 05:27:34 +00:00
|
|
|
#include "model.h"
|
2016-07-16 02:17:27 +00:00
|
|
|
#include "shader.h"
|
2016-07-07 07:04:24 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include <assimp/cimport.h>
|
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/postprocess.h>
|
|
|
|
|
|
|
|
int lovrGraphicsClear(lua_State* L) {
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lovrGraphicsPresent(lua_State* L) {
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-16 02:17:27 +00:00
|
|
|
// TODO default shader
|
|
|
|
int lovrGraphicsSetShader(lua_State* L) {
|
|
|
|
GLuint shader = (GLuint) luaL_checknumber(L, 1);
|
|
|
|
glUseProgram(shader);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-07 07:04:24 +00:00
|
|
|
int lovrGraphicsNewModel(lua_State* L) {
|
2016-07-16 02:17:27 +00:00
|
|
|
const char* path = luaL_checkstring(L, 1);
|
2016-07-09 05:27:34 +00:00
|
|
|
const struct aiScene* scene = aiImportFile(path, aiProcessPreset_TargetRealtime_MaxQuality);
|
2016-07-07 07:04:24 +00:00
|
|
|
|
2016-07-09 05:27:34 +00:00
|
|
|
if (scene) {
|
|
|
|
Model* model = scene->mMeshes[0];
|
|
|
|
luax_pushmodel(L, model);
|
2016-07-07 07:04:24 +00:00
|
|
|
} else {
|
2016-07-09 05:27:34 +00:00
|
|
|
lua_pushnil(L);
|
2016-07-07 07:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-16 02:17:27 +00:00
|
|
|
int lovrGraphicsNewShader(lua_State* L) {
|
|
|
|
const char* vertexShaderSource = luaL_checkstring(L, 1);
|
|
|
|
const char* fragmentShaderSource = luaL_checkstring(L, 2);
|
|
|
|
|
|
|
|
GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource);
|
|
|
|
GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
|
|
|
|
GLuint shader = linkShaders(vertexShader, fragmentShader);
|
|
|
|
|
|
|
|
if (shader) {
|
|
|
|
lua_pushnumber(L, shader);
|
|
|
|
} else {
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-07 07:04:24 +00:00
|
|
|
const luaL_Reg lovrGraphics[] = {
|
|
|
|
{ "clear", lovrGraphicsClear },
|
|
|
|
{ "present", lovrGraphicsPresent },
|
2016-07-16 02:17:27 +00:00
|
|
|
{ "setShader", lovrGraphicsSetShader },
|
2016-07-07 07:04:24 +00:00
|
|
|
{ "newModel", lovrGraphicsNewModel },
|
2016-07-16 02:17:27 +00:00
|
|
|
{ "newShader", lovrGraphicsNewShader },
|
2016-07-07 07:04:24 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|