Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

framebuffer.inl

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 int Framebuffer::GetWidth() const {
00025     return m_width;
00026 }
00027 
00028 inline
00029 int Framebuffer::GetHeight() const {
00030     return m_height;
00031 }
00032 
00033 inline
00034 int Framebuffer::GetPixels() const {
00035     return m_pixels;
00036 }
00037 
00038 inline
00039 sheep::Real Framebuffer::GetPixelWidth() const {
00040     return m_inv_width;
00041 }
00042 
00043 inline
00044 sheep::Real Framebuffer::GetPixelHeight() const {
00045     return m_inv_height;
00046 }
00047 
00048 inline
00049 sheep::Point2 Framebuffer::ConvertToNDC(int x, int y) const {
00050     assert(x >= 0 && x < m_width);
00051     assert(y >= 0 && y < m_height);
00052 
00053     return sheep::Point2(
00054         (1 + x + x) * m_half_inv_width - 0.5,
00055         0.5 - (1 + y + y) * m_half_inv_height);
00056 }
00057 
00058 inline
00059 void Framebuffer::ConvertFromNDC(const sheep::Point2 &p, int *x, int *y) const {
00060     assert(p.m_x >= -0.5 && p.m_x <= 0.5);
00061     assert(p.m_y >= -0.5 && p.m_y <= 0.5);
00062     assert(x && y);
00063 
00064     // Discard fractional parts.
00065     *x = std::min(static_cast<int>(m_width * (p.m_x + 0.5)), m_width - 1);
00066     *y = std::min(static_cast<int>(m_height * (0.5 - p.m_y)), m_height - 1);
00067 }
00068 
00069 inline
00070 Color3 Framebuffer::GetPixel(int x, int y) const {
00071     assert(x >= 0 && x < m_width);
00072     assert(y >= 0 && y < m_height);
00073 
00074     switch(m_format) {
00075     case RGB_FLOAT_32:
00076         {
00077             const pixel_rgb_float_32 *p = &m_bits.m_rgb_float_32[y * m_width + x];
00078             return Color3(p->m_r, p->m_g, p->m_b);
00079         }
00080         break;
00081     default:
00082         assert(!"Unknown framebuffer format.");
00083         return Color3(0.0); // keep the compiler happy
00084     }
00085 }
00086 
00087 inline
00088 void Framebuffer::SetPixel(int x, int y, const Color3 &color) {
00089     assert(x >= 0 && x < m_width);
00090     assert(y >= 0 && y < m_height);
00091 
00092     switch(m_format) {
00093     case RGB_FLOAT_32:
00094         {
00095             pixel_rgb_float_32 *p = &m_bits.m_rgb_float_32[y * m_width + x];
00096             p->m_r = static_cast<sheep::float32>(color.m_r);
00097             p->m_g = static_cast<sheep::float32>(color.m_g);
00098             p->m_b = static_cast<sheep::float32>(color.m_b);
00099         }
00100         break;
00101     default:
00102         assert(!"Unknown framebuffer format.");
00103     }
00104 }

Generated on Tue May 11 01:31:50 2004 for toxic by doxygen 1.3.6