Exemplo n.º 1
0
VBO::VBO(const VBO& vbo) :
	m_data_size(vbo.m_data_size),
	m_nbElts(vbo.m_nbElts),
	m_lock(false)
{
	unsigned int nbbytes =  sizeof(float) * m_data_size * m_nbElts;

	glGenBuffers(1, &(*m_id));

	vbo.bind();
	void* src = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);

	bind();
	glBufferData(GL_ARRAY_BUFFER, nbbytes, src, GL_STREAM_DRAW);

	vbo.bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Exemplo n.º 2
0
TEST_F(TransformFeedbackTest, test)
{
    std::ifstream       vsFile("data/transform_feedback.vert");
    std::ifstream       gsFile("data/transform_feedback.geom");
    Shader              vertex(GL_VERTEX_SHADER);
    Shader              geometry(GL_GEOMETRY_SHADER);
    ShaderProgram       shader;
    Query               query(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
    VAO                 vao;
    VBO                 vbo;
    TFBO                tfbo;
    const GLchar*       feedbackVaryings[] = { "outValue" };
    GLfloat             data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
    GLfloat             feedback[15];
    GLuint              primitives;

    ASSERT_TRUE(vertex.compile(vsFile));
    ASSERT_TRUE(geometry.compile(gsFile));
    shader.attach(vertex);
    shader.attach(geometry);

    shader.setTransformFeedbackVaryings(1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);
    ASSERT_TRUE(shader.link());
    shader.use();
    shader.printDebug();

    vao.bind();

    vbo.bind();
    vbo.setData(sizeof(data), data, GL_STATIC_DRAW);

    GLint inputAttrib = shader.getAttribLocation("inValue");

    vao.enableAttrib(inputAttrib);
    glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

    tfbo.setData(sizeof(data) * 3, nullptr, GL_STATIC_READ);
    tfbo.bindBufferBase(0);

    mogl::enable(GL_RASTERIZER_DISCARD);
    query.begin();
    TransformFeedback::begin(GL_TRIANGLES);
    glDrawArrays(GL_POINTS, 0, 5);
    TransformFeedback::end();
    query.end();
    mogl::disable(GL_RASTERIZER_DISCARD);
    mogl::Sync::flush();

    primitives = query.get<GLuint>(GL_QUERY_RESULT);
    tfbo.getSubData(0, sizeof(feedback), feedback);
    std::cout << primitives << " primitives written" << std::endl;
    for (unsigned int i = 0; i < 15; ++i)
        std::cout << feedback[i] << std::endl;
}