⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 texture.hpp

📁 The goal of this project is to explore the idea of point-based radiosity, which is a shooting radio
💻 HPP
字号:
#if !defined(BRL_TEXTURE_HPP)
#define BRL_TEXTURE_HPP
/*+-------------------------------------------------------------------
  Ben Landon
  CSCI E-235
  Final Project

  Texture.hpp - A simple class to encapsulate a 2D texture.

*/

#include "Color.hpp"
#include "Map_of.hpp"


/*+-------------------------------------------------------------------
  TextureException

  Exception thrown if an error happens during texture
  operations that the calling code must handle.

*/
class TextureException 
{
public:
    TextureException (void) { }
    ~TextureException () { } 
};


/*+-------------------------------------------------------------------
  Texture 

  Base class for Textures, including the luminance textures
  in the hemicube, and the accumulation and emissive textures.

*/
class Texture
{
protected:
    Texture (unsigned int width, unsigned int height);

    unsigned int m_texture_id;
    unsigned int m_width;
    unsigned int m_height;

public:
    void make_current (void) const;
    virtual ~Texture();
    unsigned int width (void) const { return m_width; }
    unsigned int height (void) const { return m_height; }
    unsigned int texture_id (void) const { return m_texture_id; }
};


/*+-------------------------------------------------------------------
  GrayscaleTexture
  
  Class for encapsulating a grayscale texture, which is 
  used as the cosine texture in the hemicube.

*/
class GrayscaleTexture : public Texture
{
private:
    float* m_grayscale_texels;

public:
    // A Map_of float will create a greyscale texture
    GrayscaleTexture (Map_of<float>& texture_map);
    virtual ~GrayscaleTexture ();
    const float* texels (void) const { return m_grayscale_texels; }
    void mipmap_texels (int level, float* texels) const;
    void get_mipmap_dimensions (int level, int& width, int& height) const;
    int mipmap_level (unsigned int width, unsigned int height) const;
};


// Accumulation textures and emissive textures
class SceneTexture : public Texture
{
private:
    // I've decided on floats for the precision
    // This is in row major format.
    float* m_pixels;
    
    // The number of color channels in each pixel.
    static int components_per_pixel;

    // Utility method for finding the pixel offset, 
    // in the m_pixels array, given u and v coordintes.
    // u is the column (analogous to x), and v is the 
    // row (analogous to y).
    inline unsigned int get_pixel_offset (int u, int v) const
    {
	return (components_per_pixel * (v * m_width + u));
    }

    void delete_texture_data (void);

public:
    SceneTexture (int width, int height);
    ~SceneTexture (); 
    void copy_into (SceneTexture& target);

    void subtract (const Color& color_to_subtract, 
		   int u, int v, 
		   bool reset_gl_texture = false);

    void add (const Color& color_to_add, 
	      int u, int v, 
	      bool reset_gl_texture = false);
    
    void clear (void); // clears to black (0, 0, 0, 0)

    void get_brightest_texel (int& u, int& v, Color& texel) const;

    // Sum the texels in this texture.  This is 
    // the sum over all texels or (R + G + B) * A
    float get_texel_sum (void) const;
    
    // Get the area of the SceneTexture in texels.
    int   get_texel_area (void) const { return m_width * m_height; }

    // get/set the colors of individual texels.
    void  get (Color& color, int u, int v) const;
    void  set (const Color& color, int u, int v);

    // Tell OpenGL about the texels in this texture object.
    void  tell_opengl (void);
    
    void set_texels (float* texels, unsigned int num_texels);

    void normalize (void);
    void clone_into (SceneTexture& clone_target);
};

#endif





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -