Skip to content

Commit 751a578

Browse files
committed
glTexture: Implement 3D texture loading.
1 parent 8868b30 commit 751a578

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

src/Layers/xrRenderPC_GL/glTexture.cpp

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
6868
{
6969
GLuint pTexture = 0;
7070
string_path fn;
71-
u32 dwWidth, dwHeight;
71+
u32 dwWidth, dwHeight, dwDepth;
7272
u32 img_size = 0;
7373
int img_loaded_lod = 0;
7474
gli::gl::format fmt;
@@ -82,8 +82,7 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
8282
strcpy_s(fname,fRName); //. andy if (strext(fname)) *strext(fname)=0;
8383
fix_texture_name (fname);
8484
IReader* S = NULL;
85-
// TODO: OGL: Implement bump mapping.
86-
//if (!FS.exist(fn,"$game_textures$", fname, ".dds") && strstr(fname,"_bump")) goto _BUMP_from_base;
85+
if (!FS.exist(fn,"$game_textures$", fname, ".dds") && strstr(fname,"_bump")) goto _BUMP_from_base;
8786
if (FS.exist(fn,"$level$", fname, ".dds")) goto _DDS;
8887
if (FS.exist(fn,"$game_saves$", fname, ".dds")) goto _DDS;
8988
if (FS.exist(fn,"$game_textures$", fname, ".dds")) goto _DDS;
@@ -114,6 +113,7 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
114113
gli::texture Texture = gli::load((char*)S->pointer(), img_size);
115114
R_ASSERT(!Texture.empty());
116115
if (gli::is_target_cube(Texture.target())) goto _DDS_CUBE;
116+
if (Texture.target() == gli::TARGET_3D) goto _DDS_3D;
117117
else goto _DDS_2D;
118118

119119
_DDS_CUBE:
@@ -122,6 +122,7 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
122122
mip_cnt = Texture.levels();
123123
dwWidth = Texture.dimensions().x;
124124
dwHeight = Texture.dimensions().y;
125+
dwDepth = Texture.dimensions().z;
125126
fmt = GL.translate(Texture.format());
126127

127128
glGenTextures(1, &pTexture);
@@ -150,6 +151,43 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
150151
ret_desc = GL_TEXTURE_CUBE_MAP;
151152
return pTexture;
152153
}
154+
_DDS_3D:
155+
{
156+
// Check for LMAP and compress if needed
157+
strlwr(fn);
158+
159+
160+
// Load SYS-MEM-surface, bound to device restrictions
161+
gli::gl GL;
162+
mip_cnt = Texture.levels();
163+
dwWidth = Texture.dimensions().x;
164+
dwHeight = Texture.dimensions().y;
165+
dwDepth = Texture.dimensions().z;
166+
fmt = GL.translate(Texture.format());
167+
168+
glGenTextures(1, &pTexture);
169+
glBindTexture(GL_TEXTURE_3D, pTexture);
170+
CHK_GL(glTexStorage3D(GL_TEXTURE_3D, mip_cnt, (GLenum)fmt.Internal, dwWidth, dwHeight, dwDepth));
171+
for (size_t i = 0; i < mip_cnt; i++)
172+
{
173+
if (gli::is_compressed(Texture.format()))
174+
{
175+
CHK_GL(glCompressedTexSubImage3D(GL_TEXTURE_3D, i, 0, 0, 0, Texture.dimensions(i).x, Texture.dimensions(i).y, Texture.dimensions(i).z,
176+
(GLenum)fmt.Internal, Texture.size(i), Texture.data(0, 0, i)));
177+
}
178+
else {
179+
CHK_GL(glTexSubImage3D(GL_TEXTURE_3D, i, 0, 0, 0, Texture.dimensions(i).x, Texture.dimensions(i).y, Texture.dimensions(i).z,
180+
(GLenum)fmt.External, (GLenum)fmt.Type, Texture.data(0, 0, i)));
181+
}
182+
}
183+
FS.r_close(S);
184+
185+
// OK
186+
img_loaded_lod = get_texture_load_lod(fn);
187+
ret_msize = calc_texture_size(img_loaded_lod, mip_cnt, img_size);
188+
ret_desc = GL_TEXTURE_3D;
189+
return pTexture;
190+
}
153191
_DDS_2D:
154192
{
155193
// Check for LMAP and compress if needed
@@ -161,6 +199,7 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
161199
mip_cnt = Texture.levels();
162200
dwWidth = Texture.dimensions().x;
163201
dwHeight = Texture.dimensions().y;
202+
dwDepth = Texture.dimensions().z;
164203
fmt = GL.translate(Texture.format());
165204

166205
glGenTextures(1, &pTexture);
@@ -187,4 +226,32 @@ GLuint CRender::texture_load(LPCSTR fRName, u32& ret_msize, GLenum& ret_desc)
187226
return pTexture;
188227
}
189228
}
229+
230+
_BUMP_from_base:
231+
{
232+
//Msg ("! auto-generated bump map: %s",fname);
233+
Msg ("! Fallback to default bump map: %s",fname);
234+
//////////////////
235+
if (strstr(fname,"_bump#"))
236+
{
237+
R_ASSERT2 (FS.exist(fn,"$game_textures$", "ed\\ed_dummy_bump#", ".dds"), "ed_dummy_bump#");
238+
S = FS.r_open (fn);
239+
R_ASSERT2 (S, fn);
240+
img_size = S->length ();
241+
goto _DDS;
242+
}
243+
if (strstr(fname,"_bump"))
244+
{
245+
R_ASSERT2 (FS.exist(fn,"$game_textures$", "ed\\ed_dummy_bump", ".dds"),"ed_dummy_bump");
246+
S = FS.r_open (fn);
247+
248+
R_ASSERT2 (S, fn);
249+
250+
img_size = S->length ();
251+
goto _DDS;
252+
}
253+
//////////////////
254+
}
255+
256+
return 0;
190257
}

0 commit comments

Comments
 (0)