update vertices modernly

This commit is contained in:
Chris Sarbora 2024-08-01 04:14:35 -05:00
parent 0dd203e2c0
commit 625b2fc1a1
No known key found for this signature in database
3 changed files with 43 additions and 40 deletions

View File

@ -110,6 +110,18 @@ struct Renderer {
shader_.setUniform1i("u_texture_enable", texture_enable_); shader_.setUniform1i("u_texture_enable", texture_enable_);
} }
void setVertexData(size_t offset, size_t count, PosColorUV2Vertex const* vertices) {
shader_.setVertexData(offset, count, vertices);
}
void setVertexData(size_t offset, size_t count, PosColorUVVertex const* vertices) {
std::array<PosColorUV2Vertex, MAX_POINTS_IN_POLY> converted;
std::transform(vertices, vertices + count, converted.begin(), [](auto const& vtx) {
return PosColorUV2Vertex{vtx.pos, vtx.color, vtx.uv, {}};
});
setVertexData(offset, count, converted.data());
}
private: private:
glm::mat4x4 model_; glm::mat4x4 model_;
glm::mat4x4 view_; glm::mat4x4 view_;
@ -1319,9 +1331,7 @@ void gpu_BindTexture(int handle, int map_type, int slot) {
} }
void gpu_RenderPolygon(PosColorUVVertex *vData, uint32_t nv) { void gpu_RenderPolygon(PosColorUVVertex *vData, uint32_t nv) {
dglVertexPointer(3, GL_FLOAT, sizeof(*vData), &vData->pos); gRenderer->setVertexData(0, nv, vData);
dglColorPointer(4, GL_FLOAT, sizeof(*vData), &vData->color);
dglTexCoordPointer(4, GL_FLOAT, sizeof(*vData), &vData->uv);
if (gpu_state.cur_texture_quality == 0) { if (gpu_state.cur_texture_quality == 0) {
// force disable textures // force disable textures
@ -1343,12 +1353,8 @@ void gpu_RenderPolygon(PosColorUVVertex *vData, uint32_t nv) {
} }
void gpu_RenderPolygonUV2(PosColorUV2Vertex *vData, uint32_t nv) { void gpu_RenderPolygonUV2(PosColorUV2Vertex *vData, uint32_t nv) {
dglVertexPointer(3, GL_FLOAT, sizeof(*vData), &vData->pos);
dglColorPointer(4, GL_FLOAT, sizeof(*vData), &vData->color);
dglTexCoordPointer(4, GL_FLOAT, sizeof(*vData), &vData->uv0);
gRenderer->setTextureEnabled(1, true); gRenderer->setTextureEnabled(1, true);
dglTexCoordPointer(4, GL_FLOAT, sizeof(*vData), &vData->uv1); gRenderer->setVertexData(0, nv, vData);
dglDrawArrays(GL_POLYGON, 0, nv); dglDrawArrays(GL_POLYGON, 0, nv);
OpenGL_polys_drawn++; OpenGL_polys_drawn++;
@ -1599,11 +1605,13 @@ void rend_FillRect(ddgr_color color, int x1, int y1, int x2, int y2) {
void rend_SetPixel(ddgr_color color, int x, int y) { void rend_SetPixel(ddgr_color color, int x, int y) {
g3_RefreshTransforms(true); g3_RefreshTransforms(true);
std::array pos{x, y}; PosColorUV2Vertex vtx{
color_array unpacked_color{GR_COLOR_RED(color) / 255.0f, GR_COLOR_GREEN(color) / 255.0f, GR_COLOR_BLUE(color) / 255.0f, 1}; {static_cast<float>(x), static_cast<float>(y), 0},
{GR_COLOR_RED(color) / 255.0f, GR_COLOR_GREEN(color) / 255.0f, GR_COLOR_BLUE(color) / 255.0f, 1},
dglVertexPointer(2, GL_INT, sizeof(pos), &pos); {},
dglColorPointer(4, GL_FLOAT, sizeof(unpacked_color), &unpacked_color); {}
};
gRenderer->setVertexData(0, 1, &vtx);
dglDrawArrays(GL_POINTS, 0, 1); dglDrawArrays(GL_POINTS, 0, 1);
} }
@ -1635,21 +1643,22 @@ void rend_DrawLine(int x1, int y1, int x2, int y2) {
GR_COLOR_GREEN(gpu_state.cur_color) / 255.0f, GR_COLOR_GREEN(gpu_state.cur_color) / 255.0f,
GR_COLOR_BLUE(gpu_state.cur_color) / 255.0f, GR_COLOR_BLUE(gpu_state.cur_color) / 255.0f,
}; };
std::array<PosColorUVVertex, 2> vertices{ std::array<PosColorUV2Vertex, 2> vertices{
PosColorUVVertex{ PosColorUV2Vertex{
vector{static_cast<float>(x1 + gpu_state.clip_x1), static_cast<float>(y1 + gpu_state.clip_y1), 0}, {static_cast<float>(x1 + gpu_state.clip_x1), static_cast<float>(y1 + gpu_state.clip_y1), 0},
color, color,
tex_array{ /* unused */ } {},
{}
}, },
PosColorUVVertex{ PosColorUV2Vertex{
vector{static_cast<float>(x2 + gpu_state.clip_x1), static_cast<float>(y2 + gpu_state.clip_y1), 0}, {static_cast<float>(x2 + gpu_state.clip_x1), static_cast<float>(y2 + gpu_state.clip_y1), 0},
color, color,
tex_array{ /* unused */ } {},
{}
} }
}; };
dglVertexPointer(3, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].pos); gRenderer->setVertexData(0, vertices.size(), vertices.data());
dglColorPointer(4, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].color);
dglDrawArrays(GL_LINES, 0, vertices.size()); dglDrawArrays(GL_LINES, 0, vertices.size());
rend_SetAlphaType(atype); rend_SetAlphaType(atype);
@ -1733,18 +1742,17 @@ void rend_SetAlphaType(int8_t atype) {
void rend_DrawSpecialLine(g3Point *p0, g3Point *p1) { void rend_DrawSpecialLine(g3Point *p0, g3Point *p1) {
g3_RefreshTransforms(true); g3_RefreshTransforms(true);
std::array<g3Point const*, 2> pts{p0, p1}; std::array<g3Point const *, 2> pts{p0, p1};
std::array<PosColorUVVertex, 2> vertices{}; std::array<PosColorUV2Vertex, 2> vertices{};
std::transform(pts.begin(), pts.end(), vertices.begin(), [](auto pnt) { std::transform(pts.begin(), pts.end(), vertices.begin(), [](auto pnt) {
return PosColorUVVertex{ return PosColorUV2Vertex{{pnt->p3_sx + gpu_state.clip_x1, pnt->p3_sy + gpu_state.clip_y1,
{pnt->p3_sx + gpu_state.clip_x1, pnt->p3_sy + gpu_state.clip_y1, -std::clamp(1.0f - (1.0f / (pnt->p3_z + Z_bias)), 0.0f, 1.0f)}, -std::clamp(1.0f - (1.0f / (pnt->p3_z + Z_bias)), 0.0f, 1.0f)},
DeterminePointColor(pnt, false, false, true), // extras?? DeterminePointColor(pnt, false, false, true), // extras??
tex_array{ /* unused */ } {},
}; {}};
}); });
dglVertexPointer(3, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].pos); gRenderer->setVertexData(0, vertices.size(), vertices.data());
dglColorPointer(4, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].color);
dglDrawArrays(GL_LINES, 0, vertices.size()); dglDrawArrays(GL_LINES, 0, vertices.size());
} }

View File

@ -170,6 +170,10 @@ struct ShaderProgram {
dglUseProgram(0); dglUseProgram(0);
} }
void setVertexData(size_t offset, size_t count, PosColorUV2Vertex const* vertices) {
vbo_.UpdateData(offset, count, vertices);
}
void setUniformMat4f(std::string const& name, glm::mat4x4 const& matrix) { void setUniformMat4f(std::string const& name, glm::mat4x4 const& matrix) {
dglUniformMatrix4fv(getUniformId(name), 1, GL_FALSE, glm::value_ptr(matrix)); dglUniformMatrix4fv(getUniformId(name), 1, GL_FALSE, glm::value_ptr(matrix));
} }

View File

@ -141,10 +141,6 @@ DYNAEXTERN(glBufferData);
DYNAEXTERN(glBufferSubData); DYNAEXTERN(glBufferSubData);
DYNAEXTERN(glClear); DYNAEXTERN(glClear);
DYNAEXTERN(glClearColor); DYNAEXTERN(glClearColor);
DYNAEXTERN(glColor3ub);
DYNAEXTERN(glColor4f);
DYNAEXTERN(glColor4ub);
DYNAEXTERN(glColorPointer);
DYNAEXTERN(glCompileShader); DYNAEXTERN(glCompileShader);
DYNAEXTERN(glCreateProgram); DYNAEXTERN(glCreateProgram);
DYNAEXTERN(glCreateShader); DYNAEXTERN(glCreateShader);
@ -155,7 +151,6 @@ DYNAEXTERN(glDeleteTextures);
DYNAEXTERN(glDeleteVertexArrays); DYNAEXTERN(glDeleteVertexArrays);
DYNAEXTERN(glDepthFunc); DYNAEXTERN(glDepthFunc);
DYNAEXTERN(glDepthMask); DYNAEXTERN(glDepthMask);
DYNAEXTERN(glDepthRange);
DYNAEXTERN(glDisable); DYNAEXTERN(glDisable);
DYNAEXTERN(glDrawArrays); DYNAEXTERN(glDrawArrays);
DYNAEXTERN(glEnable); DYNAEXTERN(glEnable);
@ -183,9 +178,6 @@ DYNAEXTERN(glPolygonOffset);
DYNAEXTERN(glReadPixels); DYNAEXTERN(glReadPixels);
DYNAEXTERN(glScissor); DYNAEXTERN(glScissor);
DYNAEXTERN(glShaderSource); DYNAEXTERN(glShaderSource);
DYNAEXTERN(glTexCoord2f);
DYNAEXTERN(glTexCoord4fv);
DYNAEXTERN(glTexCoordPointer);
DYNAEXTERN(glTexImage2D); DYNAEXTERN(glTexImage2D);
DYNAEXTERN(glTexParameteri); DYNAEXTERN(glTexParameteri);
DYNAEXTERN(glTexSubImage2D); DYNAEXTERN(glTexSubImage2D);
@ -193,7 +185,6 @@ DYNAEXTERN(glUniform1i);
DYNAEXTERN(glUniformMatrix4fv); DYNAEXTERN(glUniformMatrix4fv);
DYNAEXTERN(glUseProgram); DYNAEXTERN(glUseProgram);
DYNAEXTERN(glVertexAttribPointer); DYNAEXTERN(glVertexAttribPointer);
DYNAEXTERN(glVertexPointer);
DYNAEXTERN(glViewport); DYNAEXTERN(glViewport);
// FBO entry points for render-to-texture ... // FBO entry points for render-to-texture ...