Closed Bug 1071233 Opened 10 years ago Closed 10 years ago

WebGL - Use strong types for framebuffers and renderbuffers

Categories

(Core :: Graphics: CanvasWebGL, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla35

People

(Reporter: wlitwinczyk, Assigned: wlitwinczyk)

References

Details

Attachments

(1 file, 3 obsolete files)

Since the strong GL enums patch has landed: Bug 1063053 it's worth going through and adding the functionality where it can be added. This bug will add strong GL enum support for:

Framebuffer targets
Framebuffer attachments
Framebuffer status

Renderbuffer targets
Renderbuffer parameters
Attached patch fb_rb_strong_types_patch (obsolete) — Splinter Review
Attachment #8493371 - Flags: review?(jgilbert)
Comment on attachment 8493371 [details] [diff] [review]
fb_rb_strong_types_patch

Review of attachment 8493371 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/canvas/WebGLContextValidate.cpp
@@ +537,5 @@
> +        // Check if the user was trying to use multiple color
> +        // buffers and provide a helpful error message.
> +        if (attachment > LOCAL_GL_COLOR_ATTACHMENT0 &&
> +            attachment <= LOCAL_GL_COLOR_ATTACHMENT15 &&
> +            !IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers))

It seems like this whole function could be simpler if we use early-returns.

if it's a depth and/or stencil buffer:
  return true

GLenum colorAttachCount = 1
if draw buffers enabled:
  colorAttachCount = mGLMaxColorAttachments

if attachment within [color0, color0+colorAttachCount):
  return true

invalid enum!
return false

::: dom/canvas/WebGLFramebuffer.cpp
@@ +335,5 @@
>          }
>  
>          if (mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0 &&
> +            mAttachmentPoint <= FBAttachment(LOCAL_GL_COLOR_ATTACHMENT0 - 1 +
> +                                             WebGLContext::kMaxColorAttachments))

I think the old way was better.
`< max` is more common than `<= last`.

@@ +765,5 @@
>  {
>      if (mStatus != 0)
>          return mStatus;
>  
> +    mStatus = PrecheckFramebufferStatus().get();

Shouldn't mStatus be a strong type?

::: dom/canvas/WebGLFramebufferAttachable.h
@@ +12,3 @@
>  #include "GLDefs.h"
>  #include "nsTArray.h"
>  #include "mozilla/WeakPtr.h"

Try to keep the includes alphabetical.
Here, it would be:
GLDefs.h
mozilla/WeakPtr.h
nsTArray.h
WebGLFramebuffer.h
WebGLStrongTypes.h
Attachment #8493371 - Flags: review?(jgilbert) → review+
(In reply to Jeff Gilbert [:jgilbert] from comment #2)
> Comment on attachment 8493371 [details] [diff] [review]
> fb_rb_strong_types_patch
> 
> Review of attachment 8493371 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: dom/canvas/WebGLContextValidate.cpp
> @@ +537,5 @@
> > +        // Check if the user was trying to use multiple color
> > +        // buffers and provide a helpful error message.
> > +        if (attachment > LOCAL_GL_COLOR_ATTACHMENT0 &&
> > +            attachment <= LOCAL_GL_COLOR_ATTACHMENT15 &&
> > +            !IsExtensionEnabled(WebGLExtensionID::WEBGL_draw_buffers))
> 
> It seems like this whole function could be simpler if we use early-returns.
> 

Done

> ::: dom/canvas/WebGLFramebuffer.cpp
> @@ +335,5 @@
> >          }
> >  
> >          if (mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0 &&
> > +            mAttachmentPoint <= FBAttachment(LOCAL_GL_COLOR_ATTACHMENT0 - 1 +
> > +                                             WebGLContext::kMaxColorAttachments))
> 
> I think the old way was better.
> `< max` is more common than `<= last`.
> 

Well, I would have left it, but because of the validation, it will assert if you do plain LOCAL_GL_COLOR_ATTACHMENT0 + kMax... The alternative is to add a LOCAL_GL_COLOR_ATTACHMENT16 to FBAttachment and then I could use the old way. I wasn't sure which would be better. As adding the extra one might let off-by-one errors slip by.

> @@ +765,5 @@
> >  {
> >      if (mStatus != 0)
> >          return mStatus;
> >  
> > +    mStatus = PrecheckFramebufferStatus().get();
> 
> Shouldn't mStatus be a strong type?
> 

I had done that originally, and ran into the problem with the sentinel value of 0 being used. I really didn't want to add LOCAL_GL_NONE to the list, but I suppose I could. Or maybe instead of using LOCAL_GL_NONE we can add another non-zero constant? Something less likely to happen? A STRONG_GLENUM_INVALID or something.

> ::: dom/canvas/WebGLFramebufferAttachable.h
> @@ +12,3 @@
> >  #include "GLDefs.h"
> >  #include "nsTArray.h"
> >  #include "mozilla/WeakPtr.h"
> 
> Try to keep the includes alphabetical.
> Here, it would be:
> GLDefs.h
> mozilla/WeakPtr.h
> nsTArray.h
> WebGLFramebuffer.h
> WebGLStrongTypes.h

Done
Depends on: 1071339, 1071340
Attached patch fb_rb_strong_types_patch (obsolete) — Splinter Review
Rebased onto bjacob's patches, which are already in inbound and made most of the requested changes (minus the two comments above).
Attachment #8493371 - Attachment is obsolete: true
Attachment #8494090 - Flags: review?(jgilbert)
Comment on attachment 8494090 [details] [diff] [review]
fb_rb_strong_types_patch

Review of attachment 8494090 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/canvas/WebGLContextValidate.cpp
@@ +544,5 @@
> +        return true;
> +    }
> +
> +    ErrorInvalidEnum("%s: attachment: invalid enum value 0x%x.", funcName, attachment);
> +    return true;

false, surely?
Attachment #8494090 - Flags: review?(jgilbert) → review-
Whoops! You are correct. At least the StrongGL types caught that in try!
Attached patch fb_rb_strong_types_patch (obsolete) — Splinter Review
Attachment #8494090 - Attachment is obsolete: true
Attachment #8494157 - Flags: review?(jgilbert)
Attachment #8494157 - Flags: review?(jgilbert) → review+
r=jgilbert carried forward. Minor try fixes due to Bug 1071339 now requiring the enums to be in ascending order.

Try: https://tbpl.mozilla.org/?tree=Try&rev=fde6088fe349
Attachment #8494157 - Attachment is obsolete: true
Attachment #8495315 - Flags: review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/6b2bd6111568
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla35
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: