00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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);
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 }