00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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>
00033 #include <cassert>
00034 #include <string>
00035
00036 namespace toxic {
00037
00038 class Framebuffer {
00039 public:
00040 enum Format {
00041 RGB_FLOAT_32
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
00052 int GetSizeInMemory() const;
00053
00054
00055 sheep::Real GetPixelWidth() const;
00056 sheep::Real GetPixelHeight() const;
00057
00058
00059
00060 sheep::Point2 ConvertToNDC(int x, int y) const;
00061
00062
00063 void ConvertFromNDC(const sheep::Point2 &p, int *x, int *y) const;
00064
00065
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
00074 void Normalize();
00075
00076
00077 void CorrectGamma(sheep::Real target_gamma);
00078
00079
00080 bool WriteToDisk(const std::string &filename) const;
00081
00082 private:
00083 int m_width, m_height;
00084 int m_pixels;
00085 Format m_format;
00086
00087 struct pixel_rgb_float_32 {
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;
00096 sheep::Real m_inv_height;
00097 sheep::Real m_half_inv_width;
00098 sheep::Real m_half_inv_height;
00099 };
00100
00101 #include "framebuffer.inl"
00102
00103 }
00104
00105 #endif // !TOXIC_RENDERER_FRAMEBUFFER_H