本文整理汇总了C++中QOpenGLShaderProgram::setAttributeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLShaderProgram::setAttributeBuffer方法的具体用法?C++ QOpenGLShaderProgram::setAttributeBuffer怎么用?C++ QOpenGLShaderProgram::setAttributeBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QOpenGLShaderProgram
的用法示例。
在下文中一共展示了QOpenGLShaderProgram::setAttributeBuffer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void Refraction::draw()
{
_arrayBuf.bind();
QOpenGLShaderProgram *program = GL::refraction();
program->bind();
int vertexLocation = program->attributeLocation("a_position");
program->enableAttributeArray(vertexLocation);
program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, sizeof(VertexData));
int fragmentLocation = program->attributeLocation("a_texcoord");
program->enableAttributeArray(fragmentLocation);
program->setAttributeBuffer(fragmentLocation, GL_FLOAT, sizeof(QVector3D), 2, sizeof(VertexData));
prepareMatrix();
program->setUniformValue("mvp_matrix", GL::projection() * model);
program->setUniformValue("refraction", 0);
_texture->bind(0);
program->setUniformValue("background", 1);
GameObjects::background()->bind(1);
program->setUniformValue("position", _position);
program->setUniformValue("radius", _radius);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, 0);
}
示例2: getShaderProgram
void
Scene_polylines_item::initializeBuffers(CGAL::Three::Viewer_interface *viewer = 0) const
{
QOpenGLShaderProgram *program;
//vao for the lines
{
program = getShaderProgram(PROGRAM_NO_SELECTION, viewer);
program->bind();
vaos[Edges]->bind();
buffers[Edges_Vertices].bind();
buffers[Edges_Vertices].allocate(positions_lines.data(),
static_cast<int>(positions_lines.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",GL_FLOAT,0,4);
buffers[Edges_Vertices].release();
vaos[Edges]->release();
program->release();
nb_lines = positions_lines.size();
positions_lines.clear();
positions_lines.swap(positions_lines);
}
are_buffers_filled = true;
}
示例3:
void
Scene_polylines_item_private::initializeBuffers(CGAL::Three::Viewer_interface *viewer = 0) const
{
float lineWidth[2];
viewer->glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidth);
line_Slider->setMaximum(lineWidth[1]);
QOpenGLShaderProgram *program;
//vao for the lines
{
program = item->getShaderProgram(Scene_polylines_item::PROGRAM_NO_SELECTION, viewer);
program->bind();
item->vaos[Edges]->bind();
item->buffers[Edges_Vertices].bind();
item->buffers[Edges_Vertices].allocate(positions_lines.data(),
static_cast<int>(positions_lines.size()*sizeof(float)));
program->enableAttributeArray("vertex");
program->setAttributeBuffer("vertex",GL_FLOAT,0,4);
item->buffers[Edges_Vertices].release();
item->vaos[Edges]->release();
program->release();
nb_lines = positions_lines.size();
positions_lines.clear();
positions_lines.swap(positions_lines);
}
item->are_buffers_filled = true;
}
示例4: Exception
/******************************************************************************
* Renders a 2d polyline in the viewport.
******************************************************************************/
void ViewportSceneRenderer::render2DPolyline(const Point2* points, int count, const ColorA& color, bool closed)
{
OVITO_STATIC_ASSERT(sizeof(points[0]) == 2*sizeof(GLfloat));
// Load OpenGL shader.
QOpenGLShaderProgram* shader = loadShaderProgram("line", ":/core/glsl/lines/line.vs", ":/core/glsl/lines/line.fs");
if(!shader->bind())
throw Exception(tr("Failed to bind OpenGL shader."));
bool wasDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
GLint vc[4];
glGetIntegerv(GL_VIEWPORT, vc);
QMatrix4x4 tm;
tm.ortho(vc[0], vc[0] + vc[2], vc[1] + vc[3], vc[1], -1, 1);
OVITO_CHECK_OPENGL(shader->setUniformValue("modelview_projection_matrix", tm));
QOpenGLBuffer vertexBuffer;
if(glformat().majorVersion() >= 3) {
if(!vertexBuffer.create())
throw Exception(tr("Failed to create OpenGL vertex buffer."));
if(!vertexBuffer.bind())
throw Exception(tr("Failed to bind OpenGL vertex buffer."));
vertexBuffer.allocate(points, 2 * sizeof(GLfloat) * count);
OVITO_CHECK_OPENGL(shader->enableAttributeArray("position"));
OVITO_CHECK_OPENGL(shader->setAttributeBuffer("position", GL_FLOAT, 0, 2));
vertexBuffer.release();
}
else {
OVITO_CHECK_OPENGL(glEnableClientState(GL_VERTEX_ARRAY));
OVITO_CHECK_OPENGL(glVertexPointer(2, GL_FLOAT, 0, points));
}
if(glformat().majorVersion() >= 3) {
OVITO_CHECK_OPENGL(shader->disableAttributeArray("color"));
OVITO_CHECK_OPENGL(shader->setAttributeValue("color", color.r(), color.g(), color.b(), color.a()));
}
else {
OVITO_CHECK_OPENGL(glColor4(color));
}
OVITO_CHECK_OPENGL(glDrawArrays(closed ? GL_LINE_LOOP : GL_LINE_STRIP, 0, count));
if(glformat().majorVersion() >= 3) {
shader->disableAttributeArray("position");
}
else {
OVITO_CHECK_OPENGL(glDisableClientState(GL_VERTEX_ARRAY));
}
shader->release();
if(wasDepthTestEnabled) glEnable(GL_DEPTH_TEST);
}
示例5: draw
void csSurface::draw(QOpenGLShaderProgram& program)
{
if( _initRequired ) {
initialize();
}
if( _meshInfo.isEmpty() ) {
return;
}
glDisable(GL_CULL_FACE);
program.setUniformValue("cs_Model", _model);
program.setUniformValue("cs_zMin", _meshInfo.zMin());
program.setUniformValue("cs_zInterval", _meshInfo.zInterval());
program.setUniformValue("cs_ColorMap", TMU_COLORMAP);
_surface->bind();
const int vertexLoc = program.attributeLocation("cs_Vertex");
program.enableAttributeArray(vertexLoc);
program.setAttributeBuffer(vertexLoc, GL_FLOAT, 0, 3);
_colorTexture->bind(TMU_COLORMAP, QOpenGLTexture::ResetTextureUnit);
_strip->bind();
const int numStrips = _meshInfo.rowCount() -1;
const int numVertPerStrip = 2*_meshInfo.columnCount();
for(int y = 0; y < numStrips; y++) {
const GLuint offset = sizeof(GLuint)*y*numVertPerStrip;
const GLvoid *indices = (GLvoid*)offset;
glDrawElements(GL_TRIANGLE_STRIP, numVertPerStrip, GL_UNSIGNED_INT, indices);
}
_strip->release();
_colorTexture->release();
program.disableAttributeArray(vertexLoc);
_surface->release();
}
示例6: drawMesh
void csSurface::drawMesh(QOpenGLShaderProgram& program)
{
if( _initRequired ) {
initialize();
}
if( _meshInfo.isEmpty() ) {
return;
}
program.setUniformValue("cs_DepthOffset", csCoordinateBox::DepthOffset);
program.setUniformValue("cs_Model", _model);
_surface->bind();
const int vertexLoc = program.attributeLocation("cs_Vertex");
program.enableAttributeArray(vertexLoc);
program.setAttributeBuffer(vertexLoc, GL_FLOAT, 0, 3);
const int colorLoc = program.attributeLocation("cs_Color");
program.setAttributeValue(colorLoc, QColor(Qt::black));
// Along x-Axis
for(int y = 0; y < _meshInfo.rowCount(); y++) {
glDrawArrays(GL_LINE_STRIP,
y*_meshInfo.columnCount(), _meshInfo.columnCount());
}
// Along y-Axis
_meshY->bind();
for(int x = 0; x < _meshInfo.columnCount(); x++) {
const GLuint offset = sizeof(GLuint)*x*_meshInfo.rowCount();
const GLvoid *indices = (GLvoid*)offset;
glDrawElements(GL_LINE_STRIP, _meshInfo.rowCount(), GL_UNSIGNED_INT, indices);
}
_meshY->release();
program.disableAttributeArray(vertexLoc);
_surface->release();
}
示例7: showDistance
void Viewer_impl::showDistance(QPoint pixel)
{
static bool isAset = false;
bool found;
CGAL::qglviewer::Vec point;
point = viewer->camera()->pointUnderPixel(pixel, found);
if(!isAset && found)
{
//set APoint
APoint = point;
isAset = true;
clearDistancedisplay();
}
else if (found)
{
//set BPoint
BPoint = point;
isAset = false;
// fills the buffers
std::vector<float> v;
v.resize(6);
v[0] = float(APoint.x); v[1] = float(APoint.y); v[2] = float(APoint.z);
v[3] = float(BPoint.x); v[4] = float(BPoint.y); v[5] = float(BPoint.z);
vao.bind();
buffer.bind();
buffer.allocate(v.data(),6*sizeof(float));
rendering_program_dist.enableAttributeArray("vertex");
rendering_program_dist.setAttributeBuffer("vertex",GL_FLOAT,0,3);
buffer.release();
vao.release();
distance_is_displayed = true;
double dist = std::sqrt((BPoint.x-APoint.x)*(BPoint.x-APoint.x) + (BPoint.y-APoint.y)*(BPoint.y-APoint.y) + (BPoint.z-APoint.z)*(BPoint.z-APoint.z));
QFont font;
font.setBold(true);
TextItem *ACoord = new TextItem(float(APoint.x),
float(APoint.y),
float(APoint.z),
QString("A(%1,%2,%3)").arg(APoint.x-viewer->offset().x).arg(APoint.y-viewer->offset().y).arg(APoint.z-viewer->offset().z), true, font, Qt::red, true);
distance_text.append(ACoord);
TextItem *BCoord = new TextItem(float(BPoint.x),
float(BPoint.y),
float(BPoint.z),
QString("B(%1,%2,%3)").arg(BPoint.x-viewer->offset().x).arg(BPoint.y-viewer->offset().y).arg(BPoint.z-viewer->offset().z), true, font, Qt::red, true);
distance_text.append(BCoord);
CGAL::qglviewer::Vec centerPoint = 0.5*(BPoint+APoint);
TextItem *centerCoord = new TextItem(float(centerPoint.x),
float(centerPoint.y),
float(centerPoint.z),
QString(" distance: %1").arg(dist), true, font, Qt::red, true);
distance_text.append(centerCoord);
Q_FOREACH(TextItem* ti, distance_text)
textRenderer->addText(ti);
Q_EMIT(viewer->sendMessage(QString("First point : A(%1,%2,%3), second point : B(%4,%5,%6), distance between them : %7")
.arg(APoint.x-viewer->offset().x)
.arg(APoint.y-viewer->offset().y)
.arg(APoint.z-viewer->offset().z)
.arg(BPoint.x-viewer->offset().x)
.arg(BPoint.y-viewer->offset().y)
.arg(BPoint.z-viewer->offset().z)
.arg(dist)));
}
}