drawPixel function

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
chronologicaldot
Competition winner
Posts: 684
Joined: Mon Sep 10, 2012 8:51 am

drawPixel function

Post by chronologicaldot »

Hi, I'm digging around again with Burnings. This post is rambling for those not interested in that renderer.
I found that the drawPixel function for Burnings is going directly to the backBuffer rather than via the render target. This doesn't look consistent with the other drivers. I've shown OpenGL below, and it looks like the drawPixel goes to the render target.

Burnings (CSoftwareDriver2.cpp, line 2267):

Code: Select all

 
void CBurningVideoDriver::drawPixel(u32 x, u32 y, const SColor & color)
{
    BackBuffer->setPixel(x, y, color, true);
    // Should probably be the following:
    // if ( x < RenderTargetSize.Width && y < RenderTargetSize.Height )
    //RenderTargetSurface->setPixel(x, y, color, true);
}
 
OpenGL:

Code: Select all

 
void COpenGLDriver::drawPixel(u32 x, u32 y, const SColor &color)
{
    const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();
    if (x > (u32)renderTargetSize.Width || y > (u32)renderTargetSize.Height)
        return;
 
    disableTextures();
    setRenderStates2DMode(color.getAlpha() < 255, false, false);
 
    glBegin(GL_POINTS);
    glColor4ub(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
    glVertex2i(x, y);
    glEnd();
}
 
Since I didn't know how the OpenGL implementation works, I'm asking for confirmation. I just assume it's the render target because of the obvious function call getCurrentRenderTargetSize().

I just wanted consistency across drivers.

There are also some other spots in Burnings where the Backbuffer is directly accessed rather than via the render target, such as the next function: draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip) on line 2275.

Notably, though, the drawRectangle with all of the colors (up-left, down-right, etc) goes to the render target. It's code, however, seems rather inefficient, so I plan on re-writing it, and I may post the code here later (if I get it to work, lol). Just musing....

Edit: Now that I see it, what if you try calling the setPixel( renderTarget width, renderTarget height ) for OpenGL? Wouldn't that crash or do the pixel indices start at (1,1)?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: drawPixel function

Post by hendu »

GL doesn't give a heck what you feed it, it will do the clipping for you. Telling it to draw one pixel outside will just not get drawn, just like a triangle 5000 times the screen will get clipped to the screen.
Post Reply