Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
a7340b9a
Commit
a7340b9a
authored
Jun 03, 2014
by
Janis Born
Browse files
add convertTextureData function
parent
6d348769
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/OpenGL/Data/TextureData.hh
View file @
a7340b9a
...
...
@@ -143,6 +143,11 @@ private:
ACGL_SMARTPOINTER_TYPEDEFS
(
TextureData
)
//! Converts the texture data in _from to the target format and type given in
//! _to. Overwrites width, height, and depth in _to. Old texture data is removed
//! and new memory is allocated.
void
convertTextureData
(
const
SharedTextureData
&
_from
,
const
SharedTextureData
&
_to
);
}
// OpenGL
}
// ACGL
...
...
src/ACGL/OpenGL/Data/TextureData.cc
View file @
a7340b9a
...
...
@@ -7,8 +7,8 @@
#include <ACGL/OpenGL/Data/TextureData.hh>
#include <ACGL/Utils/Memory.hh>
using
namespace
ACGL
;
using
namespace
ACGL
::
OpenGL
;
namespace
ACGL
{
namespace
OpenGL
{
GLsizei
TextureData
::
getPackAlignment
()
const
{
...
...
@@ -304,3 +304,74 @@ void TextureData::setTexel( glm::uvec2 _texCoord, glm::vec4 _color )
}
}
float
grayscaleMixdown
(
float
_r
,
float
_g
,
float
_b
)
{
return
0.299
f
*
_r
+
0.587
f
*
_g
+
0.114
f
*
_b
;
}
glm
::
vec4
convertTexelNumChannels
(
glm
::
vec4
_texel
,
GLsizei
_from
,
GLsizei
_to
)
{
if
(
_from
==
_to
)
{
return
_texel
;
}
else
if
(
_from
==
1
)
{
switch
(
_to
)
{
case
2
:
return
{
_texel
.
r
,
1.0
,
0.0
,
0.0
};
case
3
:
return
{
_texel
.
r
,
_texel
.
r
,
_texel
.
r
,
0.0
};
case
4
:
return
{
_texel
.
r
,
_texel
.
r
,
_texel
.
r
,
1.0
};
}
}
else
if
(
_from
==
2
)
{
switch
(
_to
)
{
case
1
:
return
{
_texel
.
r
,
0.0
,
0.0
,
0.0
};
case
3
:
return
{
_texel
.
r
,
_texel
.
r
,
_texel
.
r
,
_texel
.
g
};
case
4
:
return
{
_texel
.
r
,
_texel
.
r
,
_texel
.
r
,
_texel
.
g
};
}
}
else
if
(
_from
==
3
)
{
switch
(
_to
)
{
case
1
:
return
{
grayscaleMixdown
(
_texel
.
r
,
_texel
.
g
,
_texel
.
b
),
0.0
,
0.0
,
0.0
};
case
2
:
return
{
grayscaleMixdown
(
_texel
.
r
,
_texel
.
g
,
_texel
.
b
),
1.0
,
0.0
,
0.0
};
case
4
:
return
{
_texel
.
r
,
_texel
.
r
,
_texel
.
r
,
1.0
};
}
}
else
if
(
_from
==
4
)
{
switch
(
_to
)
{
case
1
:
return
{
grayscaleMixdown
(
_texel
.
r
,
_texel
.
g
,
_texel
.
b
),
0.0
,
0.0
,
0.0
};
case
2
:
return
{
grayscaleMixdown
(
_texel
.
r
,
_texel
.
g
,
_texel
.
b
),
1.0
,
0.0
,
0.0
};
case
3
:
return
{
_texel
.
r
,
_texel
.
r
,
_texel
.
r
,
0.0
};
}
}
return
_texel
;
}
void
convertTextureData
(
const
SharedTextureData
&
_from
,
const
SharedTextureData
&
_to
)
{
assert
(
_from
);
assert
(
_to
);
if
(
!
_from
->
getData
())
{
ACGL
::
Utils
::
error
()
<<
"Cannot convert TextureData: source TextureData contains no data"
<<
std
::
endl
;
return
;
}
// Setup target texture dimensions
_to
->
setWidth
(
_from
->
getWidth
());
_to
->
setHeight
(
_from
->
getHeight
());
_to
->
setDepth
(
_from
->
getDepth
());
// Allocate new memory
_to
->
deleteData
();
GLubyte
*
data
=
new
GLubyte
[
_to
->
getSizeInBytes
()];
_to
->
setData
(
data
);
// Transfer pixels
for
(
GLsizei
y
=
0
;
y
<
_to
->
getHeight
();
++
y
)
{
for
(
GLsizei
x
=
0
;
x
<
_to
->
getWidth
();
++
x
)
{
auto
texel
=
convertTexelNumChannels
(
_from
->
getTexel
({
x
,
y
}),
_from
->
getNumberOfChannels
(),
_to
->
getNumberOfChannels
());
_to
->
setTexel
({
x
,
y
},
texel
);
}
}
}
}
// namespace OpenGL
}
// namespace ACGL
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