Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
806024f4
Commit
806024f4
authored
Nov 13, 2016
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
faster method for texture handling
parent
0f379ba0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
51 deletions
+74
-51
MshViewer/Header/Object.h
MshViewer/Header/Object.h
+2
-1
MshViewer/Source/Object.cpp
MshViewer/Source/Object.cpp
+25
-10
MshViewer/Source/OpenGlController.cpp
MshViewer/Source/OpenGlController.cpp
+47
-40
No files found.
MshViewer/Header/Object.h
View file @
806024f4
...
...
@@ -21,7 +21,7 @@ struct ChunkHeader {
};
struct
Segment
{
std
::
string
texture
=
""
;
std
::
uint32_t
textureIndex
=
0
;
float
*
vertex
=
nullptr
;
float
*
uv
=
nullptr
;
std
::
uint32_t
*
mesh
=
nullptr
;
...
...
@@ -65,5 +65,6 @@ private:
public:
std
::
vector
<
Modl
*>
getModels
()
const
;
std
::
vector
<
std
::
string
>
getTextureList
()
const
;
};
MshViewer/Source/Object.cpp
View file @
806024f4
...
...
@@ -393,15 +393,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
if
(
!
strcmp
(
"MATI"
,
(
*
it
)
->
name
))
{
fsMesh
.
seekg
((
*
it
)
->
position
);
std
::
uint32_t
tempIndex
;
fsMesh
.
read
(
reinterpret_cast
<
char
*>
(
&
tempIndex
),
sizeof
(
tempIndex
));
if
(
vTextures
.
size
()
<=
tempIndex
)
{
std
::
cout
<<
"warning texture index <"
<<
tempIndex
<<
"> unknown"
<<
std
::
endl
;
tempData
->
texture
=
""
;
continue
;
}
tempData
->
texture
=
vTextures
[
tempIndex
];
fsMesh
.
read
(
reinterpret_cast
<
char
*>
(
&
tempData
->
textureIndex
),
sizeof
(
tempData
->
textureIndex
));
continue
;
}
...
...
@@ -471,7 +463,25 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
char
*
buffer
=
new
char
[(
*
it
)
->
size
];
*
buffer
=
{
0
};
fsMesh
.
read
(
buffer
,
(
*
it
)
->
size
);
tempData
->
texture
=
buffer
;
bool
tempFound
(
false
);
for
(
unsigned
int
index
=
0
;
index
<
vTextures
.
size
();
index
++
)
{
if
(
!
strcmp
(
buffer
,
vTextures
[
index
].
c_str
()))
{
tempData
->
textureIndex
=
index
;
tempFound
=
true
;
break
;
}
}
if
(
!
tempFound
)
{
vTextures
.
push_back
(
std
::
string
(
buffer
));
tempData
->
textureIndex
=
vTextures
.
size
()
-
1
;
}
delete
buffer
;
continue
;
}
...
...
@@ -540,6 +550,11 @@ std::vector<Modl*> Object::getModels() const
return
vModls
;
}
std
::
vector
<
std
::
string
>
Object
::
getTextureList
()
const
{
return
vTextures
;
}
/////////////////////////////////////////////////////////////////////////
// public functions
...
...
MshViewer/Source/OpenGlController.cpp
View file @
806024f4
...
...
@@ -302,7 +302,6 @@ void OpenGLController::updateScene()
glUniform1i
(
gluiSamplerID
,
0
);
int
instanceOffset
(
0
);
int
textureIndex
(
0
);
for
(
unsigned
int
modelIndex
=
0
;
modelIndex
<
vModels
.
size
();
modelIndex
++
)
{
...
...
@@ -316,16 +315,18 @@ void OpenGLController::updateScene()
for
(
auto
&
segIt
:
vModels
[
modelIndex
]
->
segmLst
)
{
// give texture to the shader
std
::
uint32_t
tempTexIndex
=
segIt
->
textureIndex
>=
vTextures
.
size
()
?
vTextures
.
size
()
-
1
:
segIt
->
textureIndex
;
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
vTextures
[
te
xture
Index
]
->
alpha
?
GL_RGBA
:
GL_RGB
,
vTextures
[
te
xture
Index
]
->
width
,
vTextures
[
te
xture
Index
]
->
height
,
vTextures
[
te
mpTex
Index
]
->
alpha
?
GL_RGBA
:
GL_RGB
,
vTextures
[
te
mpTex
Index
]
->
width
,
vTextures
[
te
mpTex
Index
]
->
height
,
0
,
vTextures
[
te
xture
Index
]
->
alpha
?
GL_BGRA
:
GL_BGR
,
vTextures
[
te
mpTex
Index
]
->
alpha
?
GL_BGRA
:
GL_BGR
,
GL_UNSIGNED_BYTE
,
vTextures
[
te
xture
Index
]
->
data
->
data
()
vTextures
[
te
mpTex
Index
]
->
data
->
data
()
);
glGenerateMipmap
(
GL_TEXTURE_2D
);
...
...
@@ -335,9 +336,8 @@ void OpenGLController::updateScene()
glDrawArrays
(
GL_TRIANGLES
,
instanceOffset
,
segIt
->
meshSize
);
//
recalulate counter
//
increase the offset
instanceOffset
+=
segIt
->
meshSize
;
textureIndex
++
;
}
}
...
...
@@ -350,11 +350,14 @@ void OpenGLController::loadMsh(const char * path)
// clean up old stuff first
deleteVectors
();
std
::
vector
<
std
::
string
>
tempTexList
;
// get all models
try
{
Object
obj
(
path
);
vModels
=
obj
.
getModels
();
tempTexList
=
obj
.
getTextureList
();
}
catch
(
std
::
invalid_argument
e
)
{
...
...
@@ -407,42 +410,46 @@ void OpenGLController::loadMsh(const char * path)
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
// get textures
for
(
auto
&
modIt
:
vModels
)
{
// we don't need textures from null, bones, shadowMesh and hidden things, since they are not displayed
if
(
modIt
->
type
==
null
||
modIt
->
type
==
bone
||
modIt
->
type
==
shadowMesh
||
modIt
->
renderFlags
==
1
)
continue
;
for
(
auto
&
segIt
:
modIt
->
segmLst
)
{
textureData
*
tempData
=
new
textureData
;
try
{
if
(
segIt
->
texture
==
""
)
throw
std
::
invalid_argument
(
"no texture name"
);
std
::
string
tempPath
=
path
;
// get textures path
std
::
string
tempPath
=
path
;
while
(
tempPath
.
back
()
!=
'/'
&&
tempPath
.
back
()
!=
'\\'
)
tempPath
.
pop_back
();
while
(
tempPath
.
back
()
!=
'/'
&&
tempPath
.
back
()
!=
'\\'
)
tempPath
.
pop_back
();
TextureTGA
tempTex
(
std
::
string
(
tempPath
+
segIt
->
texture
).
c_str
());
// load all textures;
for
(
auto
&
texIt
:
tempTexList
)
{
textureData
*
tempData
=
new
textureData
;
tempData
->
alpha
=
tempTex
.
hasAlpha
();
tempData
->
width
=
tempTex
.
getWidth
();
tempData
->
height
=
tempTex
.
getHeight
();
tempData
->
data
=
new
std
::
vector
<
std
::
uint8_t
>
(
tempTex
.
getData
());
}
catch
(
std
::
invalid_argument
e
)
{
GLubyte
solidColor
[
4
]
=
{
0
,
0
,
255
,
255
};
tempData
->
alpha
=
true
;
tempData
->
width
=
1
;
tempData
->
height
=
1
;
tempData
->
data
=
new
std
::
vector
<
std
::
uint8_t
>
({
0
,
0
,
255
,
255
});
}
try
{
TextureTGA
tempTex
(
std
::
string
(
tempPath
+
texIt
).
c_str
());
vTextures
.
push_back
(
tempData
);
tempData
->
alpha
=
tempTex
.
hasAlpha
();
tempData
->
width
=
tempTex
.
getWidth
();
tempData
->
height
=
tempTex
.
getHeight
();
tempData
->
data
=
new
std
::
vector
<
std
::
uint8_t
>
(
tempTex
.
getData
());
}
catch
(
std
::
invalid_argument
e
)
{
GLubyte
solidColor
[
4
]
=
{
0
,
0
,
255
,
255
};
tempData
->
alpha
=
true
;
tempData
->
width
=
1
;
tempData
->
height
=
1
;
tempData
->
data
=
new
std
::
vector
<
std
::
uint8_t
>
({
0
,
0
,
255
,
255
});
}
vTextures
.
push_back
(
tempData
);
}
// add a solid default color at the end (maybe there is an invalid index later)
textureData
*
tempData
=
new
textureData
;
GLubyte
solidColor
[
4
]
=
{
0
,
0
,
255
,
255
};
tempData
->
alpha
=
true
;
tempData
->
width
=
1
;
tempData
->
height
=
1
;
tempData
->
data
=
new
std
::
vector
<
std
::
uint8_t
>
({
0
,
0
,
255
,
255
});
vTextures
.
push_back
(
tempData
);
tempTexList
.
clear
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment