<div dir="ltr">On 4 February 2013 21:48, Chris Forbes <span dir="ltr"><<a href="mailto:chrisf@ijw.co.nz" target="_blank">chrisf@ijw.co.nz</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
V2: - fix formatting issues<br>
- generate GL_OUT_OF_MEMORY if teximage cannot be allocated<br>
- fix for state moving from texobj to image<br>
<br>
Signed-off-by: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz">chrisf@ijw.co.nz</a>><br>
---<br>
src/mesa/main/teximage.c | 153 +++++++++++++++++++++++++++++++++++++++++++++--<br>
1 file changed, 149 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c<br>
index dbeaa93..39e6364 100644<br>
--- a/src/mesa/main/teximage.c<br>
+++ b/src/mesa/main/teximage.c<br>
@@ -4163,13 +4163,158 @@ _mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,<br>
<br>
<br>
/** GL_ARB_texture_multisample */<br>
+static void<br>
+teximagemultisample(GLuint dims, GLenum target, GLsizei samples,<br>
+ GLint internalformat, GLsizei width, GLsizei height, GLsizei depth,<br>
+ GLboolean fixedsamplelocations)<br>
+{<br>
+ struct gl_texture_object *texObj;<br>
+ struct gl_texture_image *texImage;<br>
+ GLboolean sizeOK, dimensionsOK;<br>
+ gl_format texFormat;<br>
+<br>
+ GET_CURRENT_CONTEXT(ctx);<br>
+<br>
+ if (!(ctx->Extensions.ARB_texture_multisample<br>
+ && _mesa_is_desktop_gl(ctx))) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glTexImage%uDMultisample", dims);<br>
+ return;<br>
+ }<br>
+<br>
+ if ((dims == 2 && target != GL_TEXTURE_2D_MULTISAMPLE) ||<br>
+ (dims == 3 && target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY)) {<br>
+ _mesa_error(ctx, GL_INVALID_ENUM, "glTexImage%uDMultisample(target)", dims);<br>
+ return;<br>
+ }<br>
+<br>
+ /* check that the specified internalformat is color/depth/stencil-renderable;<br>
+ * refer GL3.1 spec 4.4.4<br>
+ */<br>
+<br>
+ if (!_mesa_base_fbo_format(ctx, internalformat)) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+ "glTexImage%uDMultisample(internalformat=%s)",<br>
+ dims,<br>
+ _mesa_lookup_enum_by_nr(internalformat));<br>
+ return;<br>
+ }<br></blockquote><div><br></div><div>In light of our discussion on patch 13/22 (where we decided that stencil only textures shouldn't be allowed), I believe this check needs to change.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+ if (_mesa_is_enum_format_integer(internalformat)) {<br>
+ if (samples > ctx->Const.MaxIntegerSamples) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+ "glTexImage%uDMultisample(samples>GL_MAX_INTEGER_SAMPLES)",<br>
+ dims);<br>
+ return;<br>
+ }<br>
+ }<br>
+ else if (_mesa_is_depth_or_stencil_format(internalformat)) {<br>
+ if (samples > ctx->Const.MaxDepthTextureSamples) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+ "glTexImage%uDMultisample(samples>GL_MAX_DEPTH_TEXTURE_SAMPLES)",<br>
+ dims);<br>
+ return;<br>
+ }<br>
+ }<br>
+ else {<br>
+ if (samples > ctx->Const.MaxColorTextureSamples) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION,<br>
+ "glTexImage%uDMultisample(samples>GL_MAX_COLOR_TEXTURE_SAMPLES)",<br>
+ dims);<br>
+ return;<br>
+ }<br>
+ }<br>
+<br>
+ /* TODO: should ask the driver for the exact limit for this internalformat<br>
+ * once IDR's internalformat_query bits land<br>
+ */<br>
+<br>
+ texObj = _mesa_get_current_tex_object(ctx, target);<br>
+ texImage = _mesa_get_tex_image(ctx, texObj, 0, 0);<br>
+<br>
+ if (texImage == NULL) {<br>
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage%uDMultisample()", dims);<br>
+ return;<br>
+ }<br>
+<br>
+ switch(internalformat) {<br>
+ /* XXX horrid hack: _mesa_choose_texture_format will be<br>
+ * very upset by these. a similar hack exists in the i965<br>
+ * renderbufferstorage path.<br>
+ */<br>
+ case GL_STENCIL_INDEX:<br>
+ case GL_STENCIL_INDEX1:<br>
+ case GL_STENCIL_INDEX4:<br>
+ case GL_STENCIL_INDEX8:<br>
+ case GL_STENCIL_INDEX16:<br>
+ texFormat = MESA_FORMAT_S8;<br>
+ break;<br></blockquote><div><br></div><div>Now that we've determined that stencil-only textures aren't allowed, can we get rid of this hack?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ default:<br>
+ texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0,<br>
+ internalformat, GL_NONE, GL_NONE);<br>
+ }<br>
+ assert(texFormat != MESA_FORMAT_NONE);<br>
+<br>
+ dimensionsOK = _mesa_legal_texture_dimensions(ctx, target, 0,<br>
+ width, height, depth, 0);<br>
+<br>
+ sizeOK = ctx->Driver.TestProxyTexImage(ctx, target, 0, texFormat,<br>
+ width, height, depth, 0);<br>
+<br>
+ if (_mesa_is_proxy_texture(target)) {<br>
+ if (dimensionsOK && sizeOK) {<br>
+ _mesa_init_teximage_fields(ctx, texImage,<br>
+ width, height, depth, 0, internalformat, texFormat);<br>
+ texImage->NumSamples = samples;<br>
+ texImage->FixedSampleLocations = fixedsamplelocations;<br>
+ }<br>
+ else {<br>
+ /* clear all image fields */<br>
+ _mesa_init_teximage_fields(ctx, texImage,<br>
+ 0, 0, 0, 0, GL_NONE, MESA_FORMAT_NONE);<br>
+ }<br>
+ }<br>
+ else {<br>
+ if (!dimensionsOK) {<br>
+ _mesa_error(ctx, GL_INVALID_VALUE,<br>
+ "glTexImage%uDMultisample(invalid width or height)", dims);<br>
+ return;<br>
+ }<br>
+<br>
+ if (!sizeOK) {<br>
+ _mesa_error(ctx, GL_OUT_OF_MEMORY,<br>
+ "glTexImage%uDMultisample(texture too large)", dims);<br>
+ return;<br>
+ }<br>
+<br>
+ assert(width > 0);<br>
+ assert(height > 0);<br>
+ assert(depth > 0);<br>
+<br>
+ _mesa_init_teximage_fields(ctx, texImage,<br>
+ width, height, depth, 0, internalformat, texFormat);<br>
+<br>
+ texImage->NumSamples = samples;<br>
+ texImage->FixedSampleLocations = fixedsamplelocations;<br>
+<br>
+ if (!ctx->Driver.AllocTextureStorage(ctx, texObj, 1,<br>
+ width, height, depth)) {<br>
+ /* tidy up the texture image state. strictly speaking,<br>
+ * we're allowed to just leave this in whatever state we<br>
+ * like, but being tidy is good.<br>
+ */<br>
+ _mesa_init_teximage_fields(ctx, texImage,<br>
+ 0, 0, 0, 0, GL_NONE, MESA_FORMAT_NONE);<br>
+ }<br>
+ }<br>
+}<br>
+<br>
void GLAPIENTRY<br>
_mesa_TexImage2DMultisample(GLenum target, GLsizei samples,<br>
GLint internalformat, GLsizei width, GLsizei height,<br>
GLboolean fixedsamplelocations)<br>
{<br>
- assert(!"Not implemented");<br>
- /* allocate a single 2d multisample texture */<br>
+ teximagemultisample(2, target, samples, internalformat,<br>
+ width, height, 1, fixedsamplelocations);<br>
}<br>
<br>
void GLAPIENTRY<br>
@@ -4177,6 +4322,6 @@ _mesa_TexImage3DMultisample(GLenum target, GLsizei samples,<br>
GLint internalformat, GLsizei width, GLsizei height,<br>
GLsizei depth, GLboolean fixedsamplelocations)<br>
{<br>
- assert(!"Not implemented");<br>
- /* allocate an array of 2d multisample textures */<br>
+ teximagemultisample(3, target, samples, internalformat,<br>
+ width, height, depth, fixedsamplelocations);<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.2<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>