CubeExample(void) : n(16) , screen_prog() , draw_prog() , screen(List("Position")("TexCoord").Get(), shapes::Screen(), screen_prog) , cube(List("Position").Get(), shapes::Cube(), draw_prog) { draw_prog.Use(); UniformBlock(draw_prog, "OffsetBlock").Binding(0); cube_pos<< BufferIndexedTarget::Uniform << 0 << BufferUsage::StaticDraw << OffsetData(n); ProgramUniformSampler(screen_prog, "Palette").Set(0); Texture::Active(0); palette << Texture::Target::_1D << TextureFilter::Nearest << TextureWrap::ClampToEdge << images::LinearGradient( 16, Vec3f(0, 0, 0), std::map<GLfloat, Vec3f>({ { 0.0/16.0, Vec3f(0.0, 0.0, 0.0)}, { 1.0/16.0, Vec3f(0.5, 0.0, 1.0)}, { 3.0/16.0, Vec3f(0.0, 0.0, 1.0)}, { 6.0/16.0, Vec3f(0.0, 0.6, 0.6)}, { 8.0/16.0, Vec3f(0.0, 1.0, 0.0)}, { 11.0/16.0, Vec3f(0.6, 0.6, 0.0)}, { 13.0/16.0, Vec3f(1.0, 0.1, 0.0)}, { 16.0/16.0, Vec3f(0.7, 0.0, 0.0)} }) ); ProgramUniformSampler(screen_prog, "Tex").Set(1); Texture::Active(1); tex << Texture::Target::Rectangle << TextureMinFilter::Nearest << TextureMagFilter::Nearest << TextureWrap::ClampToEdge << images::ImageSpec( 64, 64, Format::Red, InternalFormat::R8, DataType::UnsignedByte ); rbo << Renderbuffer::Target::Renderbuffer << images::ImageSpec(64, 64, InternalFormat::DepthComponent); fbo << Framebuffer::Target::Draw << FramebufferAttachment::Color << tex << FramebufferAttachment::Depth << rbo << FramebufferComplete(); gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.ClearDepth(1.0f); gl.Enable(Capability::CullFace); }
UniformBlock * Program::getUniformBlockByIdentity(const LocationIdentity & identity) { checkDirty(); if (m_uniformBlocks.find(identity) == m_uniformBlocks.end()) m_uniformBlocks[identity] = UniformBlock(this, identity); return &m_uniformBlocks[identity]; }
SortProc(const Particles& particles) { gl.Bind(vao); gl.Bind(BufferTarget::Array, particles.indices_d); (prog|"Index").Setup<GLint>().Enable(); gl.Bind(NoVertexArray()); gl.Bind(BufferIndexedTarget::TransformFeedback, 0, particles.indices_f); gl.Bind(BufferIndexedTarget::Uniform, 0, particles.indices_d); gl.Bind(BufferIndexedTarget::Uniform, 1, particles.distances); gl.Use(prog); UniformBlock(prog,"IndexBlock").Binding(0); UniformBlock(prog, "DistBlock").Binding(1); gl.Use(NoProgram()); }
UniformBlock Visitor::synthesizeBlock(pugi::xml_node xml_data) { int binding_pt = xml_data.attribute("BindingPoint").as_int(); UniformBlock to_add = UniformBlock(xml_data.attribute("Name").as_string(), binding_pt); for (pugi::xml_node_iterator uniform = xml_data.begin(); uniform != xml_data.end(); ++uniform) { std::string uniform_name = uniform->attribute("Name").as_string(); //Keep track of the running total size in bytes of the uniform block int block_size = 0; std::string type = uniform->attribute("Type").as_string(); float* uniform_data; if (strcmp(type.c_str(), "float") == 0) { block_size = 1; float data_str = uniform->attribute("Data0").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str; } else if (strcmp(type.c_str(), "vec2") == 0) { block_size = 2; float data_str = uniform->attribute("Data0").as_float(); float data_str1 = uniform->attribute("Data1").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str; uniform_data[1] = data_str1; } else if (strcmp(type.c_str(), "vec3") == 0) { block_size = 3; float data_str0 = uniform->attribute("Data0").as_float(); float data_str1 = uniform->attribute("Data1").as_float(); float data_str2 = uniform->attribute("Data2").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str0; uniform_data[1] = data_str1; uniform_data[2] = data_str2; } else if (strcmp(type.c_str(), "vec4") == 0) { block_size = 4; float data_str0 = uniform->attribute("Data0").as_float(); float data_str1 = uniform->attribute("Data1").as_float(); float data_str2 = uniform->attribute("Data2").as_float(); float data_str3 = uniform->attribute("Data3").as_float(); uniform_data = new float[block_size]; uniform_data[0] = data_str0; uniform_data[1] = data_str1; uniform_data[2] = data_str2; uniform_data[3] = data_str3; } //TODO: Check for other types ShaderParameter next_uniform = ShaderParameter(uniform_name, block_size * 4, block_size, uniform_data, true); to_add.addParameter(next_uniform); } return to_add; }
void XmlVisitor::visitCompositeGrid(CompositeGrid* tiles) { if (tiles->is_leaf) { std::string current = file_handler.getNextPath(); pugi::xml_parse_result res = doc.load_file(current.c_str()); if (!res) std::cout << "Errors in XML file\n" << current.c_str() << "\n"; for (pugi::xml_node_iterator current = doc.root().begin(); current != doc.root().end(); ++current) { for (pugi::xml_node_iterator resource = current->begin(); resource != current->end(); ++resource) { if (std::strcmp(resource->name(), "TriangleMesh") == 0) { std::string fs_path = resource->attribute("FSPath").as_string(); std::string vs_path = resource->attribute("VSPath").as_string(); std::string obj_path = resource->attribute("ObjFile").as_string(); std::string tex_path = resource->attribute("Texture").as_string(); pugi::xml_attribute test = resource->attribute("UniformBlock"); std::string uniform_block = resource->attribute("UniformBlock").as_string(); ObjectState scenario_state = scene_objects.synthesizeObject(vs_path.append(fs_path), obj_path, tex_path); UniformBlock to_add = UniformBlock(uniform_block, 0); float* model_view = new float[16]; float* projection = new float[16]; int k = 0; float l = 4.0 * (float) tiles->left / 512.0 - 4.0; float r = 4.0 * (float) tiles->right / 512.0 - 4.0; float b = 4.0 * (float) tiles->bottom / 512.0 - 4.0; float t = 4.0 * (float) tiles->top / 512.0 - 4.0; model_view[0] = 0.01; model_view[1] = 0; model_view[2] = 0; model_view[3] = 0; model_view[4] = 0; model_view[5] = 0.01; model_view[6] = 0; model_view[7] = 0; model_view[8] = 0; model_view[9] = 0; model_view[10] = 0.01; model_view[11] = 0; model_view[12] = (l + r) / 2; model_view[13] = (b + t) / 2; model_view[14] = -3.0; model_view[15] = 1; projection[0] = 1; projection[1] = 0; projection[2] = 0; projection[3] = 0; projection[4] = 0; projection[5] = 1; projection[6] = 0; projection[7] = 0; projection[8] = 0; projection[9] = 0; projection[10] = -11.0 / 9.0; projection[11] = -1; projection[12] = 0; projection[13] = 0; projection[14] = -20.0 / 9.0; projection[15] = 0; ShaderParameter param = ShaderParameter("ModelView", 16 * 4, 16, model_view, true); ShaderParameter param2 = ShaderParameter("Projection", 16 * 4, 16, projection, true); to_add.addParameter(param); to_add.addParameter(param2); scenario_state.addUniformBlock(to_add); tiles->meshes.push_back( TriangleMesh(scenario_state) ); } } } } if (!tiles->is_leaf) for (CompositeGrid* child: tiles->children) child->acceptVisitor(this); }