Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Multisample Anti-aliasing support #285

Merged
merged 6 commits into from Aug 31, 2021
Merged

Add Multisample Anti-aliasing support #285

merged 6 commits into from Aug 31, 2021

Conversation

cebarks
Copy link
Collaborator

@cebarks cebarks commented Jun 21, 2021

This PR adds a new WindowConfig value: SamplesMSAA.

When this is set to a power of 2, it will enable MSAA for the window.

@faiface
Copy link
Owner

faiface commented Jun 21, 2021

Question: does this work with canvases?

@cebarks
Copy link
Collaborator Author

cebarks commented Jun 22, 2021

Question: does this work with canvases?

Canvas is just a go abstraction for a gl target i think? and this is implemented at the opengl level, so I'm not 100% sure, but I think it should.

@@ -163,6 +168,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
// enter the OpenGL context
w.begin()
glhf.Init()
gl.Enable(gl.MULTISAMPLE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does having this enabled with a cfg.SamplesMSAA == 0 have any effect? If so, do we need a condition around this toggle?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the window hint for sampels is set to 0 (aka cfg.SamplesMSAA == 0), this doesn't do anything. From my reading as well, this is almost always enabled automatically by the driver whether its in use or not, so there's no reason to have a conditional.

@dusk125
Copy link
Collaborator

dusk125 commented Jul 26, 2021

Last question, you mention that setting this to a power of 2 enables the multisampling, is it just a no-op if it's set to not-a-power-of-2?

@cebarks
Copy link
Collaborator Author

cebarks commented Aug 11, 2021

Last question, you mention that setting this to a power of 2 enables the multisampling, is it just a no-op if it's set to not-a-power-of-2?

Not sure honestly? Maybe would be worth having some vars in the package with various presets.

@dusk125
Copy link
Collaborator

dusk125 commented Aug 11, 2021

Yeah I think that would be a good idea, suggest some reasonable values and if someone wants to do something else, they can.

@cebarks
Copy link
Collaborator Author

cebarks commented Aug 16, 2021

@dusk125 I added a check in NewWindow that will error out if you don't put in 0, 2, 4, 8, or 16.

@@ -119,6 +124,17 @@ func NewWindow(cfg WindowConfig) (*Window, error) {

w := &Window{bounds: cfg.Bounds, cursorVisible: true}

flag := false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do

if cfg.SampelsMSAA % 2 != 0 {
   return nil, fmt.Errorf(...)
}

Not a big deal, but wouldn't have to loop and it's a bit more clear we're looking for powers of two.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this solution but wouldn't this just check to see if its even?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahahaha yes it would.....brain fart. I think then, if there are specific values that can be set otherwise, it's an error, we should at least have those specific values documented.

@@ -75,6 +77,9 @@ type WindowConfig struct {
// Invisible specifies whether the window will be initially hidden.
// You can make the window visible later using Window.Show().
Invisible bool

//SamplesMSAA specifies the level of MSAA to be used. 0 to disable.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add something like 'must be a power of two' since we're erroring if it's not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@Asday
Copy link

Asday commented Aug 18, 2021

Seeing as there's so much discussion about powers of two and only accepting them and erroring if not, why not just not let the user set an invalid value - accept an int and left shift 1 by that int, call it something like msaaLevel.

@dusk125
Copy link
Collaborator

dusk125 commented Aug 18, 2021

Seeing as there's so much discussion about powers of two and only accepting them and erroring if not, why not just not let the user set an invalid value - accept an int and left shift 1 by that int, call it something like msaaLevel.

That would certainly clear up the power of two problem; however, I think having a specific set of values is clearer to someone who may not be as experienced.

@Asday
Copy link

Asday commented Aug 18, 2021

That would certainly clear up the power of two problem; however, I think having a specific set of values is clearer to someone who may not be as experienced.

I don't think that's too much to ask of a user, nor too high a price to pay for the nicer API. I'm just one dude though, I can be out of touch. I was floating the idea to see if it had a wider appeal.

@dusk125 dusk125 merged commit b61f150 into faiface:master Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants