void Curvature::loadVA() { glGenVertexArrays (1, Parameters::getInstance()->g_vertex_arrays + VERTEX_ARRAY_CURVATURE); glBindVertexArray(Parameters::getInstance()->g_vertex_arrays[VERTEX_ARRAY_CURVATURE]); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, Parameters::getInstance()->g_buffers[BUFFER_VERTICES]); glVertexAttribPointer(0, 4, GL_FLOAT, 0, 0, 0); glEnableVertexAttribArray(1); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Parameters::getInstance()->g_buffers[BUFFER_INDICES]); glVertexAttribIPointer(1, 1, GL_UNSIGNED_INT, 0, 0); glBindVertexArray(0); glGenVertexArrays (1, Parameters::getInstance()->g_vertex_arrays + VERTEX_ARRAY_CURVATURE_TR); glBindVertexArray(Parameters::getInstance()->g_vertex_arrays[VERTEX_ARRAY_CURVATURE_TR]); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, Parameters::getInstance()->g_buffers[BUFFER_VERTICES_TR]); glVertexAttribPointer(0, 4, GL_FLOAT, 0, 0, 0); glEnableVertexAttribArray(1); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Parameters::getInstance()->g_buffers[BUFFER_INDICES_TR]); glVertexAttribIPointer(1, 1, GL_UNSIGNED_INT, 0, 0); glBindVertexArray(0); }
void VAOInstanceUtil<InstanceDataDualTex>::SetVertexAttrib() { SetVertexAttrib_impl(); glEnableVertexAttribArray(10); glVertexAttribIPointer(10, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float))); glVertexAttribDivisorARB(10, 1); glEnableVertexAttribArray(11); glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataDualTex), (GLvoid*)(9 * sizeof(float) + 2 * sizeof(unsigned))); glVertexAttribDivisorARB(11, 1); }
void mesh_p::SubMesh::uploadVertexData() { GLuint vbo; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); { QVector<GLint> vertexIndicies; vertexIndicies.reserve(mFaces.count()*3*2); //add the vertex position indicies for (Face f : mFaces) { for (int i : f.vertexIndex) vertexIndicies.append(static_cast<GLint>(i)); } long normalOffset = vertexIndicies.count() * sizeof(GLint); //add the vertex normal indicies for (Face f : mFaces) { for (int i : f.normalIndex) vertexIndicies.append(static_cast<GLint>(i)); } long textureOffset = vertexIndicies.count() * sizeof(GLint); //add the texture coordinate indicies for (Face f : mFaces) { for (int i : f.textureIndex) vertexIndicies.append(static_cast<GLint>(i)); } mIndexCount = vertexIndicies.count(); glBufferData(GL_ARRAY_BUFFER, vertexIndicies.count()*sizeof(GLuint), &vertexIndicies[0], GL_STATIC_DRAW); glVertexAttribIPointer(0, 1, GL_INT, 0, NULL); glEnableVertexAttribArray(0); glVertexAttribIPointer(1, 1, GL_INT, 0, (void*)normalOffset); glEnableVertexAttribArray(1); glVertexAttribIPointer(2, 1, GL_INT, 0, (void*)textureOffset); glEnableVertexAttribArray(2); } }
void Mesh::setup() { glGenVertexArrays(1, &this->mVAO); glGenBuffers(1, &this->mVBO); glGenBuffers(1, &this->mEBO); glBindVertexArray(this->mVAO); glBindBuffer(GL_ARRAY_BUFFER, this->mVBO); glBufferData(GL_ARRAY_BUFFER, this->mVertices.size() * sizeof(VertexData), &this->mVertices[0], GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->mEBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->mIndices.size() * sizeof(GLuint), &this->mIndices[0], GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*)offsetof(VertexData, position)); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*)offsetof(VertexData, normal)); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*)offsetof(VertexData, textureCoordinate)); glEnableVertexAttribArray(3); glVertexAttribIPointer(3, 4, GL_INT, sizeof(VertexData), (GLvoid*)offsetof(VertexData, boneIndices)); // notice the I in IPoint for integer glEnableVertexAttribArray(4); glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(VertexData), (GLvoid*)offsetof(VertexData, weights)); glBindVertexArray(0); }
void BoundingAxis::draw() { glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, _axisBufferId); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(float) * (3 * _nVertices))); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(float) * (6 * _nVertices))); glEnableVertexAttribArray(3); glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(sizeof(float) * (9 * _nVertices))); glEnableVertexAttribArray(4); glBindBuffer(GL_ARRAY_BUFFER, _typeBufferId); glVertexAttribIPointer(4, 1, GL_UNSIGNED_BYTE, 0, 0); glDrawArrays(GL_LINES, 0, _nVertices); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDisableVertexAttribArray(2); glDisableVertexAttribArray(3); }
ColoredTextureRectShader() { #ifdef XX initQuadBuffer(); #endif loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert", GL_FRAGMENT_SHADER, "colortexturedquad.frag"); assignUniforms("center", "size", "texcenter", "texsize"); assignSamplerNames(0, "tex", ST_BILINEAR_FILTERED); glGenVertexArrays(1, &m_vao); glBindVertexArray(m_vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(3); glEnableVertexAttribArray(2); glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getQuadBuffer()); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); const unsigned quad_color[] = { 0, 0, 0, 255, 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255 }; glGenBuffers(1, &m_color_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_color_vbo); glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW); glVertexAttribIPointer(2, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); glBindVertexArray(0); } // ColoredTextureRectShader
void VAOInstanceUtil<InstanceDataThreeTex>::SetVertexAttrib() { SetVertexAttrib_impl(); glEnableVertexAttribArray(10); glVertexAttribPointer(10, 4, GL_FLOAT, GL_FALSE, sizeof(InstanceDataThreeTex), (GLvoid*)(9 * sizeof(float))); glVertexAttribDivisorARB(10, 1); glEnableVertexAttribArray(11); glVertexAttribIPointer(11, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float))); glVertexAttribDivisorARB(11, 1); glEnableVertexAttribArray(12); glVertexAttribIPointer(12, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 2 * sizeof(unsigned))); glVertexAttribDivisorARB(12, 1); glEnableVertexAttribArray(13); glVertexAttribIPointer(13, 2, GL_UNSIGNED_INT, sizeof(InstanceDataThreeTex), (GLvoid*)(13 * sizeof(float) + 4 * sizeof(unsigned))); glVertexAttribDivisorARB(13, 1); }
void VaoImplCore::reassignImpl( Context *newContext ) { if( newContext == mCtx ) return; mCtx = newContext; // generate glGenVertexArrays( 1, &mId ); // assign glBindVertexArray( mId ); // instantiate the VAO using the layout auto oldBuffer = mCtx->getBufferBinding( GL_ARRAY_BUFFER ); for( auto attribIt = mLayout.mVertexAttribs.begin(); attribIt != mLayout.mVertexAttribs.end(); ++attribIt ) { if( attribIt->second.mEnabled ) { glEnableVertexAttribArray( attribIt->first ); glBindBuffer( GL_ARRAY_BUFFER, attribIt->second.mArrayBufferBinding ); if( attribIt->second.mPointerType == Vao::VertexAttrib::FLOAT ) glVertexAttribPointer( attribIt->first, attribIt->second.mSize, attribIt->second.mType, attribIt->second.mNormalized, attribIt->second.mStride, attribIt->second.mPointer ); else glVertexAttribIPointer( attribIt->first, attribIt->second.mSize, attribIt->second.mType, attribIt->second.mStride, attribIt->second.mPointer ); } } glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mLayout.mElementArrayBufferBinding ); // we need to bind this directly to prevent the gl::Context's caching from subverting our restoration of the old GL_ARRAY_BUFFER glBindBuffer( GL_ARRAY_BUFFER, oldBuffer ); }
void VertexFormatBinder::Activate(NvSharedVBOGL* pInstanceDataStream) { // Activate the instancing data by binding the instance data stream and setting // up all of the offsets into each of the attributes intptr_t pBufferStart = pInstanceDataStream->GetDynamicOffset(); glBindBuffer(GL_ARRAY_BUFFER, pInstanceDataStream->GetBuffer()); AttribSet::iterator attribIt = m_instanceAttributes.begin(); AttribSet::const_iterator attribEnd = m_instanceAttributes.end(); for (; attribIt != attribEnd; ++attribIt) { const InstanceAttribDesc& desc = attribIt->second; glEnableVertexAttribArray(desc.m_attribIndex); // We have to use an appropriate version of the glVertexAttribPointer family of methods // depending on the type of data and how it will be used in the shader switch (desc.m_usage) { case GL_FLOAT: glVertexAttribPointer(desc.m_attribIndex, desc.m_size, desc.m_type, desc.m_normalized, m_stride, (GLvoid*)(pBufferStart + desc.m_offset)); break; case GL_INT: glVertexAttribIPointer(desc.m_attribIndex, desc.m_size, desc.m_type, m_stride, (GLvoid*)(pBufferStart + desc.m_offset)); break; case GL_DOUBLE: glVertexAttribLPointer(desc.m_attribIndex, desc.m_size, desc.m_type, m_stride, (GLvoid*)(pBufferStart + desc.m_offset)); break; } glVertexAttribDivisor(desc.m_attribIndex, desc.m_divisor); } }
void VaoImplSoftware::bindImpl( Context *context ) { if( ! context ) return; auto oldBuffer = context->getBufferBinding( GL_ARRAY_BUFFER ); for( auto attribIt = mLayout.mVertexAttribs.begin(); attribIt != mLayout.mVertexAttribs.end(); ++attribIt ) { if( attribIt->second.mEnabled ) { glEnableVertexAttribArray( attribIt->first ); glBindBuffer( GL_ARRAY_BUFFER, attribIt->second.mArrayBufferBinding ); if( attribIt->second.mPointerType == VertexAttrib::FLOAT ) glVertexAttribPointer( attribIt->first, attribIt->second.mSize, attribIt->second.mType, attribIt->second.mNormalized, attribIt->second.mStride, attribIt->second.mPointer ); else #if ! defined( CINDER_GL_ES ) glVertexAttribIPointer( attribIt->first, attribIt->second.mSize, attribIt->second.mType, attribIt->second.mStride, attribIt->second.mPointer ); #else ; // should we throw here? #endif } } context->bindBuffer( GL_ELEMENT_ARRAY_BUFFER, mLayout.mElementArrayBufferBinding ); context->bindBuffer( GL_ARRAY_BUFFER, oldBuffer ); }
void VertexBufferObject::bind(GLint attributeId) { glEnableVertexAttribArray(attributeId); glBindBuffer(GL_ARRAY_BUFFER, vbo); if(type == GL_INT || type == GL_UNSIGNED_INT) { glVertexAttribIPointer( attributeId, tupleSize, type, stride, offset ); } else { glVertexAttribPointer( attributeId, tupleSize, type, normalized, stride, offset ); } }
void SkinVertex::enableAttributes() { typedef SkinVertex ThisType; glEnableVertexAttribArray(ThisType::attr_pos); glVertexAttribPointer(ThisType::attr_pos, 3, GL_FLOAT, false, sizeof(ThisType), (void *)offsetof(ThisType, pos)); glEnableVertexAttribArray(ThisType::attr_norm); glVertexAttribPointer(ThisType::attr_norm, 3, GL_FLOAT, false, sizeof(ThisType), (void *)offsetof(ThisType, norm)); glEnableVertexAttribArray(ThisType::attr_uv); glVertexAttribPointer(ThisType::attr_uv, 2, GL_FLOAT, false, sizeof(ThisType), (void *)offsetof(ThisType, uv)); glEnableVertexAttribArray(ThisType::attr_color); glVertexAttribPointer(ThisType::attr_color, 4, GL_FLOAT, false, sizeof(ThisType), (void *)offsetof(ThisType, color)); glEnableVertexAttribArray(ThisType::attr_boneindex); glVertexAttribIPointer(ThisType::attr_boneindex, 4, GL_INT, sizeof(ThisType), (void *)offsetof(ThisType, boneIndex)); glEnableVertexAttribArray(ThisType::attr_boneweight); glVertexAttribPointer(ThisType::attr_boneweight, 4, GL_FLOAT, false, sizeof(ThisType), (void *)offsetof(ThisType, boneWeight)); }
inline void vertex_attrib_i_pointer(uint32 location, uint32 element_count, uint32 type, uint32 stride, uint32 offset) { ARC_GL_CLEAR_ERRORS(); glVertexAttribIPointer(location,element_count, type, stride, reinterpret_cast<void*>(offset)); ARC_GL_CHECK_FOR_ERRORS(); }
void chunk_draw(Chunk *chunk, World *world) { if(chunk->empty) {return;} if(chunk->changed) { Chunk *adjacent[27]; world_chunk_adjacent(world, chunk, adjacent); chunk_regen_buffer(adjacent); } glUseProgram(program_render); glUniform1i(glGetUniformLocation(program_render, "textures"), 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture_atlas); matrix_update_mvp(glGetUniformLocation(program_render, "mvp")); glBindBuffer(GL_ARRAY_BUFFER, chunk->buffer); glBindVertexArray(vao_render); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, (sizeof(GLfloat)*5)+sizeof(GLint), (const GLvoid *) 0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, (sizeof(GLfloat)*5)+sizeof(GLint), (const GLvoid *) (sizeof(GLfloat)*3)); glVertexAttribIPointer(2, 1, GL_INT, (sizeof(GLfloat)*5)+sizeof(GLint), (const GLvoid *) (sizeof(GLfloat)*5)); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDrawArrays(GL_TRIANGLES, 0, chunk->num_verts); }
void create_indexed_animated_vertex_array(GLuint *vertexArray, GLuint *vertexBuffer, GLuint *indexBuffer, U32 vertexCount, U32 indexCount, const AnimatedVertex *vertices, const U32 *indices, GLenum drawMode) { glGenVertexArrays(1, vertexArray); glBindVertexArray(*vertexArray); glGenBuffers(1, vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, *vertexBuffer); glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(AnimatedVertex), vertices, drawMode); glGenBuffers(1, indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, *indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(U32), indices, drawMode); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); glEnableVertexAttribArray(4); glEnableVertexAttribArray(5); //glEnableVertexAttribArray(6); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(AnimatedVertex), (GLvoid*)offsetof(AnimatedVertex, position)); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(AnimatedVertex), (GLvoid*)offsetof(AnimatedVertex, normal)); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(AnimatedVertex), (GLvoid*)offsetof(AnimatedVertex, tangent)); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(AnimatedVertex), (GLvoid*)offsetof(AnimatedVertex, texcoord)); glVertexAttribIPointer(4, 4, GL_INT, sizeof(AnimatedVertex), (GLvoid*)offsetof(AnimatedVertex, joint_index)); glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(AnimatedVertex), (GLvoid*)offsetof(AnimatedVertex, weight)); glBindVertexArray(0); }
void VaoImplCore::vertexAttribIPointerImpl( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) { // test to see if the layout doesn't already reflect this, so we can avoid a redundant call to glVertexAttribPointer if( ! mLayout.isVertexAttribEqual( index, size, type, false, stride, VertexAttrib::INTEGER, pointer, mLayout.mCachedArrayBufferBinding ) ) { mLayout.vertexAttribIPointer( index, size, type, stride, pointer ); glVertexAttribIPointer( index, size, type, stride, pointer ); } }
//! glVertexAttribIPointer wrapper. May throw. inline void vertexAttribIPointer(GLuint const index, GLint const size, GLenum const type, GLsizei const stride, GLvoid const* pointer) { glVertexAttribIPointer(index, size, type, stride, pointer); checkError("glVertexAttribIPointer"); }
void VaoImplSoftware::vertexAttribIPointerImpl( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) { mLayout.vertexAttribIPointer( index, size, type, stride, pointer ); #if ( ! defined( CINDER_GL_ES ) ) || ( defined( CINDER_GL_ES ) && ( CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_3 ) ) glVertexAttribIPointer( index, size, type, stride, pointer ); #endif }
void VertexAttribIPointer( const GLuint Index, const GLint Size, const EType::Value Type, const GLsizei Stride, const GLvoid* const Pointer) { glVertexAttribIPointer(Index, Size, Type, Stride, Pointer); }
//Funktion um das Partikelsystem zu initialisieren void initParticleSystem() { glGenVertexArrays(1, &VertexArrayIds[0]); //neues VAO generieren glBindVertexArray(VertexArrayIds[0]); //VAO binden Particle particles[maxParticleCount]; //Particle Array erstellen for(int i=0; i<particleCount; ++i) { //particle Array befüllen Particle particle; particle.x = 0.0; particle.y = 0.0; particle.z = 0.0; particle.w = 1.0; particle.age = rand() % particleLifetime; particles[i] = particle; //std::cout<<particle.age<<std::endl; } /*for(int i=1; i<=4; ++i) { std::cout<<i<<" "<<particles[i].age<<std::endl; }*/ //Databuffer generieren glGenBuffers(2, &VertexArrayIds[1]); //2 Buffer fürs VAO generieren glBindBuffer(GL_ARRAY_BUFFER,VertexArrayIds[1]); //1. Buffer binden glBufferData(GL_ARRAY_BUFFER,sizeof(particles), particles, GL_STATIC_DRAW); //Buffer Data deklarieren GLint input = glGetAttribLocation(ShaderIds[6], "posIn"); //Attribut Position für posIn angeben glEnableVertexAttribArray(input); //vertex Array aktivieren glVertexAttribPointer(input, 4, GL_FLOAT, GL_FALSE, 4*(sizeof(float)) + sizeof(int),0); //Attribut Pointer für posIn angeben input = glGetAttribLocation(ShaderIds[6], "ageIn"); //Attribut Position für ageIn angeben glEnableVertexAttribArray(input); //vertex Array aktivieren glVertexAttribIPointer(input, 1, GL_INT, 4*(sizeof(float)) + sizeof(int),(GLvoid*)(sizeof(float)*4)); //Attribut Pointer(int) für ageIn angeben //Feedbackbuffer generieren glBindBuffer(GL_ARRAY_BUFFER, VertexArrayIds[2]); //2. Buffer binden glBufferData(GL_ARRAY_BUFFER, sizeof(particles), particles, GL_STATIC_READ); //Buffer Data deklarieren GLint input2 = glGetAttribLocation(ShaderIds[6], "posIn");//Attribut Position für posIn angeben glEnableVertexAttribArray(input2); //vertex Array aktivieren glVertexAttribPointer(input2, 4, GL_FLOAT, GL_FALSE, 4*(sizeof(float)) + sizeof(int),0); //Attribut Pointer für posIn angeben input2 = glGetAttribLocation(ShaderIds[6], "ageIn"); //Attribut Position für ageIn angeben glEnableVertexAttribArray(input2); //vertex Array aktivieren glVertexAttribIPointer(input2, 1, GL_INT, 4*(sizeof(float)) + sizeof(int),(GLvoid*)(sizeof(float)*4)); //Attribut Pointer(int) für ageIn angeben glBindVertexArray(0); //VAO unbinden }
void Particles::_init_cl_context(void) { cl_int ret; std::vector<cl::Platform> platforms; ret = cl::Platform::get(&platforms); // printf("Number of platforms: %ld\n", platforms.size()); std::vector<cl::Device> devices; ret = platforms.front().getDevices(CL_DEVICE_TYPE_GPU, &devices); // printf("Number of devices GPU on first platform: %ld\n", devices.size()); std::string device_name; std::string device_extensions; ret = devices.front().getInfo(CL_DEVICE_NAME, &device_name); // printf("Device name: %s\n", device_name.c_str()); ret = devices.front().getInfo(CL_DEVICE_EXTENSIONS, &device_extensions); if (device_extensions.find(CL_GL_SHARING_EXT) == std::string::npos) { dprintf(2, "This device doesn't support GL/CL sharing...\n"); throw std::exception(); } // Get current CGL Context and CGL Share group CGLContextObj kCGLContext = CGLGetCurrentContext(); CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext); // Create CL context properties, add handle & share-group enum cl_context_properties properties[] = { CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, 0 }; this->_cl_context = cl::Context::Context(devices, properties, NULL, NULL, &ret); if (ret != CL_SUCCESS) { dprintf(2, "Error while trying to create context...\n"); throw std::exception(); } this->bind_array(); this->bind_buffer(); glEnableVertexAttribArray(0); glVertexAttribIPointer(0, 2, GL_UNSIGNED_INT, 0, NULL); cl::BufferGL::BufferGL(this->_cl_context, CL_MEM_READ_WRITE, this->_positions_vbo, &ret); if (ret != CL_SUCCESS) { dprintf(2, "Error while trying to create buffer from openGL...\n"); throw std::exception(); } }
inline void VL_glVertexAttribIPointer(GLuint name, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) { if(glVertexAttribIPointer) glVertexAttribIPointer(name, size, type, stride, pointer); else if (glVertexAttribIPointerEXT) glVertexAttribIPointerEXT(name, size, type, stride, pointer); else VL_UNSUPPORTED_FUNC(); }
void GLVertexSource::setVertexAttribute(int attribute_slot, int components, GLenum component_type, GLSLVecType glsl_type, int attribute_stride, std::int64_t attribute_offset) { glBindVertexArray(_vao_id); glEnableVertexAttribArray(attribute_slot); if (glsl_type == GLSLVecType::ivec || glsl_type == GLSLVecType::uvec) glVertexAttribIPointer(attribute_slot, components, component_type, attribute_stride, (const void*)attribute_offset); else glVertexAttribPointer(attribute_slot, components, component_type, GL_FALSE, attribute_stride, (const void*)attribute_offset); glBindVertexArray(0); }
void VertexArrayObject::setVertexAttributeIPointer( GLuint _id, GLint _size, GLenum _type, GLsizei _stride, unsigned int _dataOffset ) { if(m_bound !=true) { std::cerr<<"Warning trying to set attribute on Unbound VOA\n"; } glVertexAttribIPointer(_id,_size,_type,_stride,static_cast<Real *>(NULL) +_dataOffset) ;//((Real *)NULL + (_dataOffset))); glEnableVertexAttribArray(_id); }
void GlassRenderer::draw(RModel* rmodel){ if(rmodel->positionDataBufferObject == RModel::NULL_BUFFER) return;// Create and set-up the vertex array object glm::mat3 normalMatrix = glm::mat3(rmodel->getMV()); //normalMatrix = glm::inverse(glm::transpose(normalMatrix)); glUseProgram(theProgram); ShaderUtils::setUniform(theProgram, "MVP",rmodel->getMVP()); ShaderUtils::setUniform(theProgram, "ViewportMatrix",rmodel->getViewPortMatrix()); ShaderUtils::setUniform(theProgram, "ModelView",rmodel->getMV()); ShaderUtils::setUniform(theProgram, "NormalMatrix",normalMatrix); ShaderUtils::setUniform(theProgram, "Material.Ka",config->phong1DConfig.material.Ka); ShaderUtils::setUniform(theProgram, "Material.Kd",config->phong1DConfig.material.Kd); ShaderUtils::setUniform(theProgram, "Material.Ks",config->phong1DConfig.material.Ks); ShaderUtils::setUniform(theProgram, "Material.Shininess",config->phong1DConfig.material.Shininess); ShaderUtils::setUniform(theProgram, "Light.La",config->phong1DConfig.light.La); ShaderUtils::setUniform(theProgram, "Light.Ld",config->phong1DConfig.light.Ld); ShaderUtils::setUniform(theProgram, "Light.Ls",config->phong1DConfig.light.Ls); ShaderUtils::setUniform(theProgram, "Light.Position",config->phong1DConfig.light.Position); ShaderUtils::setUniform(theProgram, "ElementDrawOption",config->elementDrawConfig.elementDrawnOption); ShaderUtils::setUniform(theProgram, "selectedModelColor",config->selectedBaseColor); ShaderUtils::setUniform(theProgram, "baseModelColor",config->modelBaseColor); //In the render function, bind to the vertex array object and call glDrawArrays to // Enable the vertex attribute arrays glEnableVertexAttribArray(POSITION_ATTRIBUTE); // Vertex position glEnableVertexAttribArray(NORMAL_ATTRIBUTE); glEnableVertexAttribArray(FLAG_ATTRIBUTE); // Map index 0 to the position buffer glBindBuffer(GL_ARRAY_BUFFER, rmodel->positionDataBufferObject); glVertexAttribPointer( POSITION_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL ); glBindBuffer(GL_ARRAY_BUFFER, rmodel->vertexNormalDataBufferObject); glVertexAttribPointer( NORMAL_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, (GLubyte *)NULL ); glBindBuffer(GL_ARRAY_BUFFER, rmodel->vertexFlagsDataBufferObject); glVertexAttribIPointer( FLAG_ATTRIBUTE, 1, GL_UNSIGNED_INT, 0, (GLubyte *)NULL ); // Map index 1 to the color buffer /*if(this->config.transparencyEnabled){ glEnable( GL_BLEND ); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }*/ glDrawArrays(GL_TRIANGLES, 0, rmodel->vertexFlagsAttribute.size() ); /*if(this->config.transparencyEnabled){ glDisable( GL_BLEND ); }*/ glDisableVertexAttribArray(POSITION_ATTRIBUTE); // Vertex position glDisableVertexAttribArray(NORMAL_ATTRIBUTE); // Vertex position glDisableVertexAttribArray(FLAG_ATTRIBUTE); // Vertex position glBindBuffer(GL_ARRAY_BUFFER,0); glUseProgram(0); }
void CRenderingContext::SetCustomIntBuffer(const char* pszName, size_t iSize, size_t iOffset, size_t iStride) { int iAttribute = glGetAttribLocation(m_iProgram, pszName); TAssert(iAttribute != ~0); if (iAttribute == ~0) return; glEnableVertexAttribArray(iAttribute); glVertexAttribIPointer(iAttribute, iSize, GL_INT, iStride, BUFFER_OFFSET(iOffset)); }
void rglVertexAttribIPointer( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer) { #if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3) glVertexAttribIPointer(index, size, type, stride, pointer); #endif }
void VaoImplEs::vertexAttribIPointerImpl( GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ) { // currently a no-op although this is implemented in ES 3 #if 0 // test to see if the layout doesn't already reflect this, so we can avoid a redundant call to glVertexAttribPointer if( ! mLayout.isVertexAttribEqual( index, size, type, normalized, stride, VertexAttrib::INTEGER, pointer, mLayout.mCachedArrayBufferBinding ) ) { mLayout.vertexAttribPointer( index, size, type, normalized, stride, pointer ); glVertexAttribIPointer( index, size, type, normalized, stride, pointer ); } #endif }
void MeshDrawCommand::setAttribState() { glUseProgram(shader_id); // tell opengl which vbos to use glBindBuffer(GL_ARRAY_BUFFER,vbo[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,vbo[1]); //offset fot position quintptr = offset = offsetof(VertexData,position); // Tell OpenGL programmable pipeline how to locate vertex position data int vertexLocation = glGetAttribLocation (shader_id,"a_position"); glEnableVertexAttribArray (vertexLocation); glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset); // Offset for texture coordinate offset = offsetof(VertexData,texCoord); // Tell OpenGL programmable pipeline how to locate vertex texture coordinate data int texcoordLocation = glGetAttribLocation (shader_id,"a_texcoord"); if(texcoordLocation>=0) { glEnableVertexAttribArray(texcoordLocation); //pass the texcoord to shader glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset); } offset =offsetof(VertexData,normalLine); int normalLineLocation = glGetAttribLocation (shader_id,"a_normal_line"); if(normalLineLocation>=0) { glEnableVertexAttribArray(normalLineLocation); glVertexAttribPointer(normalLineLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset); } offset = offsetof(VertexData,boneId); int BoneId = glGetAttribLocation (shader_id,"a_bone_ID"); // bone ID if(BoneId>=0) { glEnableVertexAttribArray(BoneId); glVertexAttribPointer(BoneId,4,GL_INT,GL_FALSE,sizeof(VertexData),(const void *)offset); } offset = offsetof(VertexData,boneWeight); int BoneWeight = glGetAttribLocation (shader_id,"a_bone_weight"); //bone weight if(BoneWeight>=0) { glEnableVertexAttribArray(BoneWeight); glVertexAttribIPointer(BoneWeight,4,GL_INT,sizeof(VertexData),(const void *)offset); } offset = offsetof(VertexData,tangent); int tangentLocation = glGetAttribLocation (shader_id,"a_tangent"); if(tangentLocation >= 0) { glEnableVertexAttribArray (tangentLocation); glVertexAttribPointer (tangentLocation,3,GL_FLOAT,GL_FALSE,sizeof(VertexData),(const void *) offset); } }
static void SetPointer(u32 attrib, u32 stride, const AttributeFormat &format) { if (!format.enable) return; glEnableVertexAttribArray(attrib); if (format.integer) glVertexAttribIPointer(attrib, format.components, VarToGL(format.type), stride, (u8*)nullptr + format.offset); else glVertexAttribPointer(attrib, format.components, VarToGL(format.type), true, stride, (u8*)nullptr + format.offset); }