void device_load_texture(gs_device_t *device, gs_texture_t *tex, int unit) { struct gs_shader_param *param; struct gs_sampler_state *sampler; struct gs_texture *cur_tex = device->cur_textures[unit]; /* need a pixel shader to properly bind textures */ if (!device->cur_pixel_shader) tex = NULL; if (cur_tex == tex) return; if (!gl_active_texture(GL_TEXTURE0 + unit)) goto fail; /* the target for the previous text may not be the same as the * next texture, so unbind the previous texture first to be safe */ if (cur_tex && (!tex || cur_tex->gl_target != tex->gl_target)) gl_bind_texture(cur_tex->gl_target, 0); device->cur_textures[unit] = tex; param = get_texture_param(device, unit); if (!param) return; param->texture = tex; if (!tex) return; // texelFetch doesn't need a sampler if (param->sampler_id != (size_t)-1) sampler = device->cur_samplers[param->sampler_id]; else sampler = NULL; if (!gl_bind_texture(tex->gl_target, tex->texture)) goto fail; if (sampler && !load_texture_sampler(tex, sampler)) goto fail; return; fail: blog(LOG_ERROR, "device_load_texture (GL) failed"); }
void device_load_texture(device_t device, texture_t tex, int unit) { struct shader_param *param; struct gs_sampler_state *sampler; struct gs_texture *cur_tex = device->cur_textures[unit]; /* need a pixel shader to properly bind textures */ if (!device->cur_pixel_shader) tex = NULL; if (cur_tex == tex) return; if (!gl_active_texture(GL_TEXTURE0 + unit)) goto fail; if (cur_tex && cur_tex->gl_target != tex->gl_target) gl_bind_texture(cur_tex->gl_target, 0); device->cur_textures[unit] = tex; param = get_texture_param(device, unit); if (!param) return; param->texture = tex; if (!tex) return; sampler = device->cur_samplers[param->sampler_id]; if (!gl_bind_texture(tex->gl_target, tex->texture)) goto fail; if (sampler && !load_texture_sampler(tex, sampler)) goto fail; return; fail: blog(LOG_ERROR, "device_load_texture (GL) failed"); }
static bool load_sampler_on_textures(device_t device, samplerstate_t ss, int sampler_unit) { struct gs_shader *shader = device->cur_pixel_shader; size_t i; for (i = 0; i < shader->params.num; i++) { struct shader_param *param = shader->params.array+i; if (param->type == SHADER_PARAM_TEXTURE && param->sampler_id == (uint32_t)sampler_unit && param->texture) { if (!gl_active_texture(GL_TEXTURE0 + param->texture_id)) return false; if (!load_texture_sampler(param->texture, ss)) return false; } } return true; }