static int lnewdfont(lua_State *L) { int width = luaL_checkinteger(L, 1); int height = luaL_checkinteger(L, 2); int format = luaL_checkinteger(L, 3); int id = luaL_checkinteger(L, 4); lua_createtable(L, 0, 1); size_t size = dfont_data_size(width, height); void * d = lua_newuserdata(L, size); dfont_init(d, width, height); lua_setfield(L, -2, "__obj"); const char* err = texture_load(id, (enum TEXTURE_FORMAT)format, width, height, NULL, 0); if (err) { return luaL_error(L, err); } RID tex = texture_glid(id); render_texture_update(R, tex, width, height, NULL, 0, 0); lua_pushinteger(L, id); lua_setfield(L, -2, "texture"); return 1; }
const char * texture_load(int id, enum TEXTURE_FORMAT pixel_format, int pixel_width, int pixel_height, void *data, int reduce) { if (id >= MAX_TEXTURE) { return "Too many texture"; } struct texture * tex = &POOL.tex[id]; if (id >= POOL.count) { POOL.count = id + 1; } tex->fb = 0; tex->width = pixel_width; tex->height = pixel_height; tex->invw = 1.0f / (float)pixel_width; tex->invh = 1.0f / (float)pixel_height; if (tex->id == 0) { tex->id = render_texture_create(R, pixel_width, pixel_height, pixel_format, TEXTURE_2D, 0); } if (data == NULL) { // empty texture return NULL; } if (reduce) { texture_reduce(pixel_format, &pixel_width, &pixel_height, data); } render_texture_update(R, tex->id, pixel_width, pixel_height, data, 0, 0); return NULL; }
void label_load() { if (Dfont) return; Dfont = dfont_create(TEX_WIDTH, TEX_HEIGHT); Tex = render_texture_create(R, TEX_WIDTH, TEX_HEIGHT, TEX_FMT, TEXTURE_2D, 0); render_texture_update(R, Tex, TEX_WIDTH, TEX_HEIGHT ,NULL, 0, 0); }
RID render_target_create(struct render *R, int width, int height, enum TEXTURE_FORMAT format) { RID tex = render_texture_create(R, width, height, format, TEXTURE_2D, 0); if (tex == 0) return 0; render_texture_update(R, tex, width, height, NULL, 0, 0); RID rt = create_rt(R, tex); glBindFramebuffer(GL_FRAMEBUFFER, R->default_framebuffer); R->last.target = 0; R->changeflag |= CHANGE_TARGET; if (rt == 0) { render_release(R, TEXTURE, tex); } CHECK_GL_ERROR return rt; }
const char * texture_update(int id, int pixel_width, int pixel_height, void *data) { if (id >= MAX_TEXTURE) { return "Too many texture"; } if(data == NULL){ return "no content"; } struct texture * tex = &POOL.tex[id]; if(tex->id == 0){ return "not a valid texture"; } render_texture_update(R, tex->id, pixel_width, pixel_height, data, 0, 0); return NULL; }
static int _texture_create(int type, int width, int height, const void* data, int channel, unsigned int id) { enum TEXTURE_FORMAT t = TEXTURE_RGBA8; switch (type) { case DTEX_TF_RGBA8: t = TEXTURE_RGBA8; break; case DTEX_TF_PVR4: t = TEXTURE_PVR4; break; default: assert(0); } struct render* r = sl_shader_get_render(); int texid = render_texture_create(r, width, height, t, TEXTURE_2D, 0); render_texture_update(r, texid, width, height, data, 0, 0); return texid; }