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 texture coordinates to WebGL rounded rects #5795

Merged
merged 1 commit into from
Sep 11, 2022

Conversation

davepagurek
Copy link
Contributor

@davepagurek davepagurek commented Sep 10, 2022

Addresses #5001

Currently, textures only work for rounded rects in WebGL if you have textureMode(IMAGE) set. If you don't add border radii, then any texture mode works. This explicitly specifies texture coordinates in the WebGL rect implementation so that it always works with provided textures regardless of mode.

Changes:

  • Adds texture coordinates to the immediate mode rendering of rounded rects in WebGL mode

Problems not addressed yet:

Screenshots of the change:

let w, h, tl, tr, bl, br
let img

function preload() {
  img = loadImage('cat.jpg')
}

function setup() {
  createCanvas(400, 400, WEBGL)
  w = createSlider(0, 400, 200)
  h = createSlider(0, 400, 200)
  tl = createSlider(0, 300, 0)
  tr = createSlider(0, 300, 0)
  bl = createSlider(0, 300, 0)
  br = createSlider(0, 300, 0)
}

function draw() {
  background(255)
  rectMode(CENTER)
  textureMode(NORMAL) // This breaks on main
  texture(img)
  rect(
    0,
    0,
    w.value(),
    h.value(),
    tl.value(),
    tr.value(),
    br.value(),
    bl.value()
  )
}

rounded-rect

PR Checklist

  • npm run lint passes
  • [Inline documentation] is included / updated
  • [Unit tests] are included / updated

@ShenpaiSharma
Copy link
Contributor

Hi @davepagurek, when I am using it, texturing doesn't seem to be working right.

ezgif com-gif-maker

@davepagurek
Copy link
Contributor Author

Thanks for trying it out! I have a web editor version here, does this work for you? https://editor.p5js.org/davepagurek/sketches/bMIevQinw If not, so I can try to reproduce it, what browser are you testing in?

@ShenpaiSharma
Copy link
Contributor

Yeah, thanks, this works fine for me.

Copy link
Contributor

@stalgiag stalgiag left a comment

Choose a reason for hiding this comment

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

I haven't been following the rounded rects saga so this is all fairly new to me and all I can do is test it. It tests well. This seems like a straightforward addition to the current approach.

I think that the current approach might need further examination down the road (for the reasons you listed). Ideally, any vertex processing used to generate values for immediate mode could also be used to generate values for retained mode. What if the quadraticVertex function produced vertices based on the look-up table using a helper function so that the same helper function could be used elsewhere for caching?

Anyways! All that aside, I think this works well with the current implementation!

@davepagurek
Copy link
Contributor Author

I think that the current approach might need further examination down the road (for the reasons you listed). Ideally, any vertex processing used to generate values for immediate mode could also be used to generate values for retained mode. What if the quadraticVertex function produced vertices based on the look-up table using a helper function so that the same helper function could be used elsewhere for caching?

True good call, I imagine (but have not profiled to verify) that that'll be the majority of the time spent in this function now, so caching it would be good!

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.

3 participants