Ejemplo n.º 1
0
static int l_graphics_Image_getHeight(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  lua_pushinteger(state, img->image.height);
  return 1;
}
Ejemplo n.º 2
0
static int l_graphics_Shader_getExternVariable(lua_State* state) {
  l_assertType(state, 1, l_graphics_isShader); 
  l_graphics_Shader const* shader = l_graphics_toShader(state, 1);

  char const* name = l_tools_toStringOrError(state, 2);

  graphics_ShaderUniformInfo const* info = graphics_Shader_getUniform(&shader->shader, name);

  if(!info) {
    goto errout;
  }
  
  graphics_ShaderUniformType type =  graphics_shader_toMotorType(info->type);
  if(type == graphics_ShaderUniformType_none) {
    goto errout;
  }

  l_tools_pushEnum(state, type, l_graphics_ShaderUniformType);
  lua_pushnumber(state, graphics_shader_toMotorComponents(info->type));
  lua_pushnumber(state, info->elements);

  return 3;

errout:
  lua_pushnil(state);
  lua_pushnil(state);
  lua_pushnil(state);
  return 3;
}
Ejemplo n.º 3
0
static int l_graphics_SpriteBatch_set(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  int id = l_tools_toNumberOrError(state, 2);

  graphics_Quad const * quad = &defaultQuad;
  int baseidx = 3;

  if(l_graphics_isQuad(state, 3)) {
    quad = l_graphics_toQuad(state, 3);
    baseidx = 4;
  }

  float x  = luaL_optnumber(state, baseidx,     0.0f);
  float y  = luaL_optnumber(state, baseidx + 1, 0.0f);
  float r  = luaL_optnumber(state, baseidx + 2, 0.0f);
  float sx = luaL_optnumber(state, baseidx + 3, 1.0f);
  float sy = luaL_optnumber(state, baseidx + 4, sx);
  float ox = luaL_optnumber(state, baseidx + 5, 0.0f);
  float oy = luaL_optnumber(state, baseidx + 6, 0.0f);
  float kx = luaL_optnumber(state, baseidx + 7, 0.0f);
  float ky = luaL_optnumber(state, baseidx + 8, 0.0f);

  //graphics_Batch_set(&batch->batch, id, quad, x, y, r, sx, sy, ox, oy, kx, ky);

  return 0;
}
Ejemplo n.º 4
0
static int l_graphics_SpriteBatch_add(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  graphics_Quad const * quad = &defaultQuad;
  int baseidx = 2;

  if(l_graphics_isQuad(state, 2)) {
    quad = l_graphics_toQuad(state, 2);
    baseidx = 3;
  }

  float x  = luaL_optnumber(state, baseidx,     0.0f);
  float y  = luaL_optnumber(state, baseidx + 1, 0.0f);
  float r  = luaL_optnumber(state, baseidx + 2, 0.0f);
  float sx = luaL_optnumber(state, baseidx + 3, 1.0f);
  float sy = luaL_optnumber(state, baseidx + 4, sx);
  float ox = luaL_optnumber(state, baseidx + 5, 0.0f);
  float oy = luaL_optnumber(state, baseidx + 6, 0.0f);
  float kx = luaL_optnumber(state, baseidx + 7, 0.0f);
  float ky = luaL_optnumber(state, baseidx + 8, 0.0f);

  int i = graphics_Batch_add(&batch->batch, quad, x, y, r, sx, sy, ox, oy, kx, ky);
  lua_pushinteger(state, i);


  return 1;
}
Ejemplo n.º 5
0
static int l_graphics_Mesh_getVertexCount(lua_State *state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh const *mesh = l_graphics_toMesh(state, 1);

  lua_pushnumber(state, graphics_Mesh_getVertexCount(&mesh->mesh));
  return 1;
}
Ejemplo n.º 6
0
static int l_audio_SourceCommon_setVolume(lua_State *state) {
  l_assertType(state, 1, isSource);
  float gain = l_tools_toNumberOrError(state, 2);
  audio_SourceCommon *source = (audio_SourceCommon*)lua_touserdata(state, 1);
  audio_SourceCommon_setVolume(source, gain);
  return 0;
}
Ejemplo n.º 7
0
static int l_graphics_Mesh_setVertexMap(lua_State *state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh *mesh = l_graphics_toMesh(state, 1);
  
  size_t top = (size_t)lua_gettop(state);
  if(top == 1) {
    graphics_Mesh_setVertexMap(&mesh->mesh, 0, 0);
    return 0;
  } 
  
  size_t count;
  if(top > 2) {
    ensureBufferSize(sizeof(uint32_t) * (top - 1));
    for(int i = 0; i < top - 1; ++i) {
      ((uint32_t*)moduleData.buffer)[i] = (uint32_t)l_tools_toNumberOrError(state, i + 2) - 1;
      printf("Index: %d\n", ((uint32_t*)moduleData.buffer)[i]);
    }
    count = top - 1;
  } else {
    size_t len = (size_t)lua_objlen(state, 2);
    ensureBufferSize(len * sizeof(uint32_t));
    for(int i = 0; i < len; ++i) {
      lua_rawgeti(state, 2, i+1);
      ((uint32_t*)moduleData.buffer)[i] = (uint32_t)l_tools_toNumberOrError(state, -1) - 1;
    }
    count = len;
  }

  graphics_Mesh_setVertexMap(&mesh->mesh, count, (uint32_t*)moduleData.buffer);

  return 0;
}
Ejemplo n.º 8
0
static int l_graphics_Image_getDimensions(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  lua_pushinteger(state, img->image.width);
  lua_pushinteger(state, img->image.height);
  return 2;
}
Ejemplo n.º 9
0
static int l_graphics_Image_getPath(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  
  lua_pushstring (state, img->path);
  return 1;
}
Ejemplo n.º 10
0
static int l_graphics_Shader_getWarnings(lua_State *state) {
  l_assertType(state, 1, l_graphics_isShader); 
  l_graphics_Shader const* shader = l_graphics_toShader(state, 1);

  pushShaderInfoLog(state, &shader->shader);

  return 1;
}
Ejemplo n.º 11
0
static int l_graphics_SpriteBatch_clear(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);
  graphics_Batch_clear(&batch->batch);

  return 0;
}
Ejemplo n.º 12
0
static int l_graphics_Font_getBaseline(lua_State* state) {
  l_assertType(state, 1, l_graphics_isFont);

  graphics_Font* font = l_graphics_toFont(state, 1);

  lua_pushinteger(state, graphics_Font_getBaseline(font));
  return 1;
}
Ejemplo n.º 13
0
static int l_graphics_Mesh_getTexture(lua_State* state) {
  l_assertType(state, 1, l_graphics_isMesh);

  l_graphics_Mesh * mesh = l_graphics_toMesh(state, 1);

  lua_rawgeti(state, LUA_REGISTRYINDEX, mesh->textureRef);

  return 1;
}
Ejemplo n.º 14
0
static int l_graphics_Mesh_setDrawMode(lua_State *state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh *mesh = l_graphics_toMesh(state, 1);
  
  graphics_MeshDrawMode mode = l_tools_toEnumOrError(state, 2, l_graphics_MeshDrawMode);

  graphics_Mesh_setDrawMode(&mesh->mesh, mode);
  return 0;
}
Ejemplo n.º 15
0
static int l_graphics_Font_getHeight(lua_State* state) {
  l_assertType(state, 1, l_graphics_isFont);

  graphics_Font* font = l_graphics_toFont(state, 1);
  
  int height = graphics_Font_getHeight(font);
  lua_pushinteger(state, height);
  return 1;
}
Ejemplo n.º 16
0
int l_graphics_SpriteBatch_getCount(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  lua_pushnumber(state, batch->batch.insertPos);

  return 1;
}
Ejemplo n.º 17
0
int l_graphics_SpriteBatch_getTexture(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  lua_rawgeti(state, LUA_REGISTRYINDEX, batch->textureRef);

  return 1;
}
Ejemplo n.º 18
0
static int l_graphics_Image_getData(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);

  lua_rawgeti(state, LUA_REGISTRYINDEX, img->imageDataRef);

  return 1;
}
Ejemplo n.º 19
0
int l_graphics_SpriteBatch_getBufferSize(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  lua_pushnumber(state, batch->batch.maxCount);

  return 1;
}
Ejemplo n.º 20
0
static int l_audio_StaticSource_clone(lua_State *state) {
  l_assertType(state, 1, l_audio_isStaticSource);
  audio_StaticSource *oldSrc = l_audio_toStaticSource(state, 1);
  audio_StaticSource *newSrc = lua_newuserdata(state, sizeof(audio_StaticSource));
  audio_StaticSource_clone(oldSrc, newSrc);
  lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.staticMT);
  lua_setmetatable(state, -2);
  return 1;
}
Ejemplo n.º 21
0
static int l_graphics_Mesh_getDrawMode(lua_State *state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh const *mesh = l_graphics_toMesh(state, 1);
  
  graphics_MeshDrawMode mode = graphics_Mesh_getDrawMode(&mesh->mesh);

  l_tools_pushEnum(state, mode, l_graphics_MeshDrawMode);

  return 1;
}
Ejemplo n.º 22
0
static int l_graphics_Mesh_setVertexColors(lua_State* state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh * mesh = l_graphics_toMesh(state, 1);

  bool use = l_tools_toBooleanOrError(state, 2);

  graphics_Mesh_setVertexColors(&mesh->mesh, use);

  return 0;
}
Ejemplo n.º 23
0
static int l_graphics_Quad_getViewport(lua_State* state) {
  l_assertType(state, 1, l_graphics_isQuad);

  graphics_Quad *quad = l_graphics_toQuad(state, 1);
  lua_pushnumber(state, quad->x);
  lua_pushnumber(state, quad->y);
  lua_pushnumber(state, quad->w);
  lua_pushnumber(state, quad->h);

  return 4;
}
Ejemplo n.º 24
0
static int l_graphics_Font_getWrap(lua_State* state) {
  l_assertType(state, 1, l_graphics_isFont);

  graphics_Font* font = l_graphics_toFont(state, 1);

  char const* line = l_tools_toStringOrError(state, 2);
  int width = l_tools_toNumberOrError(state, 3);

  lua_pushinteger(state, graphics_Font_getWrap(font, line, width, NULL));
  return 1;
}
Ejemplo n.º 25
0
static int l_graphics_Mesh_setVertices(lua_State* state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh *mesh = l_graphics_toMesh(state, 1);

  bool hasColor;
  size_t count = readVertices(state, &hasColor, 2);

  graphics_Mesh_setVertices(&mesh->mesh, count, (graphics_Vertex const*)moduleData.buffer);

  return 0;
}
Ejemplo n.º 26
0
static int l_graphics_Image_refresh(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);
  l_graphics_Image* img = l_graphics_toImage(state, 1);

  lua_rawgeti(state, LUA_REGISTRYINDEX, img->imageDataRef);
  image_ImageData *data = l_image_toImageData(state, -1);

  graphics_Image_refresh(&img->image, data);

  return 0;
}
Ejemplo n.º 27
0
int l_graphics_SpriteBatch_setBufferSize(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  int newsize = l_tools_toNumberOrError(state, 2);

  graphics_Batch_changeBufferSize(&batch->batch, newsize);

  return 0;
}
Ejemplo n.º 28
0
static int l_graphics_Image_setWrap(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  graphics_Wrap wrap;
  wrap.horMode = l_tools_toEnumOrError(state, 2, l_graphics_WrapMode);
  wrap.verMode = l_tools_toEnumOrError(state, 3, l_graphics_WrapMode);

  graphics_Image_setWrap(&img->image, &wrap);

  return 0;
}
Ejemplo n.º 29
0
static int l_graphics_Shader_send(lua_State *state) {
  l_assertType(state, 1, l_graphics_isShader); 
  l_graphics_Shader* shader = l_graphics_toShader(state, 1);

  char const* name = l_tools_toStringOrError(state, 2);

  graphics_ShaderUniformInfo const* info = graphics_Shader_getUniform(&shader->shader, name);

  switch(info->type) {
  case GL_INT:
    sendIntegers(state, shader, info);
    break;

  case GL_FLOAT:
    sendFloats(state, shader, info);
    break;

  case GL_BOOL:
    sendBooleans(state, shader, info);
    break;

  case GL_INT_VEC2:
  case GL_INT_VEC3:
  case GL_INT_VEC4:
    sendIntegerVectors(state, shader, info);
    break;

  case GL_FLOAT_VEC2:
  case GL_FLOAT_VEC3:
  case GL_FLOAT_VEC4:
    sendFloatVectors(state, shader, info);
    break;

  case GL_BOOL_VEC2:
  case GL_BOOL_VEC3:
  case GL_BOOL_VEC4:
    sendBooleanVectors(state, shader, info);
    break;

  case GL_FLOAT_MAT2:
  case GL_FLOAT_MAT3:
  case GL_FLOAT_MAT4:
    sendFloatMatrices(state, shader, info);
    break;

  case GL_SAMPLER_2D:
    sendSamplers(state, shader, info);
    break;

  };

  return 0;
}
Ejemplo n.º 30
0
static int l_graphics_Mesh_getDrawRange(lua_State *state) {
  l_assertType(state, 1, l_graphics_isMesh);
  l_graphics_Mesh const* mesh = l_graphics_toMesh(state, 1);

  int idx1, idx2;
  if(graphics_Mesh_getDrawRange(&mesh->mesh, &idx1, &idx2)) {
    lua_pushnumber(state, idx1);
    lua_pushnumber(state, idx2);
    return 2;
  }
  return 0;
}