コード例 #1
0
ファイル: 029_flares.cpp プロジェクト: matus-chochlik/oglplus
    Shape(const Program& prog, const ShapeBuilder& builder)
      : make_shape(builder)
      , shape_instr(make_shape.Instructions())
      , shape_indices(make_shape.Indices())
      , vbos(4) {
        // bind the VAO for the shape
        vao.Bind();

        typename ShapeBuilder::VertexAttribs vert_attr_info;
        const GLchar* vert_attr_name[] = {
          "Position", "Normal", "Tangent", "TexCoord"};
        for(int va = 0; va != 4; ++va) {
            const GLchar* name = vert_attr_name[va];
            std::vector<GLfloat> data;
            auto getter = vert_attr_info.VertexAttribGetter(data, name);
            if(getter != nullptr)
                try {
                    // bind the VBO for the vertex attribute
                    vbos[va].Bind(Buffer::Target::Array);
                    GLuint npv = getter(make_shape, data);
                    // upload the data
                    Buffer::Data(Buffer::Target::Array, data);
                    // setup the vertex attribs array
                    VertexArrayAttrib attr(prog, name);
                    attr.Setup<GLfloat>(npv);
                    attr.Enable();
                } catch(Error&) {
                }
        }
    }
コード例 #2
0
ファイル: wrapper.hpp プロジェクト: BrainlessLabsInc/oglplus
	void _init(
		const ShapeBuilder& builder,
		const ShapeIndices& shape_indices,
		Iterator name,
		Iterator end
	)
	{
		VertexArray::Unbind();
		typename ShapeBuilder::VertexAttribs vert_attr_info;
		unsigned i = 0;
		std::vector<GLfloat> data;
		while(name != end)
		{
			auto getter = vert_attr_info.VertexAttribGetter(
				data,
				*name
			);
			if(getter != nullptr)
			{
				_vbos[i].Bind(Buffer::Target::Array);
				_npvs[i] = getter(builder, data);
				_names[i] = *name;

				Buffer::Data(Buffer::Target::Array, data);
			}
			++name;
			++i;
		}

		if(!shape_indices.empty())
		{
			assert((i+1) == _npvs.size());
			assert((i+1) == _vbos.size());

			_npvs[i] = 1;
			_vbos[i].Bind(Buffer::Target::ElementArray);
			Buffer::Data(
				Buffer::Target::ElementArray,
				shape_indices
			);
		}

		builder.BoundingSphere(_bounding_sphere);
	}
コード例 #3
0
	Shape(const Program& prog, const ShapeBuilder& builder)
	 : make_shape(builder)
	 , shape_instr(make_shape.Instructions())
	 , shape_indices(make_shape.Indices())
	 , nva(4)
	 , vbos(nva+1)
	{
		vao.Bind();

		typename ShapeBuilder::VertexAttribs vert_attr_info;
		const GLchar* vert_attr_name[] = {
			"Position",
			"Normal",
			"Tangent",
			"TexCoord"
		};
		for(GLuint va=0; va!=nva; ++va)
		{
			const GLchar* name = vert_attr_name[va];
			std::vector<GLfloat> data;
			auto getter = vert_attr_info.VertexAttribGetter(data, name);
			if(getter != nullptr)
			try
			{
				vbos[va].Bind(Buffer::Target::Array);
				GLuint npv = getter(make_shape, data);
				Buffer::Data(Buffer::Target::Array, data);
				VertexAttribArray attr(prog, name);
				attr.Setup<GLfloat>(npv);
				attr.Enable();
			}
			catch(Error& error)
			{ }
		}
		vbos[nva].Bind(Buffer::Target::ElementArray);
		Buffer::Data(Buffer::Target::ElementArray, shape_indices);
		shape_indices.clear();
	}
コード例 #4
0
ファイル: 031_sketch.cpp プロジェクト: AdamSimpson/oglplus
	Shape(const Program& prog, const ShapeBuilder& builder)
	 : make_shape(builder)
	 , shape_instr(make_shape.Instructions(shapes::DrawMode::Default()))
	 , edge_instr(make_shape.Instructions(shapes::DrawMode::Edges()))
	 , shape_indices(make_shape.Indices(shapes::DrawMode::Default()))
	 , edge_indices(make_shape.Indices(shapes::DrawMode::Edges()))
	 , vbos(3)
	{
		// bind the VAO for the shape
		vao.Bind();

		typename ShapeBuilder::VertexAttribs vert_attr_info;
		const GLuint nva = 3;
		const GLchar* vert_attr_name[nva] = {
			"Position",
			"Normal",
			"TexCoord"
		};
		for(GLuint va=0; va!=nva; ++va)
		{
			const GLchar* name = vert_attr_name[va];
			std::vector<GLfloat> data;
			auto getter = vert_attr_info.VertexAttribGetter(data, name);
			if(getter != nullptr)
			{
				// bind the VBO for the vertex attribute
				vbos[va].Bind(Buffer::Target::Array);
				GLuint n_per_vertex = getter(make_shape, data);
				// upload the data
				Buffer::Data(Buffer::Target::Array, data);
				// setup the vertex attribs array
				VertexArrayAttrib attr(prog, name);
				attr.Setup<GLfloat>(n_per_vertex);
				attr.Enable();
			}
		}
	}