Calling glViewport at higher than screen resolution causing problems.

Hi! I’m really stuck.

I’m rendering to a FBO at 4x screen resolution for the 4xSSAA I’m trying out; however, when I call glViewport at any resolution higher that my monitor resolution I get very occasional glitches with warped triangles. I really don’t understand.

Here is what it looks like (50 seconds in)

Anyone have any suggestions on what I might try? My matrix stack doesn’t seem to be under/over flowing - the bug only happens when the viewport is set higher than my screen resoultion (to render to FBO). I’m also using SDL - could it be something to do with OpenGL and SDL not playing well together?

Thank you for any help

Unfortunately, my sad devotion to an ancient religion has not given me clairvoyance enough to know what bugs are lurking in your code without seeing it. And the video of your bug is similarly not enlightening (it looks far more like memory corruption than viewport issues).

If you really think the viewport is to blame, what happens if you do everything for your 4x-supersampling, but leave the viewport smaller?

Thanks for taking the time to reply. Sorry for not providing code straight away.

OK, here’s the source. I agree with you; it looks like memory corruption. The glViewport command on line 58 of renderer/pileline/render_stage.h triggers it; if resolution_multiplier is less than or equal to 1.0, the bug doesn’t show up. It’s probably just a coincidence or something. Something is really broken somewhere. I really don’t know what I’m doing!

Also, I tried rendering with the 4xSSAA in a small viewport (200px x 200px) as you suggested, and the bug didn’t go away.
Another quirk I discovered: calling glFlush() after rendering each individual model fixes it!? (calling it before and/or after a group of models doesn’t work; it has to be done every time. Obviously not a solution because it kills the framerate)
Yet another hint: some of the glitched triangles have colours blended across them, but that should be impossible because glColor is only called once for each triangle:


  static void SetMaterialAndDrawTriangleAtIndex(Model* model, int index) {
    SetMaterialForTriangle(model, index);
    SetNormalForTriangle(model, index);
    DrawTriangle(model, index);
  }

  static void SetMaterialForTriangle(Model* model, int index) {
    MaterialRenderer::Render(model->GetMaterialForTriangle(index)); // this is just a wrapped glColor
  }

  static void SetNormalForTriangle(Model* model, int index) {
    NormalRenderer::Render(model->GetNormalForTriangle(index)); // this is just a wrapped glNormal
  }
   
  static void DrawTriangle(Model* model, int index) {
    VertexRenderer::Render(model->GetVertex(index,0)); // these are just simple glVertex commands
    VertexRenderer::Render(model->GetVertex(index,1));
    VertexRenderer::Render(model->GetVertex(index,2));
  }


It’s like the video card is having memory problems and calling functions out of order. How did I break it so bad? My friend’s PC had the same glitch (although he does have the same video card as me so that’s not very useful but it rules out my video card being broken)

Again, thanks! If you can help me fix this I would be glad to give you a steam gift or something - this is very important to me.

Realistically, that’s no use to anyone but yourself. Once you get that far down the OOP rabbit hole, you’re going to have to do your own debugging. No-one else is likely to put that much effort into trying to understand the code just to answer a forum post.

That’s why I tried to bribe the forum with a steam gift! Fair enough, though. I originally posted this is the hope that someone might recognise the bug as something they had come across.

Thanks for your time, anyway!

BTW when I do finally find the answer I’ll post it here in the small chance that someone else ever comes across this.