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"); }