Browse Source

Fix a couple bugs with love.graphics.clear.

Alex Szpakowski 7 years ago
parent
commit
3a8390ceff
2 changed files with 8 additions and 10 deletions
  1. 7 9
      src/modules/graphics/opengl/Graphics.cpp
  2. 1 1
      src/modules/graphics/opengl/OpenGL.h

+ 7 - 9
src/modules/graphics/opengl/Graphics.cpp

@@ -608,14 +608,12 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors, OptionalInt sten
 	if (colors.size() == 0 && !stencil.hasValue && !depth.hasValue)
 	if (colors.size() == 0 && !stencil.hasValue && !depth.hasValue)
 		return;
 		return;
 
 
-	int ncanvases = (int) states.back().renderTargets.colors.size();
-	int ncolors = std::min((int) colors.size(), ncanvases);
+	int ncolorcanvases = (int) states.back().renderTargets.colors.size();
+	int ncolors = std::min((int) colors.size(), ncolorcanvases);
 
 
-	if (ncolors <= 1 && ncanvases <= 1)
+	if (ncolors <= 1 && ncolorcanvases <= 1)
 	{
 	{
-		if (colors[0].hasValue)
-			clear(colors[0].value, stencil, depth);
-
+		clear(ncolors > 0 ? colors[0] : OptionalColorf(), stencil, depth);
 		return;
 		return;
 	}
 	}
 
 
@@ -652,10 +650,10 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors, OptionalInt sten
 	{
 	{
 		GLenum bufs[MAX_COLOR_RENDER_TARGETS];
 		GLenum bufs[MAX_COLOR_RENDER_TARGETS];
 
 
-		for (int i = 0; i < ncanvases; i++)
+		for (int i = 0; i < ncolorcanvases; i++)
 			bufs[i] = GL_COLOR_ATTACHMENT0 + i;
 			bufs[i] = GL_COLOR_ATTACHMENT0 + i;
 
 
-		glDrawBuffers(ncanvases, bufs);
+		glDrawBuffers(ncolorcanvases, bufs);
 	}
 	}
 
 
 	GLbitfield flags = 0;
 	GLbitfield flags = 0;
@@ -1160,7 +1158,7 @@ void Graphics::setDepthMode(CompareMode compare, bool write)
 	if (depthenable)
 	if (depthenable)
 	{
 	{
 		glDepthFunc(OpenGL::getGLCompareMode(compare));
 		glDepthFunc(OpenGL::getGLCompareMode(compare));
-		glDepthMask(write ? GL_TRUE : GL_FALSE);
+		gl.setDepthWrites(write);
 	}
 	}
 }
 }
 
 

+ 1 - 1
src/modules/graphics/opengl/OpenGL.h

@@ -453,7 +453,7 @@ private:
 
 
 		float pointSize;
 		float pointSize;
 
 
-		bool depthWritesEnabled;
+		bool depthWritesEnabled = true;
 
 
 		GLuint boundFramebuffers[2];
 		GLuint boundFramebuffers[2];