diff --git a/renderer/HardwareOpenGL.cpp b/renderer/HardwareOpenGL.cpp index b9f76ff6..a77a36b3 100644 --- a/renderer/HardwareOpenGL.cpp +++ b/renderer/HardwareOpenGL.cpp @@ -110,6 +110,18 @@ struct Renderer { 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 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: glm::mat4x4 model_; 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) { - dglVertexPointer(3, GL_FLOAT, sizeof(*vData), &vData->pos); - dglColorPointer(4, GL_FLOAT, sizeof(*vData), &vData->color); - dglTexCoordPointer(4, GL_FLOAT, sizeof(*vData), &vData->uv); + gRenderer->setVertexData(0, nv, vData); if (gpu_state.cur_texture_quality == 0) { // force disable textures @@ -1343,12 +1353,8 @@ void gpu_RenderPolygon(PosColorUVVertex *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); - dglTexCoordPointer(4, GL_FLOAT, sizeof(*vData), &vData->uv1); + gRenderer->setVertexData(0, nv, vData); dglDrawArrays(GL_POLYGON, 0, nv); 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) { g3_RefreshTransforms(true); - std::array pos{x, y}; - color_array unpacked_color{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); + PosColorUV2Vertex vtx{ + {static_cast(x), static_cast(y), 0}, + {GR_COLOR_RED(color) / 255.0f, GR_COLOR_GREEN(color) / 255.0f, GR_COLOR_BLUE(color) / 255.0f, 1}, + {}, + {} + }; + gRenderer->setVertexData(0, 1, &vtx); 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_BLUE(gpu_state.cur_color) / 255.0f, }; - std::array vertices{ - PosColorUVVertex{ - vector{static_cast(x1 + gpu_state.clip_x1), static_cast(y1 + gpu_state.clip_y1), 0}, + std::array vertices{ + PosColorUV2Vertex{ + {static_cast(x1 + gpu_state.clip_x1), static_cast(y1 + gpu_state.clip_y1), 0}, color, - tex_array{ /* unused */ } + {}, + {} }, - PosColorUVVertex{ - vector{static_cast(x2 + gpu_state.clip_x1), static_cast(y2 + gpu_state.clip_y1), 0}, + PosColorUV2Vertex{ + {static_cast(x2 + gpu_state.clip_x1), static_cast(y2 + gpu_state.clip_y1), 0}, color, - tex_array{ /* unused */ } + {}, + {} } }; - dglVertexPointer(3, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].pos); - dglColorPointer(4, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].color); + gRenderer->setVertexData(0, vertices.size(), vertices.data()); dglDrawArrays(GL_LINES, 0, vertices.size()); rend_SetAlphaType(atype); @@ -1733,18 +1742,17 @@ void rend_SetAlphaType(int8_t atype) { void rend_DrawSpecialLine(g3Point *p0, g3Point *p1) { g3_RefreshTransforms(true); - std::array pts{p0, p1}; - std::array vertices{}; + std::array pts{p0, p1}; + std::array vertices{}; std::transform(pts.begin(), pts.end(), vertices.begin(), [](auto pnt) { - return PosColorUVVertex{ - {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)}, - DeterminePointColor(pnt, false, false, true), // extras?? - tex_array{ /* unused */ } - }; + return PosColorUV2Vertex{{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)}, + DeterminePointColor(pnt, false, false, true), // extras?? + {}, + {}}; }); - dglVertexPointer(3, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].pos); - dglColorPointer(4, GL_FLOAT, sizeof(PosColorUVVertex), &vertices[0].color); + gRenderer->setVertexData(0, vertices.size(), vertices.data()); dglDrawArrays(GL_LINES, 0, vertices.size()); } diff --git a/renderer/ShaderProgram.h b/renderer/ShaderProgram.h index c5831cd7..3746aa17 100644 --- a/renderer/ShaderProgram.h +++ b/renderer/ShaderProgram.h @@ -170,6 +170,10 @@ struct ShaderProgram { 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) { dglUniformMatrix4fv(getUniformId(name), 1, GL_FALSE, glm::value_ptr(matrix)); } diff --git a/renderer/dyna_gl.h b/renderer/dyna_gl.h index 6b7fd47c..f79118c9 100644 --- a/renderer/dyna_gl.h +++ b/renderer/dyna_gl.h @@ -141,10 +141,6 @@ DYNAEXTERN(glBufferData); DYNAEXTERN(glBufferSubData); DYNAEXTERN(glClear); DYNAEXTERN(glClearColor); -DYNAEXTERN(glColor3ub); -DYNAEXTERN(glColor4f); -DYNAEXTERN(glColor4ub); -DYNAEXTERN(glColorPointer); DYNAEXTERN(glCompileShader); DYNAEXTERN(glCreateProgram); DYNAEXTERN(glCreateShader); @@ -155,7 +151,6 @@ DYNAEXTERN(glDeleteTextures); DYNAEXTERN(glDeleteVertexArrays); DYNAEXTERN(glDepthFunc); DYNAEXTERN(glDepthMask); -DYNAEXTERN(glDepthRange); DYNAEXTERN(glDisable); DYNAEXTERN(glDrawArrays); DYNAEXTERN(glEnable); @@ -183,9 +178,6 @@ DYNAEXTERN(glPolygonOffset); DYNAEXTERN(glReadPixels); DYNAEXTERN(glScissor); DYNAEXTERN(glShaderSource); -DYNAEXTERN(glTexCoord2f); -DYNAEXTERN(glTexCoord4fv); -DYNAEXTERN(glTexCoordPointer); DYNAEXTERN(glTexImage2D); DYNAEXTERN(glTexParameteri); DYNAEXTERN(glTexSubImage2D); @@ -193,7 +185,6 @@ DYNAEXTERN(glUniform1i); DYNAEXTERN(glUniformMatrix4fv); DYNAEXTERN(glUseProgram); DYNAEXTERN(glVertexAttribPointer); -DYNAEXTERN(glVertexPointer); DYNAEXTERN(glViewport); // FBO entry points for render-to-texture ...