Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element array buffer support #15

Open
medilies opened this issue Aug 14, 2023 · 4 comments
Open

Element array buffer support #15

medilies opened this issue Aug 14, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@medilies
Copy link

Hi, can I currently use GL_ELEMENT_ARRAY_BUFFER and glDrawElements? because I tried some hours ago and got an error (I do not remember its detail but I'll reproduce it if needed)

If not, are there any plans to add support?

@mario-deluna
Copy link
Owner

Hey @medilies, element drawing is currently not supported. I haven't prioritized element drawing yet, as its benefits truly shine in larger scenes with highly complex geometry.

The obj. file loader included with php-glfw produces non-indexed vertex arrays.
I plan to support element drawing in the future, as I aim to cover the entirety of the OpenGL API. But for now almost everything should be solvable with normal vertex arrays.

Does your use case greatly benefit from indexed vertices? Are you implementing skinning or something similar?

@medilies
Copy link
Author

Nah, I'm too noob to play with skinning and similar things. I'm still tinkering with the included examples and trying to make a pong game.

I just didn't like how verbose it is to write a vertex buffer without indexing. And I also noticed that the instancing example was consuming 100% of my GPU.

@mario-deluna
Copy link
Owner

mario-deluna commented Aug 14, 2023

The instancing example renders 125,000 cubes, so it requires a significant amount of GPU power. Additionally, there's considerable overdraw in the example. You can view it as a simple benchmark ;)

In VISU there is a simple abstraction around vertex arrays/buffers, which reduces some of the verbosity. Here's an example of instanced rendering of several planes to render images, sprites, rectangles, etc.

$vertexLayout = [
    2, // position
    2, // tex coords
];

$instanceLayout = [
    4, // mat4x0
    4, // mat4x1
    4, // mat4x2
    4, // mat4x3
];

$vertexArray = new BasicInstancedVertexArray($gl, $vertexLayout, $instanceLayout);
$vertexArray->uploadVertexData(new FloatBuffer([
    // vertex positions
    // this makes up the quad
    // position  // tex coords
    -1.0, -1.0,  0.0, -1.0,
     1.0, -1.0,  1.0, -1.0,
    -1.0,  1.0,  0.0,  0.0,
     1.0,  1.0,  1.0,  0.0,
]));

Then to render:

// allocate a buffer to hold all instance matrices
$buffer = new FloatBuffer();

// create a transform for item A
$itemA = new Transform();
$itemA->position->x = 20;

// and B..
$itemB = new Transform();
$itemB->position->x = 40;

// push the matrices into our buffer
$buffer->pushMat4($transform->getLocalMatrix());
$buffer->pushMat4($transform->getLocalMatrix());

// upload the buffer and draw the vertex array in TRAINGLE_STRIP mode.
$this->vertexArray->uploadInstanceData($buffer);
$this->vertexArray->drawAll(GL_TRIANGLE_STRIP);

@medilies
Copy link
Author

medilies commented Aug 15, 2023

Thank you for the tip 🙇🏼, I'll keep a note to try it when I use VISU.

Edit: I think I shouldn't keep this to myself, but I find it a little bit hard to understand the VISU folder structure and dev flow, and I couldn't find any doc.

Edit 2: Maybe I find it hard because I'm alien to game dev jargon (scene, node, signals ...)

@mario-deluna mario-deluna added the enhancement New feature or request label Sep 7, 2023
@mario-deluna mario-deluna self-assigned this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants