Exemplo 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;
}
Exemplo n.º 2
0
static int l_graphics_gcImage(lua_State* state) {
  l_graphics_Image* img = l_graphics_toImage(state, 1);

  graphics_Image_free(&img->image);
  luaL_unref(state, LUA_REGISTRYINDEX, img->imageDataRef);
  return 0;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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;
}
Exemplo n.º 8
0
static void sendSamplers(lua_State *state, l_graphics_Shader* shader, graphics_ShaderUniformInfo const* info) {
  if(l_graphics_isCanvas(state, 3)) {
    graphics_Canvas * canvas = l_graphics_toCanvas(state, 3);
    referenceAndSendTexture(state, shader, info, canvas->image.texID);
  } else if(l_graphics_isImage(state,3)) {
    l_graphics_Image * image = l_graphics_toImage(state, 3);
    referenceAndSendTexture(state, shader, info, image->image.texID);
  } else {
    lua_pushstring(state, "Expected texture");
    lua_error(state);
  }
}
Exemplo n.º 9
0
static int l_graphics_Image_getWrap(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);

  graphics_Wrap wrap;
  graphics_Image_getWrap(&img->image, &wrap);

  l_tools_pushEnum(state, wrap.horMode, l_graphics_WrapMode);
  l_tools_pushEnum(state, wrap.verMode, l_graphics_WrapMode);

  return 2;
}
Exemplo n.º 10
0
static int l_graphics_Image_setFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);
  graphics_Filter newFilter;
  graphics_Image_getFilter(&img->image, &newFilter);
  newFilter.minMode = l_tools_toEnumOrError(state, 2, l_graphics_FilterMode);
  newFilter.magMode = l_tools_toEnumOrError(state, 3, l_graphics_FilterMode);
  newFilter.maxAnisotropy = luaL_optnumber(state, 4, 1.0f);
  graphics_Image_setFilter(&img->image, &newFilter);

  return 0;
}
Exemplo n.º 11
0
int l_graphics_SpriteBatch_setTexture(lua_State* state) {
  l_assertType(state, 1, l_graphics_isBatch);

  l_graphics_Batch * batch = l_graphics_toBatch(state, 1);

  l_graphics_Image const* image = l_graphics_toImage(state, 2);

  batch->batch.texture = &image->image;
  luaL_unref(state, LUA_REGISTRYINDEX, batch->textureRef);
  lua_settop(state, 2);
  batch->textureRef = luaL_ref(state, LUA_REGISTRYINDEX);

  return 0;
}
Exemplo n.º 12
0
static int l_graphics_Image_getMipmapFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);

  graphics_Filter filter;

  graphics_Image_getFilter(&img->image, &filter);

  l_tools_pushEnum(state, filter.mipmapMode, l_graphics_FilterMode);
  lua_pushnumber(state, filter.mipmapLodBias);

  return 2;
}
Exemplo n.º 13
0
int l_graphics_newSpriteBatch(lua_State* state) {
  l_graphics_Image const* image = l_graphics_toImage(state, 1);

  int count = luaL_optnumber(state, 2, 128);

  l_graphics_Batch* batch = lua_newuserdata(state, sizeof(l_graphics_Batch));
  graphics_Batch_new(&batch->batch, &image->image, count, graphics_BatchUsage_static);

  lua_pushvalue(state, 1);
  batch->textureRef = luaL_ref(state, LUA_REGISTRYINDEX);

  lua_rawgeti(state, LUA_REGISTRYINDEX, moduleData.batchMT);
  lua_setmetatable(state, -2);
  return 1;
}
Exemplo n.º 14
0
static int l_graphics_Image_getFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);

  graphics_Filter filter;

  graphics_Image_getFilter(&img->image, &filter);

  l_tools_pushEnum(state, filter.minMode, l_graphics_FilterMode);
  l_tools_pushEnum(state, filter.magMode, l_graphics_FilterMode);
  lua_pushnumber(state, filter.maxAnisotropy);

  return 3;
}
Exemplo n.º 15
0
static int l_graphics_Image_setMipmapFilter(lua_State* state) {
  l_assertType(state, 1, l_graphics_isImage);

  l_graphics_Image* img = l_graphics_toImage(state, 1);

  graphics_Filter newFilter;
  graphics_Image_getFilter(&img->image, &newFilter);

  if(lua_isnoneornil(state, 2)) {
      newFilter.mipmapMode  = graphics_FilterMode_none;
      newFilter.mipmapLodBias = 0.0f;
    } else {
      newFilter.mipmapMode  = l_tools_toEnumOrError(state, 2, l_graphics_FilterMode);
      // param 2 is supposed to be "sharpness", which is exactly opposite to LOD,
      // therefore we use the negative value
      newFilter.mipmapLodBias = -luaL_optnumber(state, 3, 0.0f);
    }
  graphics_Image_setFilter(&img->image, &newFilter);

  return 0;
}