mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 13:01:28 +01:00
feat: switch to rendering grid with EBO
This commit is contained in:
parent
dbb4488c75
commit
af189dc9b0
108
src/main.cpp
108
src/main.cpp
@ -30,8 +30,8 @@ SShader* g_shader {};
|
||||
constexpr unsigned int g_SUBDIVS = 2;
|
||||
static_assert(g_SUBDIVS > 0);
|
||||
|
||||
GLuint g_VAO, g_VBO, g_VBO_UVs;
|
||||
unsigned int g_vertCount = 0;
|
||||
GLuint g_VAO, g_VBO, g_VBO_UVs, g_EBO;
|
||||
unsigned int g_indexCount = 0;
|
||||
|
||||
class CBindOwnFramebufferPassElement final: public IPassElement {
|
||||
public:
|
||||
@ -125,20 +125,8 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, g_VBO_UVs);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, UVs.size(), UVs.data());
|
||||
|
||||
GLCALL(glDisable(GL_CULL_FACE));
|
||||
GLCALL(glDrawArrays(GL_TRIANGLES, 0, g_vertCount));
|
||||
|
||||
int nBufferSize = 0;
|
||||
glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &nBufferSize);
|
||||
int originalVertexArraySize = (nBufferSize / sizeof(float));
|
||||
std::println(
|
||||
"Drew {} verts, from VBO that has {} floats",
|
||||
g_vertCount,
|
||||
originalVertexArraySize
|
||||
);
|
||||
|
||||
// GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_EBO));
|
||||
// GLCALL(glDrawElements(GL_TRIANGLE_STRIP, g_indicesCount, GL_UNSIGNED_INT, 0));
|
||||
GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_EBO));
|
||||
GLCALL(glDrawElements(GL_TRIANGLE_STRIP, g_indexCount, GL_UNSIGNED_INT, 0));
|
||||
|
||||
GLCALL(glBindVertexArray(0));
|
||||
pWindowFB->getTexture()->unbind();
|
||||
@ -252,78 +240,56 @@ void hkRenderWindow(
|
||||
void initGPUObjects() {
|
||||
g_shader = &g_pHyprOpenGL->m_shaders->m_shRGBA;
|
||||
|
||||
std::vector<float> finalVerts;
|
||||
{
|
||||
const unsigned int vertsPerRow = g_SUBDIVS + 1;
|
||||
std::vector<float> verts;
|
||||
verts.reserve(vertsPerRow * vertsPerRow * 2);
|
||||
// std::vector<float> finalVerts;
|
||||
const unsigned int vertsPerRow = g_SUBDIVS + 1;
|
||||
std::vector<float> verts;
|
||||
verts.reserve(vertsPerRow * vertsPerRow * 2);
|
||||
|
||||
const float step = 1.f / (g_SUBDIVS);
|
||||
for (unsigned int y = 0; y < vertsPerRow; ++y) {
|
||||
for (unsigned int x = 0; x < vertsPerRow; ++x) {
|
||||
verts.push_back(x * step);
|
||||
verts.push_back(y * step);
|
||||
}
|
||||
const float step = 1.f / (g_SUBDIVS);
|
||||
for (unsigned int y = 0; y < vertsPerRow; ++y) {
|
||||
for (unsigned int x = 0; x < vertsPerRow; ++x) {
|
||||
verts.push_back(x * step);
|
||||
verts.push_back(y * step);
|
||||
}
|
||||
}
|
||||
|
||||
verts[4 * 2] = 0.7f;
|
||||
std::vector<GLuint> indices;
|
||||
g_indexCount = 3 * 2 * g_SUBDIVS * g_SUBDIVS;
|
||||
indices.reserve(g_indexCount);
|
||||
|
||||
for (unsigned int i = 0; i < verts.size(); i += 2) {
|
||||
std::println("Created vert ({}, {})", verts[i], verts[i + 1]);
|
||||
}
|
||||
for (int y = 0; y < g_SUBDIVS; ++y) {
|
||||
for (int x = 0; x < g_SUBDIVS; ++x) {
|
||||
indices.push_back(y * vertsPerRow + x + 1); // top right
|
||||
indices.push_back(y * vertsPerRow + x); // top left
|
||||
indices.push_back((y + 1) * vertsPerRow + x + 1); // bottom right
|
||||
|
||||
std::vector<unsigned int> indices;
|
||||
g_vertCount = 3 * 2 * g_SUBDIVS * g_SUBDIVS;
|
||||
indices.reserve(g_vertCount);
|
||||
|
||||
for (int y = 0; y < g_SUBDIVS; ++y) {
|
||||
for (int x = 0; x < g_SUBDIVS; ++x) {
|
||||
indices.push_back(y * vertsPerRow + x + 1); // top right
|
||||
indices.push_back(y * vertsPerRow + x); // top left
|
||||
indices.push_back((y + 1) * vertsPerRow + x + 1); // bottom right
|
||||
|
||||
indices.push_back(y * vertsPerRow + x); // top left
|
||||
indices.push_back((y + 1) * vertsPerRow + x); // bottom left
|
||||
indices.push_back((y + 1) * vertsPerRow + x + 1); // bottom right
|
||||
}
|
||||
}
|
||||
|
||||
finalVerts.reserve(g_vertCount);
|
||||
for (auto&& index : indices) {
|
||||
finalVerts.push_back(verts[index * 2]);
|
||||
finalVerts.push_back(verts[index * 2 + 1]);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < finalVerts.size(); i += 6) {
|
||||
std::println(
|
||||
"Created tri <({}, {}), ({}, {}), ({}, {})>",
|
||||
finalVerts[i],
|
||||
finalVerts[i + 1],
|
||||
finalVerts[i + 2],
|
||||
finalVerts[i + 3],
|
||||
finalVerts[i + 4],
|
||||
finalVerts[i + 5]
|
||||
);
|
||||
indices.push_back(y * vertsPerRow + x); // top left
|
||||
indices.push_back((y + 1) * vertsPerRow + x); // bottom left
|
||||
indices.push_back((y + 1) * vertsPerRow + x + 1); // bottom right
|
||||
}
|
||||
}
|
||||
|
||||
GLCALL(glGenVertexArrays(1, &g_VAO));
|
||||
GLCALL(glGenBuffers(1, &g_VBO));
|
||||
GLCALL(glGenBuffers(1, &g_VBO_UVs));
|
||||
// GLCALL(glGenBuffers(1, &g_EBO));
|
||||
GLCALL(glGenBuffers(1, &g_EBO));
|
||||
|
||||
GLCALL(glBindVertexArray(g_VAO));
|
||||
|
||||
// GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_EBO));
|
||||
// GLCALL(glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size(), indices.data(), GL_STATIC_DRAW));
|
||||
GLCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_EBO));
|
||||
GLCALL(glBufferData(
|
||||
GL_ELEMENT_ARRAY_BUFFER,
|
||||
indices.size() * sizeof(GLuint),
|
||||
indices.data(),
|
||||
GL_STATIC_DRAW
|
||||
));
|
||||
|
||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, g_VBO));
|
||||
{
|
||||
std::println("Number of vertices in VBO: {}/2", finalVerts.size());
|
||||
GLCALL(glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
finalVerts.size() * sizeof(float),
|
||||
finalVerts.data(),
|
||||
verts.size() * sizeof(float),
|
||||
verts.data(),
|
||||
GL_DYNAMIC_DRAW
|
||||
));
|
||||
|
||||
@ -342,8 +308,8 @@ void initGPUObjects() {
|
||||
{
|
||||
GLCALL(glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
finalVerts.size() * sizeof(float),
|
||||
finalVerts.data(),
|
||||
verts.size() * sizeof(float),
|
||||
verts.data(),
|
||||
GL_DYNAMIC_DRAW
|
||||
)); // Initial dummy UVs
|
||||
GLCALL(glEnableVertexAttribArray(g_shader->uniformLocations[SHADER_TEX_ATTRIB]));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user