I am creating an API in C++ for our game which will be called from lua. The scripts will be dynamically loaded to speed up testing and prototyping.
We're creating the game from scratch and I am using OpenGL and shaders to render graphics. In particular we want to export functions like these:
I want CreateShader() to work only during initialization phase, but after the OpenGL context had been created calling it everywhere else would be îllégâl. I have this struct in C++:
These were the options I gathered:
So alin yung gamit niyo sa game engine? Do you have better ideas to implement such feature? Kaya ko rin i-modify yung lua para ma-embed yung contexts natively pero ma dedelay kami... illustrator din kasi ako
references:
You do not have permission to view the full content of this post. Log in or register now.
We're creating the game from scratch and I am using OpenGL and shaders to render graphics. In particular we want to export functions like these:
testscript.lua
Pero gusto ko i-introduce yung concept ng contexts - not the "state" or "context" object you usually pass around as first parameter in c - but rather the scope in which functions can be called.
Code:
params = {}
-- name of the shader object
params.name = "simple"
-- load vertex shader
params.vert = GetFileContents("simple.vert")
-- conveniently code glsl directly
params.frag = [[
#version 130
in vec3 color;
void main() {
gl_FragColor = vec4(color, 1.0);
}]]
local shader = CreateShader(params)
I want CreateShader() to work only during initialization phase, but after the OpenGL context had been created calling it everywhere else would be îllégâl. I have this struct in C++:
lua_AIPstate.h
This should be enough to validate function calls, however the problem is *how* to pass this struct around.
Code:
struct AIPstate {
enum {
PreInit, // pre-initialization no opengl context is active yet
Init, // this is where CreateShader() is legal
Update,
Render
} context;
GLFWwindow* window;
// ...
};
These were the options I gathered:
a) put this struct in lua registry and,
b) pass a context object around
Yung unang option parang maganda, pero may consistent overhead sa mga context-sensitive functions. Yung second option naman eh boilerplate sa lua script:b) pass a context object around
Code:
function Initialize(context)
-- passing 'context' around reduces productivity and more opportunity for bugs
shader = CreateShader(context, params)
invProj = GetShaderUniform(context, shader, "invProj")
pos = GetShaderAttribute(context, shader, "pos")
end
references:
You do not have permission to view the full content of this post. Log in or register now.