小编Ped*_*pam的帖子

VBO可以绑定多个VAO吗?

我试图通过将其纹理坐标视为顶点位置数组来渲染模型的UV贴图.我为完美呈现的模型设置了VAO,然后尝试添加第二个VAO并将纹理坐标缓冲区绑定到它.不幸的是它没有渲染任何东西.

我为UV地图编写了第二组顶点和片段着色器,编译得很好.缓冲区的绑定方式与模型VAO和顶点属性集的绑定方式相同.我能看到的唯一区别是我没有重新指定缓冲区数据.

这是我设置VAO模型的代码:

// Create model VAO

glGenVertexArrays( 1, &modelVAO );
glBindVertexArray( modelVAO );

// Create position buffer

glGenBuffers( 1, &positionBuffer );
glBindBuffer( GL_ARRAY_BUFFER, positionBuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat ) * vertexCount * 4, positions, GL_STATIC_DRAW );
glVertexAttribPointer( 0, 4, GL_FLOAT, GL_FALSE, 0, 0 );
glEnableVertexAttribArray( 0 );

// Create normal buffer

glGenBuffers( 1, &normalBuffer );
glBindBuffer( GL_ARRAY_BUFFER, normalBuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof( GLfloat ) * vertexCount * 3, normals, GL_STATIC_DRAW );
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, 0 …
Run Code Online (Sandbox Code Playgroud)

c c++ opengl glsl

6
推荐指数
1
解决办法
1728
查看次数

我怎样才能防止复制?

我有一个名为sfractstore 的类,它存储指向二叉树根节点的指针.显然,当复制构造时sfract我需要克隆另一个sfract对象的二叉树.但是,复制构造函数永远不会被调用,我认为是因为复制省略.这导致两个sfract对象在解构时引用并尝试解除分配相同的根节点.我怎样才能防止这种情况发生?

//main.cpp
sfract_type a( /*...*/ );
sfract_type b( /*...*/ );
sfract_type c( a ); // copy construct

//sfract.h
template< class FType, class Alloc >
sfract( sfract< FType, Alloc > const & other )
{
    // Clone other's root node and assign to this object
    root = other.root->clone();
}
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
565
查看次数

无法将std :: list迭代器与list :: back()进行比较?

我有一个自定义迭代器模板类,它包装了一个std::list迭代器.在我的hasNext()方法中,我想检查迭代器是否引用列表中的最后一项.但是这段代码:

template< class Type >
...
virtual bool hasNext( void )
{
    return itTypes != pList->back();
}
...
typename std::list< Type > * pList;
typename std::list< Type >::iterator itTypes;
Run Code Online (Sandbox Code Playgroud)

产生错误:

error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::_List_iterator<_Mylist>'

如果我比较itTypeslist::begin()list::end()我没有得到任何问题.我在STL迭代器中看到的文档说std :: list使用的双向迭代器支持相等和不等式比较运算符.有什么理由我无法与之比较list::back()吗?

c++ templates stl

2
推荐指数
1
解决办法
664
查看次数

标签 统计

c++ ×3

c ×1

glsl ×1

opengl ×1

stl ×1

templates ×1