Have Draw and DrawIndexed share command and struct. Will make the next change easier.

This commit is contained in:
Henrik Rydgård 2023-05-10 10:40:07 +02:00
parent d5e0299b0b
commit c7caefe6d8
4 changed files with 15 additions and 15 deletions

View file

@ -1187,20 +1187,21 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
CHECK_GL_ERROR_IF_DEBUG(); CHECK_GL_ERROR_IF_DEBUG();
break; break;
} }
case GLRRenderCommand::GENMIPS:
// TODO: Should we include the texture handle in the command?
// Also, should this not be an init command?
glGenerateMipmap(GL_TEXTURE_2D);
break;
case GLRRenderCommand::DRAW: case GLRRenderCommand::DRAW:
if (c.draw.indexType == 0) {
glDrawArrays(c.draw.mode, c.draw.first, c.draw.count); glDrawArrays(c.draw.mode, c.draw.first, c.draw.count);
break; } else if (c.draw.instances == 1) {
case GLRRenderCommand::DRAW_INDEXED:
if (c.draw.instances == 1) {
glDrawElements(c.draw.mode, c.draw.count, c.draw.indexType, c.draw.indices); glDrawElements(c.draw.mode, c.draw.count, c.draw.indexType, c.draw.indices);
} else { } else {
glDrawElementsInstanced(c.draw.mode, c.draw.count, c.draw.indexType, c.draw.indices, c.draw.instances); glDrawElementsInstanced(c.draw.mode, c.draw.count, c.draw.indexType, c.draw.indices, c.draw.instances);
} }
CHECK_GL_ERROR_IF_DEBUG();
break;
case GLRRenderCommand::GENMIPS:
// TODO: Should we include the texture handle in the command?
// Also, should this not be an init command?
glGenerateMipmap(GL_TEXTURE_2D);
CHECK_GL_ERROR_IF_DEBUG();
break; break;
case GLRRenderCommand::TEXTURESAMPLER: case GLRRenderCommand::TEXTURESAMPLER:
{ {

View file

@ -63,7 +63,6 @@ enum class GLRRenderCommand : uint8_t {
BIND_VERTEX_BUFFER, BIND_VERTEX_BUFFER,
GENMIPS, GENMIPS,
DRAW, DRAW,
DRAW_INDEXED,
TEXTURE_SUBIMAGE, TEXTURE_SUBIMAGE,
}; };
@ -111,9 +110,9 @@ struct GLRRenderData {
GLenum mode; // primitive GLenum mode; // primitive
GLint first; GLint first;
GLint count; GLint count;
GLint indexType;
void *indices; void *indices;
GLint instances; GLint instances;
GLint indexType;
} draw; } draw;
struct { struct {
const char *name; // if null, use loc const char *name; // if null, use loc

View file

@ -923,18 +923,18 @@ public:
data.draw.mode = mode; data.draw.mode = mode;
data.draw.first = first; data.draw.first = first;
data.draw.count = count; data.draw.count = count;
data.draw.indices = nullptr; data.draw.indexType = 0;
curRenderStep_->commands.push_back(data); curRenderStep_->commands.push_back(data);
curRenderStep_->render.numDraws++; curRenderStep_->render.numDraws++;
} }
void DrawIndexed(GLenum mode, int count, GLenum indexType, void *indices, int instances = 1) { void DrawIndexed(GLenum mode, int count, GLenum indexType, void *indices, int instances = 1) {
_dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
GLRRenderData data{ GLRRenderCommand::DRAW_INDEXED }; GLRRenderData data{ GLRRenderCommand::DRAW };
data.draw.mode = mode; data.draw.mode = mode;
data.draw.count = count; data.draw.count = count;
data.draw.indices = indices;
data.draw.indexType = indexType; data.draw.indexType = indexType;
data.draw.indices = indices;
data.draw.instances = instances; data.draw.instances = instances;
curRenderStep_->commands.push_back(data); curRenderStep_->commands.push_back(data);
curRenderStep_->render.numDraws++; curRenderStep_->render.numDraws++;

View file

@ -574,7 +574,7 @@ void PreprocessSkyplane(GLRStep* step) {
for (auto& command : step->commands) { for (auto& command : step->commands) {
if (command.cmd == GLRRenderCommand::DEPTH) { if (command.cmd == GLRRenderCommand::DEPTH) {
depthEnabled = command.depth.enabled; depthEnabled = command.depth.enabled;
} else if ((command.cmd == GLRRenderCommand::DRAW_INDEXED) && !depthEnabled) { } else if ((command.cmd == GLRRenderCommand::DRAW && command.draw.indices != nullptr) && !depthEnabled) {
command.draw.count = 0; command.draw.count = 0;
} }
} }