Project

General

Profile

Statistics
| Branch: | Revision:

root / rgbdslam / external / siftgpu / src / SiftGPU / GLTexImage.h @ 9240aaa3

History | View | Annotate | Download (5.52 KB)

1 9240aaa3 Alex
////////////////////////////////////////////////////////////////////////////
2
//        File:                GLTexImage.h
3
//        Author:                Changchang Wu
4
//        Description : interface for the GLTexImage class.
5
//                GLTexImage:                naive texture class. 
6
//                                                sevral different quad drawing functions are provied
7
//                GLTexPacked:        packed version (four value packed as four channels of a pixel)
8
//                GLTexInput:                GLTexImage + some input information
9
//
10
//        Copyright (c) 2007 University of North Carolina at Chapel Hill
11
//        All Rights Reserved
12
//
13
//        Permission to use, copy, modify and distribute this software and its
14
//        documentation for educational, research and non-profit purposes, without
15
//        fee, and without a written agreement is hereby granted, provided that the
16
//        above copyright notice and the following paragraph appear in all copies.
17
//        
18
//        The University of North Carolina at Chapel Hill make no representations
19
//        about the suitability of this software for any purpose. It is provided
20
//        'as is' without express or implied warranty. 
21
//
22
//        Please send BUG REPORTS to ccwu@cs.unc.edu
23
//
24
////////////////////////////////////////////////////////////////////////////
25
26
27
#ifndef GL_TEX_IMAGE_H
28
#define GL_TEX_IMAGE_H
29
30
class GlobalUtil;
31
class GLTexImage :public GlobalUtil 
32
{        
33
protected:
34
        GLuint        _texID;
35
        int                _imgWidth;
36
        int                _imgHeight;
37
        int                _texWidth;
38
        int                _texHeight;
39
        int                _drawWidth;
40
        int                _drawHeight;
41
public:
42
        static void DetachFBO(int i);
43
        static void UnbindTex();
44
        static void UnbindMultiTex(int n);
45
        static void DrawQuad(float x1, float x2, float y1, float y2);
46
47
public:
48
        virtual void DrawQuadUS(int scale);
49
        virtual void DrawQuadDS(int scale);
50
        virtual void DrawImage();
51
        virtual void TexConvertRGB();
52
        virtual void ZeroHistoMargin();
53
        virtual void SetImageSize(int width, int height);
54
        virtual void InitTexture(int width, int height, int clamp_to_edge =1 );
55
        void InitTexture(int width, int height, int clamp_to_edge, GLuint format);
56
        virtual void FillMargin(int marginx, int marginy);
57
public:
58
        void DrawScaledQuad(float scale);
59
        int  CopyToPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA);
60
        void CopyFromPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA);
61
        void FitRealTexViewPort();
62
        void DrawQuadMT8();
63
        void DrawQuadMT4();
64
        void DrawQuadReduction();
65
        void DrawQuadReduction(int w, int h);
66
        void DrawMargin(int right, int bottom);
67
        void DrawQuad();
68
        void FitTexViewPort();
69
        void ZeroHistoMargin(int hw, int hh);
70
        int  CheckTexture();
71
public:
72
        void AttachToFBO(int i );
73
        void BindTex();
74
        operator GLuint (){return _texID;}        
75
        GLuint GetTexID(){return _texID;}
76
        int        GetImgPixelCount(){return _imgWidth*_imgHeight;}
77
        int GetTexPixelCount(){return _texWidth*_texHeight;}
78
        int        GetImgWidth(){return _imgWidth;}
79
        int GetImgHeight(){return _imgHeight;}
80
        int        GetTexWidth(){return _texWidth;}
81
        int GetTexHeight(){return _texHeight;}
82
        int        GetDrawWidth(){return _drawWidth;}
83
        int GetDrawHeight(){return _drawHeight;}
84
        //int        IsTexTight(){return _texWidth == _drawWidth && _texHeight == _drawHeight;}
85
        int        IsTexPacked(){return _drawWidth != _imgWidth;}
86
        GLTexImage();
87
        virtual ~GLTexImage();
88
        friend class SiftGPU;
89
};
90
91
//class for handle data input, to support all openGL-supported data format, 
92
//data are first uploaded to an openGL texture then converted, and optionally
93
//when the datatype is simple, we downsample/convert on cpu
94
class GLTexInput:public GLTexImage
95
{
96
public:
97
        int      _down_sampled;
98
        int      _rgb_converted;
99
    int      _data_modified;
100
101
    //////////////////////////
102
        float *        _converted_data;
103
    const void*    _pixel_data;
104
public:
105
        static int  IsSimpleGlFormat(unsigned int gl_format, unsigned int gl_type)
106
        {
107
                //the formats there is a cpu code to conver rgb and downsample
108
                 return (gl_format ==GL_LUMINANCE ||gl_format == GL_LUMINANCE_ALPHA||
109
                                gl_format == GL_RGB||        gl_format == GL_RGBA||
110
                                gl_format == GL_BGR || gl_format == GL_BGRA) && 
111
                                (gl_type == GL_UNSIGNED_BYTE || gl_type == GL_FLOAT || gl_type == GL_UNSIGNED_SHORT); 
112
        }
113
//in vc6, template member function doesn't work
114
#if !defined(_MSC_VER) || _MSC_VER > 1200
115
        template <class Uint> 
116
        static int DownSamplePixelDataI(unsigned int gl_format, int width, int height, 
117
                int ds, const Uint * pin, Uint * pout);
118
        template <class Uint> 
119
        static int DownSamplePixelDataI2F(unsigned int gl_format, int width, int height, 
120
                int ds, const Uint * pin, float * pout, int skip  = 0);
121
#endif
122
        static int DownSamplePixelDataF(unsigned int gl_format, int width, int height, 
123
                int ds, const float * pin, float * pout, int skip = 0);
124
    static int TruncateWidthCU(int w) {return  w & 0xfffffffc; }
125
public:
126
        GLTexInput() : _down_sampled(0), _rgb_converted(0), _data_modified(0), 
127
                    _converted_data(0), _pixel_data(0){}
128
        int SetImageData(int width, int height, const void * data, 
129
                                        unsigned int gl_format, unsigned int gl_type);
130
        int LoadImageFile(char * imagepath, int & w, int &h);
131
    void VerifyTexture();
132
    virtual ~GLTexInput();
133
};
134
135
//GLTexPacked doesn't have any data
136
//so that we can use the GLTexImage* pointer to index a GLTexPacked Vector
137
138
class GLTexPacked:public GLTexImage
139
{
140
public:
141
        virtual void        DrawImage();
142
        virtual void        DrawQuadUS(int scale);
143
        virtual void        DrawQuadDS(int scale);
144
        virtual void        FillMargin(int marginx, int marginy);
145
        virtual void        InitTexture(int width, int height, int clamp_to_edge =1);
146
        virtual void        TexConvertRGB();
147
        virtual void        SetImageSize(int width, int height);
148
        virtual void        ZeroHistoMargin();
149
        //virtual void        GetHistWH(int& w, int& h){return w = (3 + sz)>>1;}
150
public:
151
        void        DrawMargin(int right, int bottom, int mx, int my);
152
        GLTexPacked():GLTexImage(){}
153
};
154
155
156
#endif // !defined(GL_TEX_IMAGE_H)