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);
        }
    }
	bool initVertexArray()
	{
		glGenVertexArrays(1, &VertexArrayName);
		glBindVertexArray(VertexArrayName);
			glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]);
			glVertexAttribPointer(semantic::attr::POSITION + 0, 2, GL_FLOAT, GL_FALSE, sizeof(glf::vertex_v2fc4d), BUFFER_OFFSET(0));
			glVertexAttribPointer(semantic::attr::POSITION + 1, 2, GL_FLOAT, GL_FALSE, sizeof(glf::vertex_v2fc4d), BUFFER_OFFSET(0));
			glVertexAttribLPointer(semantic::attr::COLOR, 4, GL_DOUBLE, sizeof(glf::vertex_v2fc4d), BUFFER_OFFSET(sizeof(glm::vec2)));
			//glVertexAttribLPointer(semantic::attr::COLOR, 4, GL_DOUBLE, sizeof(glf::vertex_v2fc4d), BUFFER_OFFSET(sizeof(glm::vec2)));
			glBindBuffer(GL_ARRAY_BUFFER, 0);

			glEnableVertexAttribArray(semantic::attr::POSITION + 0);
			glEnableVertexAttribArray(semantic::attr::POSITION + 1);
			glEnableVertexAttribArray(semantic::attr::COLOR);
		glBindVertexArray(0);

		/*
		std::vector<glf::vertexattrib> Valid(16); 
		Valid[semantic::attr::POSITION + 0] = glf::vertexattrib(GL_TRUE, 2, sizeof(glf::vertex_v2fc4d), GL_FLOAT, GL_FALSE, GL_FALSE, GL_FALSE, 0, NULL);
		Valid[semantic::attr::POSITION + 1] = glf::vertexattrib(GL_TRUE, 2, sizeof(glf::vertex_v2fc4d), GL_FLOAT, GL_FALSE, GL_FALSE, GL_FALSE, 0, NULL);
		Valid[semantic::attr::COLOR] = glf::vertexattrib(GL_TRUE, 4, sizeof(glf::vertex_v2fc4d), GL_DOUBLE, GL_FALSE, GL_FALSE, GL_FALSE, 0, BUFFER_OFFSET(sizeof(glm::vec2)));

		// TODO
		//glf::validateVAO(VertexArrayName, Valid);
		*/

		return true;
	}
Exemplo n.º 3
0
//! glVertexAttribLPointer wrapper. May throw.
inline void vertexAttribLPointer(GLuint const index,
                                 GLint const size,
                                 GLenum const type,
                                 GLsizei const stride,
                                 GLvoid const* pointer) {
  glVertexAttribLPointer(index, size, type, stride, pointer);
  checkError("glVertexAttribLPointer");
}
Exemplo n.º 4
0
		void VertexAttribLPointer(
			const GLuint Index,
			const GLint Size,
			const EType::Value Type,
			const GLsizei Stride,
			const GLvoid* const Pointer)
		{
			glVertexAttribLPointer(Index, Size, Type, Stride, Pointer);
		}
 inline void VL_glVertexAttribLPointer(GLuint name, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
 {
   if(glVertexAttribLPointer)
     glVertexAttribLPointer(name, size, type, stride, pointer);
   else
   if(glVertexAttribLPointerEXT)
     glVertexAttribLPointerEXT(name, size, type, stride, pointer);
   else
     VL_UNSUPPORTED_FUNC();
 }
Exemplo n.º 6
0
void rglVertexAttribLPointer(
      GLuint index,
      GLint size,
      GLenum type,
      GLsizei stride,
      const GLvoid * pointer)
{
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) && defined(HAVE_OPENGLES3)
   glVertexAttribLPointer(index, size, type, stride, pointer);
#endif
}
Exemplo n.º 7
0
	bool initVertexArray()
	{
		glGenVertexArrays(1, &VertexArrayName);

		glBindVertexArray(VertexArrayName);
			glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::F64]);
			glVertexAttribLPointer(semantic::attr::POSITION, 3, GL_DOUBLE, sizeof(glm::dvec3), BUFFER_OFFSET(0));
			glBindBuffer(GL_ARRAY_BUFFER, 0);

			glEnableVertexAttribArray(semantic::attr::POSITION);
		glBindVertexArray(0);

		return this->checkError("initVertexArray");
	}
void VertexAttributeBindingImplementation_Legacy::finish(const VertexAttributeBinding * binding) const
{
    assert(bindingData(binding) != nullptr);

    vao(binding)->bind();

    void * offset = nullptr;

    if (vbo(binding))
    {
        vbo(binding)->bind(GL_ARRAY_BUFFER);
        const auto offset64 = static_cast<GLuint64>(bindingData(binding)->baseoffset + bindingData(binding)->format.relativeoffset);
        offset = reinterpret_cast<void *>(offset64);
    }
    else
    {
        Buffer::unbind(GL_ARRAY_BUFFER);
    }

    const GLint attribute = attributeIndex(binding);

    switch (bindingData(binding)->format.method)
    {
    case Format::Method::I:
        glVertexAttribIPointer(attribute, bindingData(binding)->format.size, bindingData(binding)->format.type
            , bindingData(binding)->stride, offset);
        break;

    case Format::Method::L:
        glVertexAttribLPointer(attribute, bindingData(binding)->format.size, bindingData(binding)->format.type
            , bindingData(binding)->stride, offset);
        break;

    default:
        glVertexAttribPointer(attribute, bindingData(binding)->format.size, bindingData(binding)->format.type
            , bindingData(binding)->format.normalized, bindingData(binding)->stride, offset);
    }
}
Exemplo n.º 9
0
 // Not supported in ES
 void AddVertexLPointer(GLint index, GLint count, GLenum type, GLint stride, void * offset)
 {
     GL_CHECK(glEnableVertexAttribArray(index));
     GL_CHECK(glVertexAttribLPointer(index, count, type, stride, offset));
 }
Exemplo n.º 10
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglVertexAttribLPointerBO(JNIEnv *env, jclass clazz, jint index, jint size, jint type, jint stride, jlong pointer_buffer_offset, jlong function_pointer) {
	const GLvoid *pointer_address = (const GLvoid *)(intptr_t)offsetToPointer(pointer_buffer_offset);
	glVertexAttribLPointerPROC glVertexAttribLPointer = (glVertexAttribLPointerPROC)((intptr_t)function_pointer);
	glVertexAttribLPointer(index, size, type, stride, pointer_address);
}
Exemplo n.º 11
0
static bool
test_vertex_attribs()
{
	bool pass = true;
	GLuint data = 0;

	/* "The error INVALID_OPERATION is generated by ... , or VertexAttribPointer
	 * if <type> is UNSIGNED_INT_10F_11F_11F_REV and <size> is not 3.
	 */

	glVertexAttribPointer(0, 3, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0, (GLvoid *)0);
	TEST("VertexAttribPointer-ok", GL_NO_ERROR);

	glVertexAttribPointer(0, 2, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0, (GLvoid *)0);
	TEST("VertexAttribPointer-badsize", GL_INVALID_OPERATION);

	glVertexAttribPointer(0, GL_BGRA, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0, (GLvoid *)0);
	TEST("VertexAttribPointer-badsize-bgra", GL_INVALID_OPERATION);

	/* The error INVALID_ENUM is generated by .., VertexAttribIPointer,
	 * VertexAttribLPointer, ... if <type> is UNSIGNED_INT_10F_11F_11F_REV.
	 */

	if (piglit_get_gl_version() >= 30) {
		glVertexAttribIPointer(0, 3, GL_UNSIGNED_INT_10F_11F_11F_REV, 0, (GLvoid *)0);
		TEST("VertexAttribIPointer-not-allowed", GL_INVALID_ENUM);
	}

	if (piglit_is_extension_supported("GL_ARB_vertex_attrib_64bit")) {
		glVertexAttribLPointer(0, 3, GL_UNSIGNED_INT_10F_11F_11F_REV, 0, (GLvoid *)0);
		TEST("VertexAttribLPointer-not-allowed", GL_INVALID_ENUM);
	}

	/* The error INVALID_ENUM is generated by ... VertexAttribP4ui, VertexAttribP4uiv
	 * if <type> is UNSIGNED_INT_10F_11F_11F_REV
	 */

	glVertexAttribP4ui(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0);
	TEST("VertexAttribP4ui-not-allowed", GL_INVALID_ENUM);

	glVertexAttribP4uiv(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, &data);
	TEST("VertexAttribP4uiv-not-allowed", GL_INVALID_ENUM);

	glVertexAttribP1ui(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0);
	TEST("VertexAttribP1ui-ok", GL_NO_ERROR);

	glVertexAttribP1uiv(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, &data);
	TEST("VertexAttribP1uiv-ok", GL_NO_ERROR);

	glVertexAttribP2ui(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0);
	TEST("VertexAttribP2ui-ok", GL_NO_ERROR);

	glVertexAttribP2uiv(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, &data);
	TEST("VertexAttribP2uiv-ok", GL_NO_ERROR);

	glVertexAttribP3ui(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, 0);
	TEST("VertexAttribP3ui-ok", GL_NO_ERROR);

	glVertexAttribP3uiv(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FALSE, &data);
	TEST("VertexAttribP3uiv-ok", GL_NO_ERROR);

	/* Test that normalized = GL_TRUE doesn't spuriously produce an error */
	glVertexAttribP3uiv(0, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_TRUE, &data);
	TEST("VertexAttribP3uiv-normalized-ok", GL_NO_ERROR);

	return pass;
}
Exemplo n.º 12
0
 void GLState::glsVertexAttribLPointer(const GLuint index, const GLint size,
   const GLenum type, const GLsizei stride, const GLvoid* pointer) {
   glVertexAttribLPointer(index, size, type, stride, pointer);
   ERROR_CHECK;
 }
Exemplo n.º 13
0
Arquivo: Mesh.cpp Projeto: vdt/magnum
void Mesh::vertexAttribPointer(const LongAttribute& attribute) {
    glEnableVertexAttribArray(attribute.location);
    attribute.buffer->bind(Buffer::Target::Array);
    glVertexAttribLPointer(attribute.location, attribute.size, attribute.type, attribute.stride, reinterpret_cast<const GLvoid*>(attribute.offset));
}
Exemplo n.º 14
0
		void AttributeLPointer(VertexAttribute attrib, GLint size, GLenum type, GLsizei stride, const GLvoid * pointer){
			glVertexAttribLPointer(attrib,size,type,stride,pointer);
		}
Exemplo n.º 15
0
void GeometryBatch::setVertices(const std::shared_ptr<Buffer>& vbo, size_t count, const std::vector<VertexElement>& layout) {
	m_vbo = vbo;
	m_vertexCount = count;
	m_vao.bind();

	size_t computedStride = computeStride(layout);

	size_t previousOffset = 0;

	vbo->bind(GL_ARRAY_BUFFER);
	for (size_t i = 0; i < layout.size(); ++i) {
		auto element = layout[i];

		size_t offset = element.offset;
		// if offset is 0 then compute it
		if (i != 0 && offset == 0)
			offset = previousOffset + layout[i - 1].numComponents * elementTypeSize(layout[i - 1].type);

		previousOffset = offset;

		size_t stride = element.stride;
		if (stride == 0)
			stride = computedStride;

		glEnableVertexAttribArray(i);
		switch (element.type)
		{
		case VertexElementType::Float:
			glVertexAttribPointer(i, element.numComponents, GL_FLOAT, GL_FALSE, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		case VertexElementType::Double:
			glVertexAttribLPointer(i, element.numComponents, GL_DOUBLE, 
				stride, reinterpret_cast<const void*>(offset));
		case VertexElementType::Byte:
			glVertexAttribIPointer(i, element.numComponents, GL_BYTE, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		case VertexElementType::UnsignedByte:
			glVertexAttribIPointer(i, element.numComponents, GL_UNSIGNED_BYTE, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		case VertexElementType::Short:
			glVertexAttribIPointer(i, element.numComponents, GL_SHORT, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		case VertexElementType::UnsignedShort:
			glVertexAttribIPointer(i, element.numComponents, GL_UNSIGNED_SHORT, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		case VertexElementType::Int:
			glVertexAttribIPointer(i, element.numComponents, GL_INT, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		case VertexElementType::UsignedInt:
			glVertexAttribIPointer(i, element.numComponents, GL_UNSIGNED_INT, 
				stride, reinterpret_cast<const void*>(offset));
			break;
		}
	}
}