void Mesh::renderTriangles() { glVertexPointer(3, GL_FLOAT, 0, this->m_pVerts); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT, sizeof(t_TangentSpace), this->m_pTangentSpace->normal); glEnableClientState(GL_NORMAL_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, this->m_pTexVerts); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexAttribPointerARB(BINORMAL_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(t_TangentSpace), this->m_pTangentSpace->binormal); glEnableVertexAttribArrayARB(BINORMAL_ARRAY); glVertexAttribPointerARB(TANGENT_ARRAY, 3, GL_FLOAT, GL_FALSE, sizeof(t_TangentSpace), this->m_pTangentSpace->tangent); glEnableVertexAttribArrayARB(TANGENT_ARRAY); glDrawElements(GL_TRIANGLES, this->m_NumFaces * 3, GL_UNSIGNED_INT, this->m_pVertIndex); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableVertexAttribArrayARB(BINORMAL_ARRAY); glDisableVertexAttribArrayARB(TANGENT_ARRAY); }
void Renderer::flushText() { if (!currentFont) return; if (!bindShader(textShader)) return; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, currentFont->tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo); glEnableVertexAttribArrayARB(uniform_coord); glVertexAttribPointerARB(uniform_coord, 4, GL_FLOAT, GL_FALSE, sizeof(TextVertex), 0); glEnableVertexAttribArrayARB(uniform_atr); glVertexAttribPointerARB(uniform_atr, 4, GL_FLOAT, GL_FALSE, sizeof(TextVertex), (const void *)(offsetof(TextVertex, c))); float* ptr = (float*)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); if (ptr) { memcpy(ptr, textVertexBuffer, sizeof(TextVertex)* currentTextVertexBufferPos); glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); glDrawArrays(GL_TRIANGLES, 0, currentTextVertexBufferPos); } currentTextVertexBufferPos = 0; }
// Used only for VSM shader with geometry instancing support. void GPU_shader_bind_instancing_attrib(GPUShader *shader, void *matrixoffset, void *positionoffset, unsigned int stride) { int posloc = GPU_shader_get_attribute(shader, GPU_builtin_name(GPU_INSTANCING_POSITION_ATTRIB)); int matloc = GPU_shader_get_attribute(shader, GPU_builtin_name(GPU_INSTANCING_MATRIX_ATTRIB)); // Matrix if (matloc != -1) { glEnableVertexAttribArrayARB(matloc); glEnableVertexAttribArrayARB(matloc + 1); glEnableVertexAttribArrayARB(matloc + 2); glVertexAttribPointerARB(matloc, 3, GL_FLOAT, GL_FALSE, stride, matrixoffset); glVertexAttribPointerARB(matloc + 1, 3, GL_FLOAT, GL_FALSE, stride, ((char *)matrixoffset) + 3 * sizeof(float)); glVertexAttribPointerARB(matloc + 2, 3, GL_FLOAT, GL_FALSE, stride, ((char *)matrixoffset) + 6 * sizeof(float)); glVertexAttribDivisorARB(matloc, 1); glVertexAttribDivisorARB(matloc + 1, 1); glVertexAttribDivisorARB(matloc + 2, 1); } // Position if (posloc != -1) { glEnableVertexAttribArrayARB(posloc); glVertexAttribPointerARB(posloc, 3, GL_FLOAT, GL_FALSE, stride, positionoffset); glVertexAttribDivisorARB(posloc, 1); } }
void RenderablePatchSolid::render(const RenderInfo& info) const { #ifdef PATCHES_USE_VBO glBindBuffer(GL_ARRAY_BUFFER, _vboData); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIdx); glNormalPointer(GL_DOUBLE, sizeof(ArbitraryMeshVertex), BUFFER_OFFSET(16)); glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_DOUBLE, sizeof(ArbitraryMeshVertex), BUFFER_OFFSET(0)); glVertexPointer(3, GL_DOUBLE, sizeof(ArbitraryMeshVertex), BUFFER_OFFSET(40)); const RenderIndex* strip_indices = 0; for (std::size_t i = 0; i < m_tess.m_numStrips; i++, strip_indices += m_tess.m_lenStrips) { glDrawElements(GL_QUAD_STRIP, GLsizei(m_tess.m_lenStrips), RenderIndexTypeID, strip_indices); } GlobalOpenGL().assertNoErrors(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); #else if (m_tess.vertices.empty() || m_tess.indices.empty()) return; if (info.checkFlag(RENDER_BUMP)) { glVertexAttribPointerARB(11, 3, GL_DOUBLE, 0, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().normal); glVertexAttribPointerARB(8, 2, GL_DOUBLE, 0, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().texcoord); glVertexAttribPointerARB(9, 3, GL_DOUBLE, 0, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().tangent); glVertexAttribPointerARB(10, 3, GL_DOUBLE, 0, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().bitangent); } else { glNormalPointer(GL_DOUBLE, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().normal); glTexCoordPointer(2, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().texcoord); } glVertexPointer(3, GL_DOUBLE, sizeof(ArbitraryMeshVertex), &m_tess.vertices.front().vertex); const RenderIndex* strip_indices = &m_tess.indices.front(); for(std::size_t i = 0; i<m_tess.m_numStrips; i++, strip_indices += m_tess.m_lenStrips) { glDrawElements(GL_QUAD_STRIP, GLsizei(m_tess.m_lenStrips), RenderIndexTypeID, strip_indices); } #if defined(_DEBUG) //RenderNormals(); #endif #endif }
enum piglit_result piglit_display(void) { enum piglit_result result = PIGLIT_PASS; unsigned r; unsigned c; glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_FRAGMENT_PROGRAM_ARB); glEnable(GL_VERTEX_PROGRAM_ARB); glVertexAttribPointerARB(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), position); glVertexAttribPointerARB(1, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), axis); glVertexAttribPointerARB(2, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), direction); glEnableVertexAttribArrayARB(0); glEnableVertexAttribArrayARB(1); glEnableVertexAttribArrayARB(2); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vert_prog); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, frag_prog); glPointSize((float) BOX_SIZE); glDrawArrays(GL_POINTS, 0, TEST_ROWS * TEST_COLS); for (r = 0; r < TEST_ROWS; r++) { for (c = 0; c < TEST_COLS; c++) { const int idx = 4 * ((r * TEST_COLS) + c); if (!piglit_probe_pixel_rgb(position[idx + 0], position[idx + 1], green)) { printf("direction = { %.2f %.2f %.2f }\n" "axis = { %.2f %.2f %.2f }\n", direction[idx + 0], direction[idx + 1], direction[idx + 2], axis[idx + 0], axis[idx + 1], axis[idx + 2]); } } } glutSwapBuffers(); return result; }
// virtual (default) void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const { LLMemType mt(LLMemType::MTYPE_VERTEX_DATA); stop_glerror(); U8* base = useVBOs() ? NULL : mMappedData; S32 stride = mStride; if ((data_mask & mTypeMask) != data_mask) { llerrs << "LLVertexBuffer::setupVertexBuffer missing required components for supplied data mask." << llendl; } if (data_mask & MAP_VERTEX) { glVertexPointer(3,GL_FLOAT, stride, (void*)(base + 0)); } if (data_mask & MAP_NORMAL) { glNormalPointer(GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_NORMAL])); } if (data_mask & MAP_TEXCOORD2) { glClientActiveTextureARB(GL_TEXTURE1_ARB); glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); } if (data_mask & MAP_TEXCOORD) { glClientActiveTextureARB(GL_TEXTURE0_ARB); glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD])); } if (data_mask & MAP_COLOR) { glColorPointer(4, GL_UNSIGNED_BYTE, stride, (void*)(base + mOffsets[TYPE_COLOR])); } if (data_mask & MAP_BINORMAL) { glVertexAttribPointerARB(6, 3, GL_FLOAT, FALSE, stride, (void*)(base + mOffsets[TYPE_BINORMAL])); } if (data_mask & MAP_WEIGHT) { glVertexAttribPointerARB(1, 1, GL_FLOAT, FALSE, stride, (void*)(base + mOffsets[TYPE_WEIGHT])); } if (data_mask & MAP_CLOTHWEIGHT) { glVertexAttribPointerARB(4, 4, GL_FLOAT, TRUE, stride, (void*)(base + mOffsets[TYPE_CLOTHWEIGHT])); } llglassertok(); }
void cRendererGLES2::TexCoordPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) { if ( mCurShaderLocal ) { if ( 1 == mTexActive ) { if ( mCurShader == mShaders[ EEGLES2_SHADER_PRIMITIVE ] ) { if ( mClippingEnabled ) { SetShader( EEGLES2_SHADER_CLIPPED ); } else if ( mPointSpriteEnabled ) { SetShader( EEGLES2_SHADER_POINTSPRITE ); } else { SetShader( EEGLES2_SHADER_BASE ); } } } } const GLint index = mTextureUnits[ mCurActiveTex ]; if ( -1 != index ) { if ( 0 == mTextureUnitsStates[ mCurActiveTex ] ) { mTextureUnitsStates[ mCurActiveTex ] = 1; glEnableVertexAttribArray( index ); } glVertexAttribPointerARB( index, size, type, GL_FALSE, stride, pointer ); } }
static void draw_arrays(int i) { struct galaxy *g = get_galaxy(i); GLsizei sz = sizeof (struct star); if (GL_has_vertex_program) glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 1, g->magnitude, 0, 0, 0); /* Enable the star arrays. */ glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); /* Bind the vertex buffers. */ if (GL_has_vertex_buffer_object) { glEnableVertexAttribArrayARB(6); glBindBufferARB(GL_ARRAY_BUFFER_ARB, g->buffer); glColorPointer (3, GL_UNSIGNED_BYTE, sz, (GLvoid *) 0); glVertexPointer(3, GL_FLOAT, sz, (GLvoid *) 4); glVertexAttribPointerARB(6, 1, GL_FLOAT, 0, sz, (GLvoid *) 16); } else { glColorPointer (3, GL_UNSIGNED_BYTE, sz, g->S->col); glVertexPointer(3, GL_FLOAT, sz, g->S->pos); } }
void Renderer::drawQuad(Shader *shader, vec4 color, GLuint texId) { if (shader == 0) shader = quadShader; if (!bindShader(shader)) return; glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); float time = (timeGetTime() - startTime) / 10000.0f; float h = glutGet(GLUT_WINDOW_HEIGHT); float w = glutGet(GLUT_WINDOW_WIDTH); shader->setUniform1f("time", time); shader->setUniform2f("resolution", vec2(w, h)); shader->setUniform4fv("color", 1, (float*)&color); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboQuad); GLuint uniform_pos = glGetAttribLocation(shader->shaderProgram, "position"); glEnableVertexAttribArrayARB(uniform_pos); glVertexAttribPointerARB(uniform_pos, 2, GL_FLOAT, GL_FALSE, sizeof(vec2), 0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); /*char c[200]; sprintf_s(c, "%f", time); render_text(0, c, 0, 12, vec4(1, 1, 1, 10));*/ }
void VAR::vertexAttribPointer(uint attribNum, bool normalize) const { debugAssert(valid()); if (GLCaps::supports_GL_ARB_vertex_program()) { glEnableVertexAttribArrayARB(attribNum); glVertexAttribPointerARB(attribNum, elementSize / sizeOfGLFormat(underlyingRepresentation), underlyingRepresentation, normalize, elementSize, _pointer); } }
void cRendererGLES2::ColorPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer, GLuint allocate ) { const GLint index = mAttribsLoc[ EEGL_COLOR_ARRAY ]; if ( -1 != index ) { if ( 0 == mAttribsLocStates[ EEGL_COLOR_ARRAY ] ) { mAttribsLocStates[ EEGL_COLOR_ARRAY ] = 1; glEnableVertexAttribArray( index ); } if ( type == GL_UNSIGNED_BYTE ) { glVertexAttribPointerARB( index, size, type, GL_TRUE, stride, pointer ); } else { glVertexAttribPointerARB( index, size, type, GL_FALSE, stride, pointer ); } } }
inline void VL_glVertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) { if (glVertexAttribPointer) glVertexAttribPointer(index, size, type, normalized, stride, pointer); else if (glVertexAttribPointerARB) glVertexAttribPointerARB(index, size, type, normalized, stride, pointer); else VL_UNSUPPORTED_FUNC(); }
void Object::updateVAO() { if (VAO==(GLuint)-1) glGenVertexArrays(1,&VAO); glBindVertexArray(VAO); glBindBufferARB(GL_ARRAY_BUFFER,vertexVBO); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, indexVBO); glEnableVertexAttribArray(0); glVertexAttribPointerARB(0,3,GL_FLOAT,GL_FALSE,sizeof(VertexDatum),0); glEnableVertexAttribArray(1); glVertexAttribPointerARB(1,4,GL_FLOAT,GL_FALSE,sizeof(VertexDatum),(void*)(3*sizeof(float))); glEnableVertexAttribArray(2); glVertexAttribPointerARB(2,2,GL_FLOAT,GL_FALSE,sizeof(VertexDatum),(void*)(10*sizeof(float))); glEnableVertexAttribArray(3); glVertexAttribPointerARB(3,3,GL_FLOAT,GL_FALSE,sizeof(VertexDatum),(void*)(7*sizeof(float))); glEnableVertexAttribArray(4); glVertexAttribPointerARB(4,4,GL_FLOAT,GL_FALSE,sizeof(VertexDatum),(void*)(12*sizeof(float))); glBindVertexArray(0); }
void CShadersManager::EnableTangents (GLfloat * tangents) { if((this->Program == ParallaxMappingSPT) || (this->Program == NormalMappingSPT)) { int tanloc = glGetAttribLocationARB(this->Programs[this->Program].GetHandle(), "Tangent"); glEnableVertexAttribArrayARB(tanloc); glVertexAttribPointerARB(tanloc, 3, GL_FLOAT, 0, 0, tangents); } }
static void draw_vert(GLubyte *base) { GLsizei s = sizeof (struct object_vert); /* Enable all necessary vertex attribute pointers. */ glEnableClientState(GL_VERTEX_ARRAY); glEnableVertexAttribArrayARB(6); glEnableVertexAttribArrayARB(7); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); /* Bind all vertex attribute pointers. */ glVertexPointer (3, GL_FLOAT, s, base); glVertexAttribPointerARB(6, 3, GL_FLOAT, 0, s, base + 3 * sizeof (float)); glVertexAttribPointerARB(7, 3, GL_FLOAT, 0, s, base + 6 * sizeof (float)); glNormalPointer ( GL_FLOAT, s, base + 9 * sizeof (float)); glTexCoordPointer (2, GL_FLOAT, s, base + 12 * sizeof (float)); }
void cRendererGLES2::VertexPointer ( GLint size, GLenum type, GLsizei stride, const GLvoid * pointer, GLuint allocate ) { const GLint index = mAttribsLoc[ EEGL_VERTEX_ARRAY ]; if ( -1 != index ) { if ( 0 == mAttribsLocStates[ EEGL_VERTEX_ARRAY ] ) { mAttribsLocStates[ EEGL_VERTEX_ARRAY ] = 1; glEnableVertexAttribArray( index ); } glVertexAttribPointerARB( index, size, type, GL_FALSE, stride, pointer ); } }
void VertexArrayNoVao::enableOpenGLVertexAttribArrays() { #ifndef OPENGLRENDERER_NO_STATE_CLEANUP // Backup the currently bound OpenGL array buffer // -> Using "GL_EXT_direct_state_access" this would not help in here because "glVertexAttribPointerARB" is not specified there :/ GLint openGLArrayBufferBackup = 0; glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB, &openGLArrayBufferBackup); #endif // Loop through all attributes // -> We're using "glBindAttribLocationARB()" when linking the program so we have known attribute locations (the vertex array can't know about the program) GLuint attributeLocation = 0; const Renderer::VertexAttribute *attributeEnd = mAttributes + mNumberOfAttributes; for (const Renderer::VertexAttribute *attribute = mAttributes; attribute < attributeEnd; ++attribute, ++attributeLocation) { // Set the OpenGL vertex attribute pointer // TODO(co) Add security check: Is the given resource one of the currently used renderer? const Renderer::VertexArrayVertexBuffer& vertexArrayVertexBuffer = mVertexBuffers[attribute->inputSlot]; glBindBufferARB(GL_ARRAY_BUFFER_ARB, static_cast<VertexBuffer*>(vertexArrayVertexBuffer.vertexBuffer)->getOpenGLArrayBuffer()); glVertexAttribPointerARB(attributeLocation, Mapping::getOpenGLSize(attribute->vertexAttributeFormat), Mapping::getOpenGLType(attribute->vertexAttributeFormat), static_cast<GLboolean>(Mapping::isOpenGLVertexAttributeFormatNormalized(attribute->vertexAttributeFormat)), static_cast<GLsizei>(vertexArrayVertexBuffer.strideInBytes), reinterpret_cast<GLvoid*>(attribute->alignedByteOffset)); // Per-instance instead of per-vertex requires "GL_ARB_instanced_arrays" if (attribute->instancesPerElement > 0 && mIsGL_ARB_instanced_arrays) { glVertexAttribDivisorARB(attributeLocation, attribute->instancesPerElement); } // Enable OpenGL vertex attribute array glEnableVertexAttribArrayARB(attributeLocation); } #ifndef OPENGLRENDERER_NO_STATE_CLEANUP // Be polite and restore the previous bound OpenGL array buffer glBindBufferARB(GL_ARRAY_BUFFER_ARB, static_cast<GLuint>(openGLArrayBufferBackup)); #endif // Get the used index buffer // -> In case of no index buffer we don't bind buffer 0, there's not really a point in it const IndexBuffer *indexBuffer = getIndexBuffer(); if (nullptr != indexBuffer) { // Bind OpenGL element array buffer glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexBuffer->getOpenGLElementArrayBuffer()); } }
void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numdata) { int i; int elementsize; intptr_t offset = 0; for(i = 0; i < MAX_GPU_ATTRIB_DATA; i++) { if(attribData[i].index != -1) { glDisableVertexAttribArrayARB(attribData[i].index); } else break; } elementsize = GPU_attrib_element_size(data, numdata); if(useVBOs) { glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer->id); for(i = 0; i < numdata; i++) { glEnableVertexAttribArrayARB(data[i].index); glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type, GL_FALSE, elementsize, (void *)offset); offset += data[i].size*GPU_typesize(data[i].type); attribData[i].index = data[i].index; attribData[i].size = data[i].size; attribData[i].type = data[i].type; } attribData[numdata].index = -1; } else { for(i = 0; i < numdata; i++) { glEnableVertexAttribArrayARB(data[i].index); glVertexAttribPointerARB(data[i].index, data[i].size, data[i].type, GL_FALSE, elementsize, (char *)buffer->pointer + offset); offset += data[i].size*GPU_typesize(data[i].type); } } }
static void render(struct glpal_ctx *ctx, GLuint draw_tex) {DEBUG_CHECK_GL_ERR; static const float verts[] = { 0, 0 , -1, -1, 1, 0 , 1, -1, 0, 1 , -1, 1, 1, 1 , 1, 1 }; struct priv_ctx *priv = (struct priv_ctx *)ctx; glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); glUseProgramObjectARB(priv->prog); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, draw_tex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_1D, priv->tex[priv->cnt]); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, pal_ctx_get_active(priv->pal)); priv->cnt = (priv->cnt+1)%2; glBindTexture(GL_TEXTURE_1D, priv->tex[priv->cnt]); glEnableVertexAttribArrayARB(0); glVertexAttribPointerARB(0, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4, verts); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glUseProgramObjectARB(0); glDisableVertexAttribArrayARB(0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_1D, 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); glPopClientAttrib(); DEBUG_CHECK_GL_ERR; }
void VertexBuffer::Bind() { GLCHECK(glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->_id)); this->_renderer.bindedVertexBuffer = this; auto program = dynamic_cast<Program*>(&this->_renderer.GetCurrentProgram()); if (program == nullptr) { for (auto it = this->_attributes, itEnd = this->_attributes + this->_nbAttrib; it != itEnd; ++it) { GLCHECK(glVertexAttribPointerARB(GetVertexAttributeIndex(it->location), it->nbElements, it->type, GL_FALSE, this->_stride, it->offset)); GLCHECK(glEnableVertexAttribArrayARB(GetVertexAttributeIndex(it->location))); } } else { for (auto it = this->_attributes, itEnd = this->_attributes + this->_nbAttrib; it != itEnd; ++it) { GLCHECK(glVertexAttribPointer(program->GetAttributeIndex(it->location), it->nbElements, it->type, GL_FALSE, this->_stride, it->offset)); GLCHECK(glEnableVertexAttribArray(program->GetAttributeIndex(it->location))); } } }
static void render(struct glpal_ctx *ctx, GLuint draw_tex) {DEBUG_CHECK_GL_ERR; static const float verts[] = { 0, 0 , -1, -1, 1, 0 , 1, -1, 0, 1 , -1, 1, 1, 1 , 1, 1 }; struct priv_ctx *priv = (struct priv_ctx *)ctx; glPushAttrib(GL_TEXTURE_BIT); glUseProgramObjectARB(priv->prog); glUniform1fARB(priv->palpos_loc, priv->palpos/255.0f); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, draw_tex); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_1D, priv->pal_tex[priv->curpal]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_1D, priv->pal_tex[priv->nextpal]); glEnableVertexAttribArrayARB(0); glVertexAttribPointerARB(0, 4, GL_FLOAT, GL_FALSE, sizeof(float)*4, verts); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glUseProgramObjectARB(0); glDisableVertexAttribArrayARB(0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_1D, 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); glPopAttrib(); DEBUG_CHECK_GL_ERR; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBVertexProgram_nglVertexAttribPointerARB(JNIEnv *env, jclass clazz, jint index, jint size, jint type, jboolean normalized, jint stride, jobject buffer, jint buffer_position, jlong function_pointer) { const GLvoid *buffer_address = ((const GLvoid *)(((char *)(*env)->GetDirectBufferAddress(env, buffer)) + buffer_position)); glVertexAttribPointerARBPROC glVertexAttribPointerARB = (glVertexAttribPointerARBPROC)((intptr_t)function_pointer); glVertexAttribPointerARB(index, size, type, normalized, stride, buffer_address); }
void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, int *attrib_layer) { int unit; // Bind buffers glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo); glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id); // Vertexes glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, this->stride, this->vertex_offset); // Normals glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, this->stride, this->normal_offset); // Colors glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, this->stride, this->color_offset); for (unit = 0; unit < texco_num; ++unit) { glClientActiveTexture(GL_TEXTURE0_ARB + unit); switch (texco[unit]) { case RAS_IRasterizer::RAS_TEXCO_ORCO: case RAS_IRasterizer::RAS_TEXCO_GLOB: glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, this->stride, this->vertex_offset); break; case RAS_IRasterizer::RAS_TEXCO_UV: glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, this->stride, (void*)((intptr_t)this->uv_offset+(sizeof(GLfloat)*2*unit))); break; case RAS_IRasterizer::RAS_TEXCO_NORM: glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(3, GL_FLOAT, this->stride, this->normal_offset); break; case RAS_IRasterizer::RAS_TEXTANGENT: glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(4, GL_FLOAT, this->stride, this->tangent_offset); break; default: break; } } glClientActiveTextureARB(GL_TEXTURE0_ARB); if (GLEW_ARB_vertex_program) { for (unit = 0; unit < attrib_num; ++unit) { switch (attrib[unit]) { case RAS_IRasterizer::RAS_TEXCO_ORCO: case RAS_IRasterizer::RAS_TEXCO_GLOB: glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, this->stride, this->vertex_offset); glEnableVertexAttribArrayARB(unit); break; case RAS_IRasterizer::RAS_TEXCO_UV: glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+attrib_layer[unit]*sizeof(GLfloat)*2)); glEnableVertexAttribArrayARB(unit); break; case RAS_IRasterizer::RAS_TEXCO_NORM: glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, stride, this->normal_offset); glEnableVertexAttribArrayARB(unit); break; case RAS_IRasterizer::RAS_TEXTANGENT: glVertexAttribPointerARB(unit, 4, GL_FLOAT, GL_FALSE, this->stride, this->tangent_offset); glEnableVertexAttribArrayARB(unit); break; case RAS_IRasterizer::RAS_TEXCO_VCOL: glVertexAttribPointerARB(unit, 4, GL_UNSIGNED_BYTE, GL_TRUE, this->stride, this->color_offset); glEnableVertexAttribArrayARB(unit); default: break; } } } glDrawElements(this->mode, this->indices, GL_UNSIGNED_SHORT, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); if (GLEW_ARB_vertex_program) { for (int i = 0; i < attrib_num; ++i) glDisableVertexAttribArrayARB(i); } glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); }
void Viewer::renderModel() { glBindProgramARB( GL_VERTEX_PROGRAM_ARB, m_vertexProgramId ); glEnableVertexAttribArrayARB(0); glEnableVertexAttribArrayARB(1); glEnableVertexAttribArrayARB(2); glEnableVertexAttribArrayARB(3); glEnableVertexAttribArrayARB(8); glEnable(GL_TEXTURE_2D); // set global OpenGL states glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_VERTEX_PROGRAM_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[0]); glVertexAttribPointerARB(0, 3 , GL_FLOAT, false, 0, NULL); glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[1]); glVertexAttribPointerARB(1, 4 , GL_FLOAT, false, 0, NULL); glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[2]); glVertexAttribPointerARB(2, 3 , GL_FLOAT, false, 0, NULL); glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[3]); glVertexAttribPointerARB(3, 4 , GL_FLOAT, false, 0, NULL); glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferObject[4]); glVertexAttribPointerARB(8, 2 , GL_FLOAT, false, 0, NULL); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferObject[5]); int hardwareMeshId; for(hardwareMeshId=0;hardwareMeshId<m_calHardwareModel->getHardwareMeshCount() ; hardwareMeshId++) { m_calHardwareModel->selectHardwareMesh(hardwareMeshId); unsigned char meshColor[4]; float materialColor[4]; // set the material ambient color m_calHardwareModel->getAmbientColor(&meshColor[0]); materialColor[0] = meshColor[0] / 255.0f; materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f; glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor); // set the material diffuse color m_calHardwareModel->getDiffuseColor(&meshColor[0]); materialColor[0] = meshColor[0] / 255.0f; materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f; glMaterialfv(GL_FRONT, GL_DIFFUSE, materialColor); // set the material specular color m_calHardwareModel->getSpecularColor(&meshColor[0]); materialColor[0] = meshColor[0] / 255.0f; materialColor[1] = meshColor[1] / 255.0f; materialColor[2] = meshColor[2] / 255.0f; materialColor[3] = meshColor[3] / 255.0f; glMaterialfv(GL_FRONT, GL_SPECULAR, materialColor); // set the material shininess factor float shininess; shininess = 50.0f; //m_calHardwareModel->getShininess(); glMaterialfv(GL_FRONT, GL_SHININESS, &shininess); int boneId; for(boneId = 0; boneId < m_calHardwareModel->getBoneCount(); boneId++) { CalQuaternion rotationBoneSpace = m_calHardwareModel->getRotationBoneSpace(boneId, m_calModel->getSkeleton()); CalVector translationBoneSpace = m_calHardwareModel->getTranslationBoneSpace(boneId, m_calModel->getSkeleton()); CalMatrix rotationMatrix = rotationBoneSpace; float transformation[12]; transformation[0]=rotationMatrix.dxdx;transformation[1]=rotationMatrix.dxdy;transformation[2]=rotationMatrix.dxdz;transformation[3]=translationBoneSpace.x; transformation[4]=rotationMatrix.dydx;transformation[5]=rotationMatrix.dydy;transformation[6]=rotationMatrix.dydz;transformation[7]=translationBoneSpace.y; transformation[8]=rotationMatrix.dzdx;transformation[9]=rotationMatrix.dzdy;transformation[10]=rotationMatrix.dzdz;transformation[11]=translationBoneSpace.z; glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,boneId*3,&transformation[0]); glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,boneId*3+1,&transformation[4]); glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,boneId*3+2,&transformation[8]); // set the texture id we stored in the map user data glBindTexture(GL_TEXTURE_2D, (GLuint)(size_t)m_calHardwareModel->getMapUserData(0)); } if(sizeof(CalIndex)==2) glDrawElements(GL_TRIANGLES, m_calHardwareModel->getFaceCount() * 3, GL_UNSIGNED_SHORT, (((CalIndex *)NULL)+ m_calHardwareModel->getStartIndex())); else glDrawElements(GL_TRIANGLES, m_calHardwareModel->getFaceCount() * 3, GL_UNSIGNED_INT, (((CalIndex *)NULL)+ m_calHardwareModel->getStartIndex())); } // clear vertex array state glDisableVertexAttribArrayARB(0); glDisableVertexAttribArrayARB(1); glDisableVertexAttribArrayARB(2); glDisableVertexAttribArrayARB(3); glDisableVertexAttribArrayARB(8); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); // clear light glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_DEPTH_TEST); glDisable(GL_VERTEX_PROGRAM_ARB); glBindProgramARB( GL_VERTEX_PROGRAM_ARB, 0 ); }
static void va_render () { GLint i; for (i = 0; i < sizeof (attribs) / sizeof (*attribs); i++) { struct ATTRIB_DATA *att = &attribs[i]; switch (att->dispatch) { case C: glColorPointer (4, GL_FLOAT, 0, att->data); glEnable (GL_COLOR_ARRAY); break; case S: glSecondaryColorPointerEXT (4, GL_FLOAT, 0, att->data); glEnable (GL_SECONDARY_COLOR_ARRAY_EXT); break; case N: glNormalPointer (GL_FLOAT, 0, att->data); glEnable (GL_NORMAL_ARRAY); break; case V: glVertexPointer (4, GL_FLOAT, 0, att->data); glEnable (GL_VERTEX_ARRAY); break; case T: assert (att->index >= 0 && att->index < 8); glClientActiveTextureARB (GL_TEXTURE0_ARB + att->index); glTexCoordPointer (4, GL_FLOAT, 0, att->data); glEnable (GL_TEXTURE_COORD_ARRAY); break; case F: glFogCoordPointerEXT (GL_FLOAT, 0, att->data); glEnable (GL_FOG_COORDINATE_ARRAY_EXT); break; case A: assert (att->index > 0 && att->index < 16); glVertexAttribPointerARB (att->index, 4, GL_FLOAT, GL_FALSE, 0, att->data); glEnableVertexAttribArrayARB (att->index); break; default: assert (0); } } glDrawArrays (GL_POINTS, 0, 1); for (i = 0; i < sizeof (attribs) / sizeof (*attribs); i++) { struct ATTRIB_DATA *att = &attribs[i]; switch (att->dispatch) { case C: glDisable (GL_COLOR_ARRAY); break; case S: glDisable (GL_SECONDARY_COLOR_ARRAY_EXT); break; case N: glDisable (GL_NORMAL_ARRAY); break; case V: glDisable (GL_VERTEX_ARRAY); break; case T: glClientActiveTextureARB (GL_TEXTURE0_ARB + att->index); glDisable (GL_TEXTURE_COORD_ARRAY); break; case F: glDisable (GL_FOG_COORDINATE_ARRAY_EXT); break; case A: glDisableVertexAttribArrayARB (att->index); break; default: assert (0); } } }
/** Test legacy/fixed-function vertex array drawing */ static GLboolean test_fixedfunc_arrays(void) { static const GLfloat expected[4] = {0.5, 0.0, 0.5, 1.0}; static const GLfloat black[4] = {0.0, 0.0, 0.0, 0.0}; GLuint buf; GLboolean p,pass = GL_TRUE; buf = setup_vbo(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf); /* * Draw with conventional arrays. */ { glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), (void *) 0); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("conventional vertex arrays\n"); pass = GL_FALSE; } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); } /* * Draw with generic array[0]=position * XXX this should only work when the driver aliases conventional * vertex attributes with the generic attributes (as w/ NVIDIA). * XXX check for that and enable this code some day. */ if (0) { GLuint attrib = 0; glVertexAttribPointerARB(attrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(attrib); glEnableClientState(GL_COLOR_ARRAY); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("generic array [%u]\n", attrib); pass = GL_FALSE; } glDisableVertexAttribArrayARB(attrib); glDisableClientState(GL_COLOR_ARRAY); } /* * Draw without GL_VERTEX or GENERIC[0] array set (should NOT draw) */ { GLuint attrib = 3; glVertexAttribPointerARB(attrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(attrib); glEnableClientState(GL_COLOR_ARRAY); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, black); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("generic array [%u]\n", attrib); pass = GL_FALSE; } glDisableVertexAttribArrayARB(attrib); glDisableClientState(GL_COLOR_ARRAY); } piglit_present_results(); glDeleteBuffersARB(1, &buf); return pass; }
/** Test drawing with GL_ARB_vertex_program */ static GLboolean test_arbvp_arrays(void) { /* Use legacy vertex array/attribute */ static const char *legacyVertProgramText = "!!ARBvp1.0 \n" "ATTRIB iPos = vertex.position;\n" "OUTPUT oPos = result.position;\n" "PARAM mvp[4] = { state.matrix.mvp };\n" "DP4 oPos.x, mvp[0], iPos;\n" "DP4 oPos.y, mvp[1], iPos;\n" "DP4 oPos.z, mvp[2], iPos;\n" "DP4 oPos.w, mvp[3], iPos;\n" "MOV result.color, vertex.color;\n" "END"; /* Use generic vertex array/attribute[0] */ static const char *generic0VertProgramText = "!!ARBvp1.0 \n" "ATTRIB iPos = vertex.attrib[0];\n" "OUTPUT oPos = result.position;\n" "PARAM mvp[4] = { state.matrix.mvp };\n" "DP4 oPos.x, mvp[0], iPos;\n" "DP4 oPos.y, mvp[1], iPos;\n" "DP4 oPos.z, mvp[2], iPos;\n" "DP4 oPos.w, mvp[3], iPos;\n" "MOV result.color, vertex.color;\n" "END"; /* Use generic vertex array/attribute[6] */ static const char *generic6VertProgramText = "!!ARBvp1.0 \n" "ATTRIB iPos = vertex.attrib[6];\n" "OUTPUT oPos = result.position;\n" "PARAM mvp[4] = { state.matrix.mvp };\n" "DP4 oPos.x, mvp[0], iPos;\n" "DP4 oPos.y, mvp[1], iPos;\n" "DP4 oPos.z, mvp[2], iPos;\n" "DP4 oPos.w, mvp[3], iPos;\n" "MOV result.color, vertex.color;\n" "END"; static const char *fragProgramText = "!!ARBfp1.0 \n" "MOV result.color, fragment.color;\n" "END"; static const GLfloat expected[4] = {0.5, 0.0, 0.5, 1.0}; GLuint buf; GLboolean p, pass = GL_TRUE; GLuint vertProg, fragProg; buf = setup_vbo(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf); fragProg = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fragProgramText); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragProg); glEnable(GL_FRAGMENT_PROGRAM_ARB); glEnable(GL_VERTEX_PROGRAM_ARB); /* * Draw with pos in conventional arrays. */ { vertProg = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, legacyVertProgramText); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertProg); glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), (void *) 0); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("ARB VP and conventional vertex arrays\n"); pass = GL_FALSE; } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDeleteProgramsARB(1, &vertProg); } /* * Draw with pos in generic array[0]. */ { GLuint attrib = 0; vertProg = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, generic0VertProgramText); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertProg); glVertexAttribPointerARB(attrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(attrib); glEnableClientState(GL_COLOR_ARRAY); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("ARB VP and generic vertex array[%u]\n", attrib); pass = GL_FALSE; } glDisableVertexAttribArrayARB(attrib); glDisableClientState(GL_COLOR_ARRAY); glDeleteProgramsARB(1, &vertProg); } /* * Draw with pos in generic array[6]. */ { GLuint attrib = 6; vertProg = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, generic6VertProgramText); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertProg); glVertexAttribPointerARB(attrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glColorPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(attrib); glEnableClientState(GL_COLOR_ARRAY); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("ARB VP and generic vertex array[%u]\n", attrib); pass = GL_FALSE; } glDisableVertexAttribArrayARB(attrib); glDisableClientState(GL_COLOR_ARRAY); glDeleteProgramsARB(1, &vertProg); } glDisable(GL_FRAGMENT_PROGRAM_ARB); glDisable(GL_VERTEX_PROGRAM_ARB); glDeleteProgramsARB(1, &fragProg); glDeleteBuffersARB(1, &buf); return pass; }
void Doom3Model::glRenderAction(GLContextData& contextData,Doom3MaterialManager::RenderContext& mmRc) const { /* Get the context data item: */ DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this); /* Get the index of the tangent vector vertex attribute: */ GLint tangentAttributeIndexS=materialManager.getTangentAttributeIndex(mmRc,0); GLint tangentAttributeIndexT=materialManager.getTangentAttributeIndex(mmRc,1); /* Enable the appropriate vertex arrays: */ glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); if(tangentAttributeIndexS>=0) glEnableVertexAttribArrayARB(tangentAttributeIndexS); if(tangentAttributeIndexT>=0) glEnableVertexAttribArrayARB(tangentAttributeIndexT); glEnableClientState(GL_VERTEX_ARRAY); /* Install the vertex and index arrays: */ const Vertex* vertexPtr; const GLuint* indexPtr; if(dataItem->hasVertexBufferExtension) { /* Bind the model's vertex buffer: */ glBindBufferARB(GL_ARRAY_BUFFER_ARB,dataItem->vertexBufferId); vertexPtr=0; /* Bind the mesh's index buffer: */ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,dataItem->indexBufferId); indexPtr=0; } else { vertexPtr=&vertices[0]; indexPtr=&vertexIndices[0]; } glTexCoordPointer(2,sizeof(Vertex),vertexPtr->texCoord.getComponents()); glNormalPointer(sizeof(Vertex),vertexPtr->normal.getComponents()); if(tangentAttributeIndexS>=0) glVertexAttribPointerARB(tangentAttributeIndexS,3,GL_FALSE,sizeof(Vertex),vertexPtr->tangents[0].getComponents()); if(tangentAttributeIndexT>=0) glVertexAttribPointerARB(tangentAttributeIndexT,3,GL_FALSE,sizeof(Vertex),vertexPtr->tangents[1].getComponents()); glVertexPointer(3,sizeof(Vertex),vertexPtr->position.getComponents()); /* Render all surfaces: */ for(std::vector<Surface>::const_iterator sIt=surfaces.begin();sIt!=surfaces.end();++sIt) { /* Install the mesh's material and check whether to render this mesh: */ if(materialManager.setMaterial(mmRc,sIt->material)) { /* Render the surface: */ glDrawElements(GL_TRIANGLES,sIt->numVertexIndices,GL_UNSIGNED_INT,indexPtr); } /* Go to the next surface's vertex indices: */ indexPtr+=sIt->numVertexIndices; } if(dataItem->hasVertexBufferExtension) { /* Unbind all buffers: */ glBindBufferARB(GL_ARRAY_BUFFER_ARB,0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0); } /* Disable the appropriate vertex arrays: */ glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); if(tangentAttributeIndexS>=0) glDisableVertexAttribArrayARB(tangentAttributeIndexS); if(tangentAttributeIndexT>=0) glDisableVertexAttribArrayARB(tangentAttributeIndexT); glDisableClientState(GL_VERTEX_ARRAY); }
/** Test drawing with GLSL shaders */ static GLboolean test_glsl_arrays(void) { static const char *vertShaderText = "attribute vec4 color, pos; \n" "varying vec4 colorVar; \n" "void main() \n" "{ \n" " colorVar = color; \n" " gl_Position = gl_ModelViewProjectionMatrix * pos; \n" "} \n"; static const char *fragShaderText = "varying vec4 colorVar; \n" "void main() \n" "{ \n" " gl_FragColor = colorVar; \n" "} \n"; static const GLfloat expected[4] = {0.5, 0.0, 0.5, 1.0}; GLuint buf; GLboolean p, pass = GL_TRUE; GLint posAttrib, colorAttrib; GLuint vertShader, fragShader, program; buf = setup_vbo(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf); vertShader = piglit_compile_shader_text(GL_VERTEX_SHADER, vertShaderText); fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragShaderText); program = piglit_link_simple_program(vertShader, fragShader); glUseProgram(program); /* * Draw with compiler-assigned attribute locations */ { posAttrib = glGetAttribLocation(program, "pos"); colorAttrib = glGetAttribLocation(program, "color"); if (0) printf("%s: GLSL posAttrib = %d colorAttrib = %d\n", TestName, posAttrib, colorAttrib); glVertexAttribPointerARB(posAttrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glVertexAttribPointerARB(colorAttrib, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(posAttrib); glEnableVertexAttribArrayARB(colorAttrib); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("compiler-assigned attribute locations\n"); pass = GL_FALSE; } glDisableVertexAttribArrayARB(posAttrib); glDisableVertexAttribArrayARB(colorAttrib); } /* * Draw with user-defined attribute bindings, not using 0. */ { posAttrib = 5; colorAttrib = 7; glBindAttribLocation(program, posAttrib, "pos"); glBindAttribLocation(program, colorAttrib, "color"); glLinkProgram(program); glVertexAttribPointerARB(posAttrib, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (void *) 0); glVertexAttribPointerARB(colorAttrib, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void *) (8 * sizeof(GLfloat))); glEnableVertexAttribArrayARB(posAttrib); glEnableVertexAttribArrayARB(colorAttrib); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_QUADS, 0, 4); p = piglit_probe_pixel_rgba(piglit_width/2, piglit_height/2, expected); piglit_present_results(); if (!p) { printf("%s: failed when drawing with ", TestName); printf("user-assigned attribute locations\n"); pass = GL_FALSE; } glDisableVertexAttribArrayARB(posAttrib); glDisableVertexAttribArrayARB(colorAttrib); } glDeleteShader(vertShader); glDeleteProgram(program); glDeleteBuffersARB(1, &buf); return pass; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBVertexProgram_nglVertexAttribPointerARBBO(JNIEnv *env, jclass clazz, jint index, jint size, jint type, jboolean normalized, jint stride, jlong buffer_buffer_offset, jlong function_pointer) { const GLvoid *buffer_address = ((const GLvoid *)offsetToPointer(buffer_buffer_offset)); glVertexAttribPointerARBPROC glVertexAttribPointerARB = (glVertexAttribPointerARBPROC)((intptr_t)function_pointer); glVertexAttribPointerARB(index, size, type, normalized, stride, buffer_address); }