// call this to bind attribute names int bind_light_shader_attributes(GLuint program) { int errors = 0; errors += get_attrib_location(&OGLAttr::lighting_shader.coord, "l_coord", program); errors += get_uniform_location(&OGLAttr::lighting_shader.mvp, "l_mvp", program); errors += get_uniform_location(&OGLAttr::lighting_shader.position_map, "g_position_map", program); errors += get_uniform_location(&OGLAttr::lighting_shader.color_map, "g_color_map", program); errors += get_uniform_location(&OGLAttr::lighting_shader.color_t_map, "g_color_t_map", program); //errors += get_uniform_location(&OGLAttr::lighting_shader.normal_map, "g_normal_map", program); errors += get_uniform_location(&OGLAttr::lighting_shader.shadow_map, "g_shadow_map", program); errors += get_uniform_location(&OGLAttr::lighting_shader.shadow_mvp, "l_shadow_mvp", program); errors += get_uniform_location(&OGLAttr::lighting_shader.screen_size, "l_screen_size", program); errors += get_uniform_location(&OGLAttr::lighting_shader.val, "l_val", program); errors += get_uniform_location(&OGLAttr::lighting_shader.properties, "l_properties", program); errors += get_uniform_location(&OGLAttr::lighting_shader.draw_mode, "l_draw_mode", program); if (errors) { printf("Could not bind one of the above variables. Aborting\n"); return errors; } printf("Done loading lighting shaders: %d\n", glGetError()); return 0; }
void base::app::load_and_init_shaders(const base::source_location &loc) { assert(_prg == 0); _prg=base::create_program( base::create_and_compile_shader( SRC_LOCATION, "shaders/showtime_v.glsl", GL_VERTEX_SHADER), 0, base::create_and_compile_shader( SRC_LOCATION, "shaders/showtime_f.glsl", GL_FRAGMENT_SHADER)); base::link_program(loc, _prg); _prg_mvp = get_uniform_location(loc, _prg, "mvp"); _prg_size = get_uniform_location(loc, _prg, "size"); _prg_tex = get_uniform_location(loc, _prg, "tex"); }
inline void get_uniform_locations(GLint prg, const ArrayIn& names, std::size_t size, ArrayOut& locs) { for (std::size_t i = 0; i != size; ++i) { locs[i] = get_uniform_location( prg, names[i] ); } }
void CL_OpenGLProgramObjectProvider::set_uniform1i(const CL_StringRef &name, int p1) { throw_if_disposed(); CL_ProgramObjectStateTracker state_tracker(handle); int loc = get_uniform_location(name); if (loc == -1) return; glUniform1i(loc, p1); }
void set_uniform_vec4_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values) { GLint location = get_uniform_location(glsl_program_num, prefix, key); if (location == -1) { return; } check_error(); glUniform4fv(location, num_values, values); check_error(); }
void set_uniform_float(GLuint glsl_program_num, const string &prefix, const string &key, float value) { GLint location = get_uniform_location(glsl_program_num, prefix, key); if (location == -1) { return; } check_error(); glUniform1f(location, value); check_error(); }
int bind_shadow_shader_attributes(GLuint program) { int errors = 0; errors += get_attrib_location(&OGLAttr::shadow_shader.coord, "g_coord", program); errors += get_uniform_location(&OGLAttr::shadow_shader.mvp, "g_mvp", program); if (errors) { printf("Could not bind one of the above variables. Aborting\n"); return errors; } printf("Done loading lighting shaders: %d\n", glGetError()); return 0; }
void program::set_uniform_matrix4x3fv( char const* varname, GLsizei count, GLboolean transpose, GLfloat* value ) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniformMatrix4x3fv(id_, location, count, transpose, value); #else glUniformMatrix4x3fv(location, count, transpose, value); #endif } }
void program::set_uniform4iv(char const* varname, GLsizei count, GLint* value) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniform4iv(id_, location, count, value); #else glUniform4iv(location, count, value); #endif } }
void program::set_uniform4i(char const* varname, GLint v0, GLint v1, GLint v2, GLint v3) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniform4i(id_, location, v0, v1, v2, v3); #else glUniform4i(location, v0, v1, v2, v3); #endif } }
void program::set_uniform1f(char const* varname, GLfloat v0) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniform1f(id_, location, v0); #else glUniform1f(location, v0); #endif } }
void CL_OpenGLProgramObjectProvider::set_uniform_matrix(const CL_StringRef &name, int size, int count, bool transpose, float *data) { throw_if_disposed(); CL_ProgramObjectStateTracker state_tracker(handle); int loc = get_uniform_location(name); if (loc == -1) return; if( size == 2 ) glUniformMatrix2fv(loc, count, transpose, data); else if( size == 3 ) glUniformMatrix3fv(loc, count, transpose, data); else if( size == 4 ) glUniformMatrix4fv(loc, count, transpose, data); else throw CL_Exception(cl_format("Unsupported size given to uniform '%1'.", name)); }
void program::set_uniform4f(char const* varname, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) const { GLint location = get_uniform_location(varname); if (location >= 0) { #if GPUCAST_GL_DIRECT_STATE_ACCESS glProgramUniform4f(id_, location, v0, v1, v2, v3); #else glUniform4f(location, v0, v1, v2, v3); #endif } //assert((location >= 0) && "set_uniform4f() : uniform not in use"); }
void set_uniform_mat3(GLuint glsl_program_num, const string &prefix, const string &key, const Eigen::Matrix3d& matrix) { GLint location = get_uniform_location(glsl_program_num, prefix, key); if (location == -1) { return; } check_error(); // Convert to float (GLSL has no double matrices). float matrixf[9]; for (unsigned y = 0; y < 3; ++y) { for (unsigned x = 0; x < 3; ++x) { matrixf[y + x * 3] = matrix(y, x); } } glUniformMatrix3fv(location, 1, GL_FALSE, matrixf); check_error(); }
// call this to bind attribute names int bind_geometry_shader_attributes(GLuint program) { int errors = 0; errors += get_attrib_location(&OGLAttr::geometry_shader.coord, "g_coord", program); errors += get_attrib_location(&OGLAttr::geometry_shader.texture_coord, "g_texturecoord", program); errors += get_uniform_location(&OGLAttr::geometry_shader.mvp, "g_mvp", program); errors += get_uniform_location(&OGLAttr::geometry_shader.world_transform, "g_worldtransform", program); errors += get_uniform_location(&OGLAttr::geometry_shader.draw_mode, "g_drawmode", program); errors += get_uniform_location(&OGLAttr::geometry_shader.intensity, "g_intensity", program); errors += get_uniform_location(&OGLAttr::geometry_shader.alphacutoff, "g_alphacutoff", program); errors += get_uniform_location(&OGLAttr::geometry_shader.enable_shadows, "g_enable_shadows", program); errors += get_uniform_location(&OGLAttr::geometry_shader.tile_texture, "tile_texture", program); if (errors) { printf("Could not bind one of the above variables. Aborting\n"); return errors; } printf("Done loading geometry shaders: %d\n", glGetError()); return 0; }
void scene_buildings::init_gpu_stuff(const base::source_location &loc){ assert(_prg == 0); char inject_buf[512]; std::string cfg; cfg += "#version 430\n"; sprintf(&inject_buf[0], "#define BLOCKS_PER_IDC %d\n", base::cfg().blocks_per_idc); cfg += inject_buf; _prg = base::create_program( base::create_and_compile_shader( SRC_LOCATION, cfg, "shaders/buildings_v_n.glsl", GL_VERTEX_SHADER), 0,/*base::create_and_compile_shader( SRC_LOCATION, "shaders/buildings_g.glsl", GL_GEOMETRY_SHADER),*/ base::create_and_compile_shader( SRC_LOCATION, cfg, "shaders/buildings_f.glsl", GL_FRAGMENT_SHADER)); base::link_program(loc, _prg); _prg_tb_blocks = get_uniform_location(loc, _prg, "tb_blocks"); _prg_tile_offset = get_uniform_location(loc, _prg, "tile_offset"); _prg_mvp = get_uniform_location(loc, _prg, "mvp"); _prg_total_count = get_uniform_location(loc, _prg, "total_count"); load_tile(glm::ivec2(0, 0)); /*load_tile(glm::ivec2(0, 1)); load_tile(glm::ivec2(0, 2)); load_tile(glm::ivec2(0, 3)); load_tile(glm::ivec2(0, 4)); load_tile(glm::ivec2(0, 5)); load_tile(glm::ivec2(1, 0)); load_tile(glm::ivec2(1, 1)); load_tile(glm::ivec2(1, 2)); load_tile(glm::ivec2(1, 3)); load_tile(glm::ivec2(1, 4)); load_tile(glm::ivec2(1, 5)); load_tile(glm::ivec2(2, 0)); load_tile(glm::ivec2(2, 1)); load_tile(glm::ivec2(2, 2)); load_tile(glm::ivec2(2, 3)); load_tile(glm::ivec2(2, 4)); load_tile(glm::ivec2(2, 5)); load_tile(glm::ivec2(3, 0)); load_tile(glm::ivec2(3, 1)); load_tile(glm::ivec2(3, 2)); load_tile(glm::ivec2(3, 3)); load_tile(glm::ivec2(3, 4)); load_tile(glm::ivec2(3, 5)); load_tile(glm::ivec2(4, 0)); load_tile(glm::ivec2(4, 1)); load_tile(glm::ivec2(4, 2)); load_tile(glm::ivec2(4, 3)); load_tile(glm::ivec2(4, 4)); load_tile(glm::ivec2(4, 5)); load_tile(glm::ivec2(5, 0)); load_tile(glm::ivec2(5, 1)); load_tile(glm::ivec2(5, 2)); load_tile(glm::ivec2(5, 3)); load_tile(glm::ivec2(5, 4)); load_tile(glm::ivec2(5, 5));*/ //base::stats()._ntriangles = 25 * _tiles[0]._blocks_count * 10; const uint32 indices_base[][3] = { { 0, 1, 4 }, { 1, 5, 4 }, { 1, 2, 5 }, { 2, 6, 5 }, { 2, 3, 6 }, { 3, 7, 6 }, { 3, 0, 7 }, { 0, 4, 7 }, { 4, 5, 6 }, { 6, 7, 4 } }; std::vector<uint32> indices; indices.resize(10 * 3 * base::cfg().blocks_per_idc); for (int b = 0; b < base::cfg().blocks_per_idc; b++){ int offset = b * 8; for (int i = 0; i < 30; i++){ indices[b * 30 + i] = (&indices_base[0][0])[i] + offset; } } _indices_vbo = base::create_buffer<uint32>(30 * base::cfg().blocks_per_idc, 0, indices.begin()._Ptr); }
void xd::shader_program::bind_uniform(const std::string& name, const glm::vec3& val) { glUniform3fv(get_uniform_location(name), 1, &val[0]); }
void xd::shader_program::bind_uniform(const std::string& name, float val) { glUniform1f(get_uniform_location(name), val); }
void app_initialize(App *app) { glGenVertexArrays(1, &app->vao); glBindVertexArray(app->vao); glViewport(0, 0, app->window_width, app->window_height); app->vbo_cube = make_cube_mesh(); app->vbo_quad = make_quad_mesh(); get_attrib_location (mapping, position); get_uniform_location(mapping, height_scale); get_uniform_location(mapping, use_mip); get_uniform_location(mapping, max_lod_coverage); get_uniform_location(mapping, screen_size); get_uniform_location(mapping, diffusemap); get_uniform_location(mapping, heightmap); get_uniform_location(mapping, model); get_uniform_location(mapping, view); get_uniform_location(mapping, projection); get_attrib_location (backdrop, position); get_uniform_location(backdrop, sun_dir); get_uniform_location(backdrop, screen_size); get_uniform_location(backdrop, inv_tan_fov); get_uniform_location(backdrop, view); app->current_scene = 0; }
void app_initialize(App *app) { // Make sure the required extensions are present. const GLubyte* extensions = glGetString(GL_EXTENSIONS); char * found_multiview2_extension = strstr ((const char*)extensions, "GL_OVR_multiview2"); char * found_multisample_multiview_extension = strstr ((const char*)extensions, "GL_OVR_multiview_multisampled_render_to_texture"); char * found_border_clamp_extension = strstr ((const char*)extensions, "GL_EXT_texture_border_clamp"); if (found_multiview2_extension == NULL) { LOGI("OpenGL ES 3.0 implementation does not support GL_OVR_multiview2 extension.\n"); exit(EXIT_FAILURE); } if (found_multisample_multiview_extension == NULL) { // If multisampled multiview is not supported, multisampling will not be used, so no need to exit here. LOGI("OpenGL ES 3.0 implementation does not support GL_OVR_multiview_multisampled_render_to_texture extension.\n"); } if (found_border_clamp_extension == NULL) { LOGI("OpenGL ES 3.0 implementation does not support GL_EXT_texture_border_clamp extension.\n"); exit(EXIT_FAILURE); } GL_CHECK(glGenVertexArrays(1, &app->vao)); GL_CHECK(glBindVertexArray(app->vao)); GL_CHECK(glViewport(0, 0, app->window_width, app->window_height)); app->vbo_cube = make_cube(); app->fb = make_eye_framebuffer(Eye_Fb_Resolution_X, Eye_Fb_Resolution_Y, Num_Views); // The coefficients below may be calibrated by photographing an // image containing straight lines, both vertical and horizontal, // through the lenses of the HMD, at the position where the viewer // would be looking through them. // Ideally, the user would be allowed to calibrate them for their // own eyes, through some calibration utility. The application should // then load a stored user-profile on runtime. For now, we hardcode // some values based on our calibration of the SM-R320 Gear VR // lenses. // Left lens app->hmd.left.coefficients_red.k1 = 0.19f; app->hmd.left.coefficients_red.k2 = 0.21f; app->hmd.left.coefficients_red.k3 = 0.0f; app->hmd.left.coefficients_red.p1 = 0.0f; app->hmd.left.coefficients_red.p2 = 0.0f; app->hmd.left.coefficients_green.k1 = 0.22f; app->hmd.left.coefficients_green.k2 = 0.24f; app->hmd.left.coefficients_green.k3 = 0.0f; app->hmd.left.coefficients_green.p1 = 0.0f; app->hmd.left.coefficients_green.p2 = 0.0f; app->hmd.left.coefficients_blue.k1 = 0.24f; app->hmd.left.coefficients_blue.k2 = 0.26f; app->hmd.left.coefficients_blue.k3 = 0.0f; app->hmd.left.coefficients_blue.p1 = 0.0f; app->hmd.left.coefficients_blue.p2 = 0.0f; // Right lens app->hmd.right.coefficients_red.k1 = 0.19f; app->hmd.right.coefficients_red.k2 = 0.21f; app->hmd.right.coefficients_red.k3 = 0.0f; app->hmd.right.coefficients_red.p1 = 0.0f; app->hmd.right.coefficients_red.p2 = 0.0f; app->hmd.right.coefficients_green.k1 = 0.22f; app->hmd.right.coefficients_green.k2 = 0.24f; app->hmd.right.coefficients_green.k3 = 0.0f; app->hmd.right.coefficients_green.p1 = 0.0f; app->hmd.right.coefficients_green.p2 = 0.0f; app->hmd.right.coefficients_blue.k1 = 0.24f; app->hmd.right.coefficients_blue.k2 = 0.26f; app->hmd.right.coefficients_blue.k3 = 0.0f; app->hmd.right.coefficients_blue.p1 = 0.0f; app->hmd.right.coefficients_blue.p2 = 0.0f; // These may be computed by measuring the distance between the top // of the unscaled distorted image and the top of the screen. Denote // this distance by Delta. The normalized view coordinate of the // distorted image top is // Y = 1 - 2 Delta / Screen_Size_Y // We want to scale this coordinate such that it maps to the top of // the view. That is, // Y * fill_scale = 1 // Solving for fill_scale gives the equations below. float delta = Centimeter(0.7f); app->hmd.left.fill_scale = 1.0f / (1.0f - 2.0f * delta / Screen_Size_Y); app->hmd.right.fill_scale = 1.0f / (1.0f - 2.0f * delta / Screen_Size_Y); // These are computed such that the centers of the displayed framebuffers // on the device are seperated by the viewer's IPD. app->hmd.left.image_centre = vec2(+1.0f - Eye_IPD / (Screen_Size_X / 2.0f), 0.0f); app->hmd.right.image_centre = vec2(-1.0f + Eye_IPD / (Screen_Size_X / 2.0f), 0.0f); // These are computed such that the distortion takes place around // an offset determined by the difference between lens seperation // and the viewer's eye IPD. If the difference is zero, the distortion // takes place around the image centre. app->hmd.left.distort_centre = vec2((Lens_IPD - Eye_IPD) / (Screen_Size_X / 2.0f), 0.0f); app->hmd.right.distort_centre = vec2((Eye_IPD - Lens_IPD) / (Screen_Size_X / 2.0f), 0.0f); app->warp_mesh[0] = make_warp_mesh(app->hmd.left); app->warp_mesh[1] = make_warp_mesh(app->hmd.right); get_attrib_location( distort, position); get_attrib_location( distort, uv_red_low_res); get_attrib_location( distort, uv_green_low_res); get_attrib_location( distort, uv_blue_low_res); get_attrib_location( distort, uv_red_high_res); get_attrib_location( distort, uv_green_high_res); get_attrib_location( distort, uv_blue_high_res); get_uniform_location(distort, layer_index); get_uniform_location(distort, framebuffer); get_attrib_location (cube, position); get_attrib_location (cube, normal); get_uniform_location(cube, projection); get_uniform_location(cube, view); get_uniform_location(cube, model); }
void ShaderGLES2::use_material(void *p_material) { RasterizerStorageGLES2::Material *material = (RasterizerStorageGLES2::Material *)p_material; if (!material) { return; } if (!material->shader) { return; } Version *v = version_map.getptr(conditional_version); // bind uniforms for (Map<StringName, ShaderLanguage::ShaderNode::Uniform>::Element *E = material->shader->uniforms.front(); E; E = E->next()) { if (E->get().texture_order >= 0) continue; // this is a texture, doesn't go here Map<StringName, Variant>::Element *V = material->params.find(E->key()); Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > value; value.first = E->get().type; value.second = E->get().default_value; if (V) { value.second = Vector<ShaderLanguage::ConstantNode::Value>(); value.second.resize(E->get().default_value.size()); switch (E->get().type) { case ShaderLanguage::TYPE_BOOL: { if (value.second.size() < 1) value.second.resize(1); value.second.write[0].boolean = V->get(); } break; case ShaderLanguage::TYPE_BVEC2: { if (value.second.size() < 2) value.second.resize(2); int flags = V->get(); value.second.write[0].boolean = flags & 1; value.second.write[1].boolean = flags & 2; } break; case ShaderLanguage::TYPE_BVEC3: { if (value.second.size() < 3) value.second.resize(3); int flags = V->get(); value.second.write[0].boolean = flags & 1; value.second.write[1].boolean = flags & 2; value.second.write[2].boolean = flags & 4; } break; case ShaderLanguage::TYPE_BVEC4: { if (value.second.size() < 4) value.second.resize(4); int flags = V->get(); value.second.write[0].boolean = flags & 1; value.second.write[1].boolean = flags & 2; value.second.write[2].boolean = flags & 4; value.second.write[3].boolean = flags & 8; } break; case ShaderLanguage::TYPE_INT: { if (value.second.size() < 1) value.second.resize(1); int val = V->get(); value.second.write[0].sint = val; } break; case ShaderLanguage::TYPE_IVEC2: { if (value.second.size() < 2) value.second.resize(2); PoolIntArray val = V->get(); for (int i = 0; i < val.size(); i++) { value.second.write[i].sint = val[i]; } } break; case ShaderLanguage::TYPE_IVEC3: { if (value.second.size() < 3) value.second.resize(3); PoolIntArray val = V->get(); for (int i = 0; i < val.size(); i++) { value.second.write[i].sint = val[i]; } } break; case ShaderLanguage::TYPE_IVEC4: { if (value.second.size() < 4) value.second.resize(4); PoolIntArray val = V->get(); for (int i = 0; i < val.size(); i++) { value.second.write[i].sint = val[i]; } } break; case ShaderLanguage::TYPE_UINT: { if (value.second.size() < 1) value.second.resize(1); uint32_t val = V->get(); value.second.write[0].uint = val; } break; case ShaderLanguage::TYPE_UVEC2: { if (value.second.size() < 2) value.second.resize(2); PoolIntArray val = V->get(); for (int i = 0; i < val.size(); i++) { value.second.write[i].uint = val[i]; } } break; case ShaderLanguage::TYPE_UVEC3: { if (value.second.size() < 3) value.second.resize(3); PoolIntArray val = V->get(); for (int i = 0; i < val.size(); i++) { value.second.write[i].uint = val[i]; } } break; case ShaderLanguage::TYPE_UVEC4: { if (value.second.size() < 4) value.second.resize(4); PoolIntArray val = V->get(); for (int i = 0; i < val.size(); i++) { value.second.write[i].uint = val[i]; } } break; case ShaderLanguage::TYPE_FLOAT: { if (value.second.size() < 1) value.second.resize(1); value.second.write[0].real = V->get(); } break; case ShaderLanguage::TYPE_VEC2: { if (value.second.size() < 2) value.second.resize(2); Vector2 val = V->get(); value.second.write[0].real = val.x; value.second.write[1].real = val.y; } break; case ShaderLanguage::TYPE_VEC3: { if (value.second.size() < 3) value.second.resize(3); Vector3 val = V->get(); value.second.write[0].real = val.x; value.second.write[1].real = val.y; value.second.write[2].real = val.z; } break; case ShaderLanguage::TYPE_VEC4: { if (value.second.size() < 4) value.second.resize(4); if (V->get().get_type() == Variant::PLANE) { Plane val = V->get(); value.second.write[0].real = val.normal.x; value.second.write[1].real = val.normal.y; value.second.write[2].real = val.normal.z; value.second.write[3].real = val.d; } else { Color val = V->get(); value.second.write[0].real = val.r; value.second.write[1].real = val.g; value.second.write[2].real = val.b; value.second.write[3].real = val.a; } } break; case ShaderLanguage::TYPE_MAT2: { Transform2D val = V->get(); if (value.second.size() < 4) { value.second.resize(4); } value.second.write[0].real = val.elements[0][0]; value.second.write[1].real = val.elements[0][1]; value.second.write[2].real = val.elements[1][0]; value.second.write[3].real = val.elements[1][1]; } break; case ShaderLanguage::TYPE_MAT3: { Basis val = V->get(); if (value.second.size() < 9) { value.second.resize(9); } value.second.write[0].real = val.elements[0][0]; value.second.write[1].real = val.elements[0][1]; value.second.write[2].real = val.elements[0][2]; value.second.write[3].real = val.elements[1][0]; value.second.write[4].real = val.elements[1][1]; value.second.write[5].real = val.elements[1][2]; value.second.write[6].real = val.elements[2][0]; value.second.write[7].real = val.elements[2][1]; value.second.write[8].real = val.elements[2][2]; } break; case ShaderLanguage::TYPE_MAT4: { Transform val = V->get(); if (value.second.size() < 16) { value.second.resize(16); } value.second.write[0].real = val.basis.elements[0][0]; value.second.write[1].real = val.basis.elements[0][1]; value.second.write[2].real = val.basis.elements[0][2]; value.second.write[3].real = 0; value.second.write[4].real = val.basis.elements[1][0]; value.second.write[5].real = val.basis.elements[1][1]; value.second.write[6].real = val.basis.elements[1][2]; value.second.write[7].real = 0; value.second.write[8].real = val.basis.elements[2][0]; value.second.write[9].real = val.basis.elements[2][1]; value.second.write[10].real = val.basis.elements[2][2]; value.second.write[11].real = 0; value.second.write[12].real = val.origin[0]; value.second.write[13].real = val.origin[1]; value.second.write[14].real = val.origin[2]; value.second.write[15].real = 1; } break; default: { } break; } } else { if (value.second.size() == 0) { // No default value set... weird, let's just use zero for everything size_t default_arg_size = 1; bool is_float = false; switch (E->get().type) { case ShaderLanguage::TYPE_BOOL: case ShaderLanguage::TYPE_INT: case ShaderLanguage::TYPE_UINT: { default_arg_size = 1; } break; case ShaderLanguage::TYPE_FLOAT: { default_arg_size = 1; is_float = true; } break; case ShaderLanguage::TYPE_BVEC2: case ShaderLanguage::TYPE_IVEC2: case ShaderLanguage::TYPE_UVEC2: { default_arg_size = 2; } break; case ShaderLanguage::TYPE_VEC2: { default_arg_size = 2; is_float = true; } break; case ShaderLanguage::TYPE_BVEC3: case ShaderLanguage::TYPE_IVEC3: case ShaderLanguage::TYPE_UVEC3: { default_arg_size = 3; } break; case ShaderLanguage::TYPE_VEC3: { default_arg_size = 3; is_float = true; } break; case ShaderLanguage::TYPE_BVEC4: case ShaderLanguage::TYPE_IVEC4: case ShaderLanguage::TYPE_UVEC4: { default_arg_size = 4; } break; case ShaderLanguage::TYPE_VEC4: { default_arg_size = 4; is_float = true; } break; default: { // TODO matricies and all that stuff default_arg_size = 1; } break; } value.second.resize(default_arg_size); for (size_t i = 0; i < default_arg_size; i++) { if (is_float) { value.second.write[i].real = 0.0; } else { value.second.write[i].uint = 0; } } } } GLint location; if (v->custom_uniform_locations.has(E->key())) { location = v->custom_uniform_locations[E->key()]; } else { int idx = v->uniform_names.find(E->key()); // TODO maybe put those in a Map? if (idx < 0) { location = -1; } else { location = v->uniform_location[idx]; } } _set_uniform_value(location, value); } // bind textures int tc = material->textures.size(); Pair<StringName, RID> *textures = material->textures.ptrw(); for (int i = 0; i < tc; i++) { Pair<ShaderLanguage::DataType, Vector<ShaderLanguage::ConstantNode::Value> > value; value.first = ShaderLanguage::TYPE_INT; value.second.resize(1); value.second.write[0].sint = i; // GLint location = get_uniform_location(textures[i].first); // if (location < 0) { // location = material->shader->uniform_locations[textures[i].first]; // } GLint location = -1; if (v->custom_uniform_locations.has(textures[i].first)) { location = v->custom_uniform_locations[textures[i].first]; } else { location = get_uniform_location(textures[i].first); } _set_uniform_value(location, value); } }
void xd::shader_program::bind_uniform(const std::string& name, const glm::mat4& val) { glUniformMatrix4fv(get_uniform_location(name), 1, GL_FALSE, glm::value_ptr(val)); }