objarni's picture

GL.WriteBuffer missing

Where is the equivalent to the c API glWriteBuffer()?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Inertia's picture

glDrawBuffer might be what you're looking for?

the Fiddler's picture

I can't find mention of that function anywhere in the specs or the manual, or even the mesa3d headers.

A quick google search returns about 7 results - are you sure such a function exists?

objarni's picture

Ahh! DrawBuffer is the one, thank you!

robpson's picture

DrawBuffer seems not to work. Shouldnt this sample show the same output if the doublebuffer flag is toggled??:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenTK.Graphics;
 
namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
 
    bool doublebuffer = true; // try toggling this!
 
    public Form1()
    {
      InitializeComponent();
      GL.Viewport(0, 0, glControl1.Width, glControl1.Height);
 
      //map coordinates to pixels:
      GL.MatrixMode(MatrixMode.Projection);
      GL.LoadIdentity();
      GL.Ortho(0.0, glControl1.Width, 0.0, glControl1.Height, -1, 1);
 
      GL.ClearColor(Color.Coral);
    }
 
    private void glControl1_Paint(object sender, PaintEventArgs e)
    {
 
      if (!doublebuffer)
        GL.DrawBuffer(DrawBufferMode.Front);
 
      GL.MatrixMode(MatrixMode.Modelview);
      GL.LoadIdentity();
 
      GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
      GL.Begin(BeginMode.Polygon);
      GL.Color3(1.0, 0.0, 0.0);
      GL.Vertex2(100, 100);
      GL.Color3(0.0, 1.0, 0.0);
      GL.Vertex2(200, 100);
      GL.Color3(0.0, 0.0, 1.0);
      GL.Vertex2(100, 200);
      GL.End();
 
      if (doublebuffer)
        glControl1.SwapBuffers();
    }
 
  }
}
the Fiddler's picture

I think you are missing a GL.Flush() call:

if (doublebuffer)
    glControl1.SwapBuffers();
else
    GL.Flush();

Also, the GLControl is creating a doublebuffered context - I don't know if this complicates things. Also, single buffering is the devil - I'd avoid subjecting my users to its ugliness. :-)

Inertia's picture

GL.DrawBuffer does work, you should check whether there are any GL.Errors and verify what buffer is set with GL.GetInteger( GetPName.DrawBuffer, etc.

Edit: Thanks for pointing at the DrawBuffer function, there's another inconsistency :P

Why do GL.DrawBuffer and GL.DrawBuffers use different enums? They're essentially the same, but DrawBuffers accepts an array of buffers.

I've also missed a couple of tokens when revisiting the enum, it should also contain the ColorAttachment0-15 tokens. If you bind a FBO it will automatically be set to ColorAttachment0 instead of the backbuffer.

Some code might be more clear:

DrawBuffersEnum[] bufs = new DrawBuffersEnum[2] { (DrawBuffersEnum) FramebufferAttachment.ColorAttachment0Ext, (DrawBuffersEnum) FramebufferAttachment.ColorAttachment1Ext };
 
GL.DrawBuffers( bufs.Length, bufs );
 
GL.GetInteger( GetPName.DrawBuffer0, out temp ); // temp==ColorAttachment0, addressed with gl_FragData[0]
GL.GetInteger( GetPName.DrawBuffer1, out temp ); // temp==ColorAttachment1, addressed with gl_FragData[1]

Edit Again: Could it be that the front buffer is protected in some way in double buffered contexts?