diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index 902475567c..fcf0bfe7a5 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -446,11 +446,11 @@ public: } void FinalizeTexture(GLRTexture *texture, int loadedLevels, bool genMips) { - GLRInitStep step(GLRInitStepType::TEXTURE_FINALIZE); + GLRInitStep &step = initSteps_.push_uninitialized(); + step.stepType = GLRInitStepType::TEXTURE_FINALIZE; step.texture_finalize.texture = texture; step.texture_finalize.loadedLevels = loadedLevels; step.texture_finalize.genMips = genMips; - initSteps_.push_back(step); } void BindTexture(int slot, GLRTexture *tex) { @@ -461,18 +461,18 @@ public: } _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); _dbg_assert_(slot < MAX_GL_TEXTURE_SLOTS); - GLRRenderData data(GLRRenderCommand::BINDTEXTURE); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::BINDTEXTURE; data.texture.slot = slot; data.texture.texture = tex; - curRenderStep_->commands.push_back(data); } void BindProgram(GLRProgram *program) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::BINDPROGRAM); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::BINDPROGRAM; _dbg_assert_(program != nullptr); data.program.program = program; - curRenderStep_->commands.push_back(data); #ifdef _DEBUG curProgram_ = program; #endif @@ -480,25 +480,25 @@ public: void SetDepth(bool enabled, bool write, GLenum func) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::DEPTH); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::DEPTH; data.depth.enabled = enabled; data.depth.write = write; data.depth.func = func; - curRenderStep_->commands.push_back(data); } void SetViewport(const GLRViewport &vp) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::VIEWPORT); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::VIEWPORT; data.viewport.vp = vp; - curRenderStep_->commands.push_back(data); } void SetScissor(const GLRect2D &rc) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::SCISSOR); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::SCISSOR; data.scissor.rc = rc; - curRenderStep_->commands.push_back(data); } void SetUniformI(const GLint *loc, int count, const int *udata) { @@ -506,12 +506,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4I); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4I; data.uniform4.name = nullptr; data.uniform4.loc = loc; data.uniform4.count = count; memcpy(data.uniform4.v, udata, sizeof(int) * count); - curRenderStep_->commands.push_back(data); } void SetUniformI1(const GLint *loc, int udata) { @@ -519,12 +519,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4I); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4I; data.uniform4.name = nullptr; data.uniform4.loc = loc; data.uniform4.count = 1; memcpy(data.uniform4.v, &udata, sizeof(udata)); - curRenderStep_->commands.push_back(data); } void SetUniformUI(const GLint *loc, int count, const uint32_t *udata) { @@ -532,12 +532,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4UI); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4UI; data.uniform4.name = nullptr; data.uniform4.loc = loc; data.uniform4.count = count; memcpy(data.uniform4.v, udata, sizeof(uint32_t) * count); - curRenderStep_->commands.push_back(data); } void SetUniformUI1(const GLint *loc, uint32_t udata) { @@ -545,12 +545,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4UI); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4UI; data.uniform4.name = nullptr; data.uniform4.loc = loc; data.uniform4.count = 1; memcpy(data.uniform4.v, &udata, sizeof(udata)); - curRenderStep_->commands.push_back(data); } void SetUniformF(const GLint *loc, int count, const float *udata) { @@ -558,12 +558,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4F); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4F; data.uniform4.name = nullptr; data.uniform4.loc = loc; data.uniform4.count = count; memcpy(data.uniform4.v, udata, sizeof(float) * count); - curRenderStep_->commands.push_back(data); } void SetUniformF1(const GLint *loc, const float udata) { @@ -571,12 +571,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4F); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4F; data.uniform4.name = nullptr; data.uniform4.loc = loc; data.uniform4.count = 1; memcpy(data.uniform4.v, &udata, sizeof(float)); - curRenderStep_->commands.push_back(data); } void SetUniformF(const char *name, int count, const float *udata) { @@ -584,12 +584,12 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORM4F); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORM4F; data.uniform4.name = name; data.uniform4.loc = nullptr; data.uniform4.count = count; memcpy(data.uniform4.v, udata, sizeof(float) * count); - curRenderStep_->commands.push_back(data); } void SetUniformM4x4(const GLint *loc, const float *udata) { @@ -597,11 +597,11 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORMMATRIX); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORMMATRIX; data.uniformMatrix4.name = nullptr; data.uniformMatrix4.loc = loc; memcpy(data.uniformMatrix4.m, udata, sizeof(float) * 16); - curRenderStep_->commands.push_back(data); } void SetUniformM4x4Stereo(const char *name, const GLint *loc, const float *left, const float *right) { @@ -609,13 +609,13 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORMSTEREOMATRIX); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORMSTEREOMATRIX; data.uniformStereoMatrix4.name = name; data.uniformStereoMatrix4.loc = loc; data.uniformStereoMatrix4.mData = new float[32]; memcpy(&data.uniformStereoMatrix4.mData[0], left, sizeof(float) * 16); memcpy(&data.uniformStereoMatrix4.mData[16], right, sizeof(float) * 16); - curRenderStep_->commands.push_back(data); } void SetUniformM4x4(const char *name, const float *udata) { @@ -623,18 +623,19 @@ public: #ifdef _DEBUG _dbg_assert_(curProgram_); #endif - GLRRenderData data(GLRRenderCommand::UNIFORMMATRIX); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::UNIFORMMATRIX; data.uniformMatrix4.name = name; data.uniformMatrix4.loc = nullptr; memcpy(data.uniformMatrix4.m, udata, sizeof(float) * 16); - curRenderStep_->commands.push_back(data); } void SetBlendAndMask(int colorMask, bool blendEnabled, GLenum srcColor, GLenum dstColor, GLenum srcAlpha, GLenum dstAlpha, GLenum funcColor, GLenum funcAlpha) { // Make this one only a non-debug _assert_, since it often comes first. // Lets us collect info about this potential crash through assert extra data. _assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::BLEND); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::BLEND; data.blend.mask = colorMask; data.blend.enabled = blendEnabled; data.blend.srcColor = srcColor; @@ -643,96 +644,95 @@ public: data.blend.dstAlpha = dstAlpha; data.blend.funcColor = funcColor; data.blend.funcAlpha = funcAlpha; - curRenderStep_->commands.push_back(data); } void SetNoBlendAndMask(int colorMask) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::BLEND); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::BLEND; data.blend.mask = colorMask; data.blend.enabled = false; - curRenderStep_->commands.push_back(data); } #ifndef USING_GLES2 void SetLogicOp(bool enabled, GLenum logicOp) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::LOGICOP); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::LOGICOP; data.logic.enabled = enabled; data.logic.logicOp = logicOp; - curRenderStep_->commands.push_back(data); } #endif void SetStencilFunc(bool enabled, GLenum func, uint8_t refValue, uint8_t compareMask) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::STENCILFUNC); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::STENCILFUNC; data.stencilFunc.enabled = enabled; data.stencilFunc.func = func; data.stencilFunc.ref = refValue; data.stencilFunc.compareMask = compareMask; - curRenderStep_->commands.push_back(data); } void SetStencilOp(uint8_t writeMask, GLenum sFail, GLenum zFail, GLenum pass) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::STENCILOP); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::STENCILOP; data.stencilOp.writeMask = writeMask; data.stencilOp.sFail = sFail; data.stencilOp.zFail = zFail; data.stencilOp.pass = pass; - curRenderStep_->commands.push_back(data); } void SetStencilDisabled() { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::STENCILFUNC); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::STENCILFUNC; data.stencilFunc.enabled = false; // When enabled = false, the others aren't read so we don't zero-initialize them. - curRenderStep_->commands.push_back(data); } void SetBlendFactor(const float color[4]) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::BLENDCOLOR); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::BLENDCOLOR; CopyFloat4(data.blendColor.color, color); - curRenderStep_->commands.push_back(data); } void SetRaster(GLboolean cullEnable, GLenum frontFace, GLenum cullFace, GLboolean ditherEnable, GLboolean depthClamp) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::RASTER); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::RASTER; data.raster.cullEnable = cullEnable; data.raster.frontFace = frontFace; data.raster.cullFace = cullFace; data.raster.ditherEnable = ditherEnable; data.raster.depthClampEnable = depthClamp; - curRenderStep_->commands.push_back(data); } // Modifies the current texture as per GL specs, not global state. void SetTextureSampler(int slot, GLenum wrapS, GLenum wrapT, GLenum magFilter, GLenum minFilter, float anisotropy) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); _dbg_assert_(slot < MAX_GL_TEXTURE_SLOTS); - GLRRenderData data(GLRRenderCommand::TEXTURESAMPLER); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::TEXTURESAMPLER; data.textureSampler.slot = slot; data.textureSampler.wrapS = wrapS; data.textureSampler.wrapT = wrapT; data.textureSampler.magFilter = magFilter; data.textureSampler.minFilter = minFilter; data.textureSampler.anisotropy = anisotropy; - curRenderStep_->commands.push_back(data); } void SetTextureLod(int slot, float minLod, float maxLod, float lodBias) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); _dbg_assert_(slot < MAX_GL_TEXTURE_SLOTS); - GLRRenderData data(GLRRenderCommand::TEXTURELOD); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::TEXTURELOD; data.textureLod.slot = slot; data.textureLod.minLod = minLod; data.textureLod.maxLod = maxLod; data.textureLod.lodBias = lodBias; - curRenderStep_->commands.push_back(data); } // If scissorW == 0, no scissor is applied (the whole render target is cleared). @@ -740,7 +740,8 @@ public: _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); if (!clearMask) return; - GLRRenderData data(GLRRenderCommand::CLEAR); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::CLEAR; data.clear.clearMask = clearMask; data.clear.clearColor = clearColor; data.clear.clearZ = clearZ; @@ -750,12 +751,12 @@ public: data.clear.scissorY = scissorY; data.clear.scissorW = scissorW; data.clear.scissorH = scissorH; - curRenderStep_->commands.push_back(data); } void Draw(GLRInputLayout *inputLayout, GLRBuffer *buffer, size_t offset, GLenum mode, int first, int count) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::DRAW); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::DRAW; data.draw.inputLayout = inputLayout; data.draw.offset = offset; data.draw.buffer = buffer; @@ -764,12 +765,12 @@ public: data.draw.first = first; data.draw.count = count; data.draw.indexType = 0; - curRenderStep_->commands.push_back(data); } void DrawIndexed(GLRInputLayout *inputLayout, GLRBuffer *buffer, size_t offset, GLRBuffer *indexBuffer, GLenum mode, int count, GLenum indexType, void *indices, int instances = 1) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER); - GLRRenderData data(GLRRenderCommand::DRAW); + GLRRenderData &data = curRenderStep_->commands.push_uninitialized(); + data.cmd = GLRRenderCommand::DRAW; data.draw.inputLayout = inputLayout; data.draw.offset = offset; data.draw.buffer = buffer; @@ -779,7 +780,6 @@ public: data.draw.indexType = indexType; data.draw.indices = indices; data.draw.instances = instances; - curRenderStep_->commands.push_back(data); } enum { MAX_INFLIGHT_FRAMES = 3 };