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

framebuffer.h

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 #ifndef TOXIC_RENDERER_FRAMEBUFFER_H
00024 #define TOXIC_RENDERER_FRAMEBUFFER_H
00025 
00026 #include "common/math/point2.h"
00027 #include "common/math/real.h"
00028 #include "common/misc/types.h"
00029 #include "color3.h"
00030 #include "globals.h"
00031 
00032 #include <algorithm>    // std::min<>(), std::max<>()
00033 #include <cassert>
00034 #include <string>
00035 
00036 namespace toxic {
00037 
00038     class Framebuffer {
00039     public:
00040         enum Format {
00041             RGB_FLOAT_32    //!< RGB format, each channel is coded as 32-bit float.
00042         };
00043 
00044         Framebuffer(int width, int height, Format format);
00045         ~Framebuffer();
00046 
00047         int GetWidth() const;
00048         int GetHeight() const;
00049         int GetPixels() const;
00050 
00051         //! Returns the size (in bytes) of the framebuffer in memory.
00052         int GetSizeInMemory() const;
00053 
00054         //! Returns the dimensions of a pixel.
00055         sheep::Real GetPixelWidth() const;
00056         sheep::Real GetPixelHeight() const;
00057 
00058         //! Converts from pixel coordinates to NDC (see file renderer/camera.h).
00059         //! Returns NDC of the center of the pixel located at (x, y).
00060         sheep::Point2 ConvertToNDC(int x, int y) const;
00061 
00062         //! Converts from NDC to pixel coordinates.
00063         void ConvertFromNDC(const sheep::Point2 &p, int *x, int *y) const;
00064 
00065         //! Clears the framebuffer with a given color.
00066         void Clear(Color3 color = Color3(0.0));
00067 
00068         Color3 GetPixel(int x, int y) const;
00069         void SetPixel(int x, int y, const Color3 &color);
00070 
00071         void PlotLine(int x1, int y1, int x2, int y2, const Color3 &color);
00072 
00073         //! Maps pixel values to the [0..1] interval.
00074         void Normalize();
00075 
00076         //!\todo Implement a complete tone mapping architecture.
00077         void CorrectGamma(sheep::Real target_gamma);
00078 
00079         //! Returns true if success, false otherwise.
00080         bool WriteToDisk(const std::string &filename) const;
00081 
00082     private:
00083         int m_width, m_height;          //!< Dimensions of the framebuffer, in pixels.
00084         int m_pixels;                   //!< Total number of pixels, which is equal to m_width * m_height.
00085         Format m_format;                //!< Format of the framebuffer.
00086 
00087         struct pixel_rgb_float_32 {     //!< Structure of a pixel for the RGB_FLOAT_32 format.
00088             sheep::float32 m_r, m_g, m_b;
00089         };
00090 
00091         union {
00092             pixel_rgb_float_32 *m_rgb_float_32;
00093         } m_bits;
00094 
00095         sheep::Real m_inv_width;        //!< m_inv_width = 1.0 / m_width.
00096         sheep::Real m_inv_height;       //!< m_inv_height = 1.0 / m_height.
00097         sheep::Real m_half_inv_width;   //!< m_half_inv_width = 1.0 / (2.0 * m_width).
00098         sheep::Real m_half_inv_height;  //!< m_half_inv_height = 1.0 / (2.0 * m_height).
00099     };
00100 
00101 #include "framebuffer.inl"
00102 
00103 }
00104 
00105 #endif  // !TOXIC_RENDERER_FRAMEBUFFER_H

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