-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextureObj.h
121 lines (106 loc) · 2.74 KB
/
TextureObj.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//############################################################
//
// TextureObj.h
//
// Szymon Rusinkiewicz
// Fri Mar 12 01:47:50 CET 1999
//
// Texture maps for scans.
//
//############################################################
#ifndef _TEXTUREOBJ_H_
#define _TEXTUREOBJ_H_
#define DEFAULT_CAMERA_FILENAME "/usr/graphics/lib/plyshade/pastecolor/dmich.cameraparams"
#define DEFAULT_CAMCALIBXF_FILENAME "/usr/graphics/lib/plyshade/pastecolor/dmich.cameracalib.xf"
#ifdef sgi
#define MAG_FILTER GL_LINEAR_SHARPEN_SGIS
#else
#define MAG_FILTER GL_LINEAR
#endif
#define MIN_FILTER GL_LINEAR_MIPMAP_LINEAR
#include <string.h>
#include <stdlib.h>
#include <GL/gl.h>
#include "Xform.h"
#include "RefCount.h"
#include "cameraparams.h"
class TextureObj : public RefCount {
public:
virtual void setupTexture() = 0;
virtual ~TextureObj() {}
};
class GL_Bound_TextureObj : public TextureObj {
private:
GLuint textureobjnum;
protected:
void bind()
{
glBindTexture(GL_TEXTURE_2D, textureobjnum);
}
void unbind()
{
glBindTexture(GL_TEXTURE_2D, 0);
}
GL_Bound_TextureObj()
{
glGenTextures(1, &textureobjnum);
bind();
}
public:
virtual ~GL_Bound_TextureObj()
{
if (textureobjnum)
glDeleteTextures(1, &textureobjnum);
}
};
class ProjectiveTexture : public GL_Bound_TextureObj {
private:
Xform<float> *camcalibxf, *camxf, *alignxf;
float xscale, yscale;
CameraParams *thecamera;
protected:
ProjectiveTexture(CameraParams *_cam,
Xform<float> *_camcalibxf = NULL,
Xform<float> *_camxf = NULL,
Xform<float> *_alignxf = NULL,
float _xscale = 1.0,
float _yscale = 1.0) :
camcalibxf(_camcalibxf), camxf(_camxf), alignxf(_alignxf),
thecamera(_cam), xscale(_xscale), yscale(_yscale)
{}
public:
static Ref<ProjectiveTexture> loadImage(const char *filename,
const char *camfilename = NULL,
const char *camcalibxffilename = NULL,
const char *camxffilename = NULL,
const char *alignxffilename = NULL,
const bool actuallyLoadImage = true,
const bool use_mipmaps = true );
virtual void setupTexture();
virtual ~ProjectiveTexture()
{
delete thecamera;
if (alignxf) delete alignxf;
if (camxf) delete camxf;
if (camcalibxf) delete camcalibxf;
}
};
class MeshAffixedProjectiveTexture : public TextureObj {
private:
Ref<ProjectiveTexture> theprojtexture;
float meshtransform[16];
MeshAffixedProjectiveTexture(Ref<ProjectiveTexture> _theprojtexture,
const float *_meshtransform) :
theprojtexture(_theprojtexture)
{
memcpy(meshtransform, _meshtransform, 16*sizeof(float));
}
public:
static Ref<TextureObj> AffixToMesh(Ref<ProjectiveTexture> projtex,
const float *transform)
{
return new MeshAffixedProjectiveTexture(projtex, transform);
}
virtual void setupTexture();
};
#endif