Simplify and centralize multisample counts.
Change-Id: I012bb669444e28f844c5571ff639b31dd1a35e1d
Reviewed-on: https://swiftshader-review.googlesource.com/3950
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGL/Context.cpp b/src/OpenGL/libGL/Context.cpp
index 0285baa..5ca3b5e 100644
--- a/src/OpenGL/libGL/Context.cpp
+++ b/src/OpenGL/libGL/Context.cpp
@@ -2685,19 +2685,21 @@
return GL_NO_ERROR;
}
-int Context::getSupportedMultiSampleDepth(sw::Format format, int requested)
+int Context::getSupportedMultisampleCount(int requested)
{
- if(requested <= 0)
- {
- return 0;
- }
-
- if(requested <= 2)
+ int supported = 0;
+
+ for(int i = NUM_MULTISAMPLE_COUNTS - 1; i >= 0; i--)
{
- return requested;
+ if(supported >= requested)
+ {
+ return supported;
+ }
+
+ supported = multisampleCount[i];
}
-
- return 4;
+
+ return supported;
}
void Context::detachBuffer(GLuint buffer)
diff --git a/src/OpenGL/libGL/Context.h b/src/OpenGL/libGL/Context.h
index dd08449..101f074 100644
--- a/src/OpenGL/libGL/Context.h
+++ b/src/OpenGL/libGL/Context.h
@@ -335,6 +335,10 @@
const GLint NUM_COMPRESSED_TEXTURE_FORMATS = sizeof(compressedTextureFormats) / sizeof(compressedTextureFormats[0]);
+const GLint multisampleCount[] = {4, 2, 1};
+const GLint NUM_MULTISAMPLE_COUNTS = sizeof(multisampleCount) / sizeof(multisampleCount[0]);
+const GLint IMPLEMENTATION_MAX_SAMPLES = multisampleCount[0];
+
const float ALIASED_LINE_WIDTH_RANGE_MIN = 1.0f;
const float ALIASED_LINE_WIDTH_RANGE_MAX = 128.0f;
const float ALIASED_POINT_SIZE_RANGE_MIN = 0.125f;
@@ -669,7 +673,7 @@
GLenum getError();
- static int getSupportedMultiSampleDepth(sw::Format format, int requested);
+ static int getSupportedMultisampleCount(int requested);
void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
diff --git a/src/OpenGL/libGL/Renderbuffer.cpp b/src/OpenGL/libGL/Renderbuffer.cpp
index 458a69f..ea65da0 100644
--- a/src/OpenGL/libGL/Renderbuffer.cpp
+++ b/src/OpenGL/libGL/Renderbuffer.cpp
@@ -336,12 +336,12 @@
}
}
-Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(NULL)
+Colorbuffer::Colorbuffer(int width, int height, GLenum format, GLsizei samples) : mRenderTarget(nullptr)
{
Device *device = getDevice();
sw::Format requestedFormat = es2sw::ConvertRenderbufferFormat(format);
- int supportedSamples = Context::getSupportedMultiSampleDepth(requestedFormat, samples);
+ int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
@@ -395,13 +395,11 @@
}
}
-DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples)
+DepthStencilbuffer::DepthStencilbuffer(int width, int height, GLsizei samples) : mDepthStencil(nullptr)
{
Device *device = getDevice();
- mDepthStencil = NULL;
-
- int supportedSamples = Context::getSupportedMultiSampleDepth(sw::FORMAT_D24S8, samples);
+ int supportedSamples = Context::getSupportedMultisampleCount(samples);
if(width > 0 && height > 0)
{
diff --git a/src/OpenGL/libGL/Texture.h b/src/OpenGL/libGL/Texture.h
index 2f8ed28..6574d42 100644
--- a/src/OpenGL/libGL/Texture.h
+++ b/src/OpenGL/libGL/Texture.h
@@ -40,7 +40,6 @@
IMPLEMENTATION_MAX_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_CUBE_MAP_TEXTURE_SIZE = 1 << (MIPMAP_LEVELS - 1),
IMPLEMENTATION_MAX_RENDERBUFFER_SIZE = OUTLINE_RESOLUTION,
- IMPLEMENTATION_MAX_SAMPLES = 4
};
class Texture : public NamedObject