22 |
<< " into texture " << t.id << "\n"; |
<< " into texture " << t.id << "\n"; |
23 |
t.clamped = true; |
t.clamped = true; |
24 |
|
|
25 |
|
#if 1 |
26 |
float *data = new float[w*h*c]; |
float *data = new float[w*h*c]; |
27 |
|
|
|
|
|
28 |
int level = 0; |
int level = 0; |
29 |
for (;;) { |
for (;;) { |
30 |
glBindTexture(GL_TEXTURE_2D, id); |
glBindTexture(GL_TEXTURE_2D, id); |
46 |
|
|
47 |
glBindTexture(GL_TEXTURE_2D, t.id); |
glBindTexture(GL_TEXTURE_2D, t.id); |
48 |
GLERR; |
GLERR; |
49 |
glTexImage2D(GL_TEXTURE_2D, 0, |
glTexImage2D(GL_TEXTURE_2D, level, |
50 |
GL_RGB, |
GL_RGB, |
51 |
w, h, 0, |
w, h, 0, |
52 |
GL_RGB, |
GL_RGB, |
56 |
|
|
57 |
level++; |
level++; |
58 |
|
|
|
// XXX: bordering the lower LOD's does not seem to work |
|
|
break; |
|
|
|
|
59 |
if (w <= 1 && h <= 1) break; |
if (w <= 1 && h <= 1) break; |
60 |
h = h+1>>1; |
h = h+1>>1; |
61 |
w = w+1>>1; |
w = w+1>>1; |
62 |
} |
} |
|
|
|
63 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
64 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, level - 1); |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, level - 1); |
65 |
GLERR; |
GLERR; |
66 |
|
|
67 |
|
delete[] data; |
68 |
|
|
69 |
|
#else |
70 |
|
/* This version uses the OpenGL texture border feature */ |
71 |
|
/* XXX: At least on NV1X, does not seem to work with |
72 |
|
GENERATE_MIPMAP_SGIS and with only one LOD seems very |
73 |
|
slow, probably emulated */ |
74 |
|
|
75 |
|
float *olddata = new float[w*h*c]; |
76 |
|
float *data = new float[(w+2)*(h+2)*c]; |
77 |
|
|
78 |
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, olddata); |
79 |
|
GLERR; |
80 |
|
|
81 |
|
|
82 |
|
int ind = 0; |
83 |
|
for (int j = 0; j < h+2; j++) |
84 |
|
for (int i = 0; i < w+2; i++) |
85 |
|
for (int a = 0; a < c; a++) |
86 |
|
data[(j * (w+2) + i) * c + a] = |
87 |
|
(i == 0 || i == w - 1 || j == 0 || j == h - 1) ? |
88 |
|
bordercolor : olddata[ind++]; |
89 |
|
|
90 |
|
glBindTexture(GL_TEXTURE_2D, t.id); |
91 |
|
GLERR; |
92 |
|
#if 0 |
93 |
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); |
94 |
|
#else |
95 |
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); |
96 |
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); |
97 |
|
#endif |
98 |
|
GLERR; |
99 |
|
|
100 |
|
glTexImage2D(GL_TEXTURE_2D, 0, |
101 |
|
GL_RGB, |
102 |
|
w+2, h+2, 1, |
103 |
|
GL_RGB, |
104 |
|
GL_FLOAT, |
105 |
|
data); |
106 |
|
GLERR; |
107 |
|
|
108 |
|
delete[] olddata; |
109 |
|
delete[] data; |
110 |
|
|
111 |
|
#endif |
112 |
|
|
113 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
114 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |