glNamedBufferStorage issue

Started by xenoliss, August 03, 2018, 20:06:45

Previous topic - Next topic

xenoliss

Hi,

I recently bought the OpenGL Programming Guide and i'm currently trying to replace my old :
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);


by :
glNamedBufferStorage(vboID, data, GL_STATIC_DRAW);
as shown in this book.

But whenever I try i get this error message :

[LWJGL] OpenGL debug message
         ID: 0x501
         Source: API
         Type: ERROR
         Severity: HIGH
         Message: GL_INVALID_VALUE error generated. <flags> has unknown bits set

Strangely enough it works with glBufferData().
I paste the code below so you can have a look :

package globalComponents;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.opengl.GL43.*;
import static org.lwjgl.opengl.GL45.*;

import java.util.ArrayList;
import java.util.List;

public abstract class VaoLoadingComponent implements IVaoLoadingComponent {

	protected int vaoID;
	protected int verticesCount;
	
	protected int primitiveDraw;
	
	protected int bufferVertexSize;
	protected float[] data;
	
	private List<Integer> vbos;
	
	public VaoLoadingComponent(int primitiveDraw, float[] data, int dataVertexSize) {
		
		vbos = new ArrayList<Integer>();
		
		this.primitiveDraw = primitiveDraw;
		this.data = data;
		this.bufferVertexSize = dataVertexSize;
	}

	@Override
	public int getVao() {
		return vaoID;
	}
	
	@Override
	public int getVertexCount() {
		return verticesCount;
	}

	@Override
	public float[] getData() {
		return data;
	}

	@Override
	public int getBufferVertexSize() {
		return bufferVertexSize;
	}
	
	@Override
	public void cleanUp() {
		
		for(int vbo : vbos) {
			glDeleteBuffers(vbo);
		}
		
		glDeleteVertexArrays(vaoID);
	}
	
	public void createVertexArray() {
		vaoID = glCreateVertexArrays();
	}
	
	public void bindVertexArray(int target) {
		glBindVertexArray(target);
	}
	
	public void setUpBuffer(float[] data, int bufferVertexSize, int bufferIndexBinding) {
		int vboID = glCreateBuffers();
		vbos.add(vboID);
		
		// HERE IT DOESNT WORK BUT glNamedBufferData(vboID, data, GL_STATIC_DRAW) works...
//		glNamedBufferStorage(vboID, data, GL_STATIC_DRAW);
		
		// Old code to replace
		glBindBuffer(GL_ARRAY_BUFFER, vboID);
		glBufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		
		glBindVertexBuffer(bufferIndexBinding, vboID, 0, bufferVertexSize * 4);
	}
	
	public void setUpVertexAttrib(int attribIndex, int bufferIndexBinding, int vertexAttribsize, int offset) {
		glEnableVertexAttribArray(attribIndex);
		glVertexAttribFormat(attribIndex, vertexAttribsize, GL_FLOAT, false, offset * 4);
		glVertexAttribBinding(attribIndex, bufferIndexBinding);
	}
	
	protected void setVertexCount() {
		this.verticesCount = getVertexCount();
	}

}


Thank you very much for your help and feel free to redirect me if my post isn't in the good category (and sorry for my bad english).

xenoliss

Ups, my bad. I juste realized I was not using the good flag in glNamedBufferStorage() function...  ::)
By the way, I'm a bit confuse about the different flags we could use here. Wich one should I use to replace a "STATIC_DRAW" flag ?

KaiHH

Read:
- https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferStorage.xhtml
- http://developer.download.nvidia.com/opengl/specs/GL_ARB_buffer_storage.txt
- https://computergraphics.stackexchange.com/questions/5550/how-to-set-flags-and-usage-glnamedbufferstorage-in-new-opengl-4-4-gl-static-dr

If you only ever initialize the buffer data once with the call to glBufferStorage/glNamedBufferStorage then you can use flags = 0. There is no real equivalent for glBufferData's usage flag, since you could do anything with the buffer afterwards anyway, such as mapping into client memory, reading from it and writing to it. This is not possible anymore with glBufferStorage, since there you have to explicitly state what you are going to do with the buffer. With flags = 0 you say: "I will never ever again touch the buffer data and only let the OpenGL server (i.e. the graphics card) read from it."

xenoliss

Hi,

Tanks for your answer, I'm gonna have a look at the links.  :D