#include "renderbuffer.h"
#include "texobj.h"
#include "glformats.h"
+#include "state.h"
/**
- * Used to answer the GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES query.
+ * Used to answer the GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES queries (using
+ * GetIntegerv, GetFramebufferParameteriv, etc)
+ *
+ * If @fb is NULL, the method returns the value for the current bound
+ * framebuffer.
*/
GLenum
-_mesa_get_color_read_format(struct gl_context *ctx)
+_mesa_get_color_read_format(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ const char *caller)
{
- if (!ctx->ReadBuffer || !ctx->ReadBuffer->_ColorReadBuffer) {
- /* The spec is unclear how to handle this case, but NVIDIA's
- * driver generates GL_INVALID_OPERATION.
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ if (fb == NULL)
+ fb = ctx->ReadBuffer;
+
+ if (!fb || !fb->_ColorReadBuffer) {
+ /*
+ * From OpenGL 4.5 spec, section 18.2.2 "ReadPixels":
+ *
+ * "An INVALID_OPERATION error is generated by GetIntegerv if pname
+ * is IMPLEMENTATION_COLOR_READ_FORMAT or IMPLEMENTATION_COLOR_-
+ * READ_TYPE and any of:
+ * * the read framebuffer is not framebuffer complete.
+ * * the read framebuffer is a framebuffer object, and the selected
+ * read buffer (see section 18.2.1) has no image attached.
+ * * the selected read buffer is NONE."
+ *
+ * There is not equivalent quote for GetFramebufferParameteriv or
+ * GetNamedFramebufferParameteriv, but from section 9.2.3 "Framebuffer
+ * Object Queries":
+ *
+ * "Values of framebuffer-dependent state are identical to those that
+ * would be obtained were the framebuffer object bound and queried
+ * using the simple state queries in that table."
+ *
+ * Where "using the simple state queries" refer to use GetIntegerv. So
+ * we will assume that on that situation the same error should be
+ * triggered too.
*/
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT: "
- "no GL_READ_BUFFER)");
+ "%s(GL_IMPLEMENTATION_COLOR_READ_FORMAT: no GL_READ_BUFFER)",
+ caller);
return GL_NONE;
}
else {
- const mesa_format format = ctx->ReadBuffer->_ColorReadBuffer->Format;
+ const mesa_format format = fb->_ColorReadBuffer->Format;
const GLenum data_type = _mesa_get_format_datatype(format);
if (format == MESA_FORMAT_B8G8R8A8_UNORM)
/**
- * Used to answer the GL_IMPLEMENTATION_COLOR_READ_TYPE_OES query.
+ * Used to answer the GL_IMPLEMENTATION_COLOR_READ_TYPE_OES queries (using
+ * GetIntegerv, GetFramebufferParameteriv, etc)
+ *
+ * If @fb is NULL, the method returns the value for the current bound
+ * framebuffer.
*/
GLenum
-_mesa_get_color_read_type(struct gl_context *ctx)
+_mesa_get_color_read_type(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ const char *caller)
{
- if (!ctx->ReadBuffer || !ctx->ReadBuffer->_ColorReadBuffer) {
- /* The spec is unclear how to handle this case, but NVIDIA's
- * driver generates GL_INVALID_OPERATION.
+ if (ctx->NewState)
+ _mesa_update_state(ctx);
+
+ if (fb == NULL)
+ fb = ctx->ReadBuffer;
+
+ if (!fb || !fb->_ColorReadBuffer) {
+ /*
+ * See comment on _mesa_get_color_read_format
*/
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE: "
- "no GL_READ_BUFFER)");
+ "%s(GL_IMPLEMENTATION_COLOR_READ_TYPE: no GL_READ_BUFFER)",
+ caller);
return GL_NONE;
}
else {
- const GLenum format = ctx->ReadBuffer->_ColorReadBuffer->Format;
+ const GLenum format = fb->_ColorReadBuffer->Format;
const GLenum data_type = _mesa_get_format_datatype(format);
if (format == MESA_FORMAT_B5G6R5_UNORM)