Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
acgl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ACGL
acgl
Commits
67d811a3
Commit
67d811a3
authored
Feb 17, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more simple texture data load/save functions and a screenshot function
parent
b280d4b7
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
278 additions
and
70 deletions
+278
-70
include/ACGL/OpenGL/Controller/FrameBufferObjectControl.hh
include/ACGL/OpenGL/Controller/FrameBufferObjectControl.hh
+3
-3
include/ACGL/OpenGL/Controller/TextureControl.hh
include/ACGL/OpenGL/Controller/TextureControl.hh
+4
-0
include/ACGL/OpenGL/Controller/TextureControlCubeMap.hh
include/ACGL/OpenGL/Controller/TextureControlCubeMap.hh
+4
-0
include/ACGL/OpenGL/Controller/TextureControlFile.hh
include/ACGL/OpenGL/Controller/TextureControlFile.hh
+4
-0
include/ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh
include/ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh
+4
-0
include/ACGL/OpenGL/Controller/TextureDataControlFilePNG.hh
include/ACGL/OpenGL/Controller/TextureDataControlFilePNG.hh
+4
-0
include/ACGL/OpenGL/Controller/TextureDataControlFilePNM.hh
include/ACGL/OpenGL/Controller/TextureDataControlFilePNM.hh
+4
-0
include/ACGL/OpenGL/Data/TextureDataLoadStore.hh
include/ACGL/OpenGL/Data/TextureDataLoadStore.hh
+57
-3
include/ACGL/OpenGL/HiLevelObjects/Uniform.hh
include/ACGL/OpenGL/HiLevelObjects/Uniform.hh
+2
-3
include/ACGL/OpenGL/Managers.hh
include/ACGL/OpenGL/Managers.hh
+2
-0
include/ACGL/OpenGL/Objects/FrameBufferObject.hh
include/ACGL/OpenGL/Objects/FrameBufferObject.hh
+7
-3
include/ACGL/OpenGL/Objects/ShaderProgram.hh
include/ACGL/OpenGL/Objects/ShaderProgram.hh
+3
-0
include/ACGL/OpenGL/Objects/Texture.hh
include/ACGL/OpenGL/Objects/Texture.hh
+2
-2
src/ACGL/OpenGL/Controller/TextureControlCubeMap.cc
src/ACGL/OpenGL/Controller/TextureControlCubeMap.cc
+3
-0
src/ACGL/OpenGL/Controller/TextureControlFile.cc
src/ACGL/OpenGL/Controller/TextureControlFile.cc
+4
-0
src/ACGL/OpenGL/Controller/TextureDataControlFileJPG.cc
src/ACGL/OpenGL/Controller/TextureDataControlFileJPG.cc
+4
-0
src/ACGL/OpenGL/Controller/TextureDataControlFilePNG.cc
src/ACGL/OpenGL/Controller/TextureDataControlFilePNG.cc
+4
-0
src/ACGL/OpenGL/Controller/TextureDataControlFilePNM.cc
src/ACGL/OpenGL/Controller/TextureDataControlFilePNM.cc
+4
-0
src/ACGL/OpenGL/Data/TextureDataLoadStore.cc
src/ACGL/OpenGL/Data/TextureDataLoadStore.cc
+144
-55
src/ACGL/OpenGL/InitStaticFileTypes.cc
src/ACGL/OpenGL/InitStaticFileTypes.cc
+2
-1
src/ACGL/OpenGL/Objects/FrameBufferObject.cc
src/ACGL/OpenGL/Objects/FrameBufferObject.cc
+10
-0
src/ACGL/OpenGL/Objects/Texture.cc
src/ACGL/OpenGL/Objects/Texture.cc
+3
-0
No files found.
include/ACGL/OpenGL/Controller/FrameBufferObjectControl.hh
View file @
67d811a3
...
...
@@ -34,7 +34,7 @@ public:
mFragDataLocations
()
{
mDepthAttachment
.
name
=
""
;
mDepthAttachment
.
texture
=
ConstSharedTexture
();
mDepthAttachment
.
texture
=
ConstSharedTexture
Base
();
mDepthAttachment
.
renderBuffer
=
ConstSharedRenderBuffer
();
}
virtual
~
FrameBufferObjectControl
()
{}
...
...
@@ -43,10 +43,10 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline
FrameBufferObjectControl
&
depthTexture
(
const
ConstSharedTexture
&
_pDepthTexture
)
{
mDepthAttachment
.
texture
=
_pDepthTexture
;
return
*
this
;
}
inline
FrameBufferObjectControl
&
depthTexture
(
const
ConstSharedTexture
Base
&
_pDepthTexture
)
{
mDepthAttachment
.
texture
=
_pDepthTexture
;
return
*
this
;
}
inline
FrameBufferObjectControl
&
depthRenderBuffer
(
const
ConstSharedRenderBuffer
&
_pDepthRenderBuffer
)
{
mDepthAttachment
.
renderBuffer
=
_pDepthRenderBuffer
;
return
*
this
;
}
inline
FrameBufferObjectControl
&
colorTexture
(
const
std
::
string
&
_name
,
const
ConstSharedTexture
&
_texture
)
inline
FrameBufferObjectControl
&
colorTexture
(
const
std
::
string
&
_name
,
const
ConstSharedTexture
Base
&
_texture
)
{
FrameBufferObject
::
Attachment
attachment
=
{
_name
,
_texture
,
SharedRenderBuffer
(),
(
GLuint
)
mColorAttachments
.
size
(),
Image
()};
mColorAttachments
.
push_back
(
attachment
);
...
...
include/ACGL/OpenGL/Controller/TextureControl.hh
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
/**
* Can create an empty texture, if a texture should get loaded from a file,
* see TextureControlFile.
...
...
@@ -121,4 +123,6 @@ protected:
}
// OpenGL
}
// ACGL
#endif
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
include/ACGL/OpenGL/Controller/TextureControlCubeMap.hh
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROLCUBEMAP_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROLCUBEMAP_HH
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
/**
* Can set up a cube map out of multiple TextureData objects.
*/
...
...
@@ -107,4 +109,6 @@ protected:
}
// OpenGL
}
// ACGL
#endif
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
include/ACGL/OpenGL/Controller/TextureControlFile.hh
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILE_HH
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
...
...
@@ -83,4 +85,6 @@ protected:
}
// OpenGL
}
// ACGL
#endif
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILE_HH
include/ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEJPG_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEJPG_HH
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
...
...
@@ -45,4 +47,6 @@ ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFileJPG)
}
// OpenGL
}
// ACGL
#endif
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEJPG_HH
include/ACGL/OpenGL/Controller/TextureDataControlFilePNG.hh
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNG_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNG_HH
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
...
...
@@ -45,4 +47,6 @@ ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFilePNG)
}
// OpenGL
}
// ACGL
#endif
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNG_HH
include/ACGL/OpenGL/Controller/TextureDataControlFilePNM.hh
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNM_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNM_HH
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
/**
* A minimal PNM loader (with some bugs). No external dependencies, so this is at least
* one image type that can be loaded without extra libs.
...
...
@@ -61,4 +63,6 @@ ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFilePNM)
}
// OpenGL
}
// ACGL
#endif
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNM_HH
include/ACGL/OpenGL/Data/TextureDataLoadStore.hh
View file @
67d811a3
...
...
@@ -14,20 +14,74 @@
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Data/TextureData.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <string>
namespace
ACGL
{
namespace
OpenGL
{
//! saves to a PPM file
bool
saveTextureDataToPPM
(
const
ConstSharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
);
///////////////////////////////////////////////////////////////////////////////////////////////////
// generic load/save
///////////////////////////////////////////////////////////////////////////////////////////////////
//! generic load function that will use one of the loading functions below based on the file ending
SharedTextureData
loadTextureData
(
const
std
::
string
&
_filename
);
//! generic save function that will use one of the saving functions below based on the file ending
bool
saveTextureData
(
const
SharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
);
//! saves the viewport visible part of the framebuffer 0 to a file named _prefix_DATE-TIME._fileEnding
bool
saveScreenshot
(
const
std
::
string
&
_prefix
=
"screenshot"
,
const
std
::
string
_fileEnding
=
"png"
);
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific load
///////////////////////////////////////////////////////////////////////////////////////////////////
//! loads from a PNG using the simple lodepng library
SharedTextureData
loadTextureDataFromLodepng
(
const
std
::
string
&
_filename
);
#ifdef ACGL_COMPILE_WITH_QT
//! loads from the QT library
SharedTextureData
loadTextureDataFromQT
(
const
std
::
string
&
_filename
);
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
///////////////////////////////////////////////////////////////////////////////////////////////////
//! saves to a PPM file
bool
saveTextureDataToPPM
(
const
SharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
);
//! save to a PNG file with lodepng
bool
saveTextureDataToLodepng
(
SharedTextureData
_data
,
const
std
::
string
&
_filename
);
bool
saveTextureDataToLodepng
(
const
SharedTextureData
&
_data
,
const
std
::
string
&
_filename
);
#ifdef ACGL_COMPILE_WITH_QT
bool
saveTextureDataToQT
(
const
SharedTextureData
&
_data
,
const
std
::
string
&
_filename
);
#endif
// helper for saveTextureDataToLodepng
template
<
typename
T
>
unsigned
char
*
preProcess
(
const
SharedTextureData
&
_data
)
{
unsigned
int
channelCount
=
getNumberOfChannels
(
_data
->
getFormat
()
);
unsigned
int
pixelCount
=
_data
->
getWidth
()
*
_data
->
getHeight
();
T
*
processedrawdata
=
new
T
[
pixelCount
*
channelCount
];
// copy & flip the image:
T
*
originalrawdata
=
(
T
*
)
_data
->
getData
();
for
(
int
i
=
0
;
i
<
_data
->
getHeight
();
++
i
)
{
size_t
srcOffset
=
_data
->
getWidth
()
*
i
*
channelCount
;
size_t
dstOffset
=
_data
->
getWidth
()
*
(
_data
->
getHeight
()
-
i
-
1
)
*
channelCount
;
memcpy
(
processedrawdata
+
dstOffset
,
originalrawdata
+
srcOffset
,
_data
->
getWidth
()
*
channelCount
*
sizeof
(
T
)
);
}
return
(
unsigned
char
*
)
processedrawdata
;
}
}
// OpenGL
}
// ACGL
...
...
include/ACGL/OpenGL/HiLevelObjects/Uniform.hh
View file @
67d811a3
...
...
@@ -206,11 +206,10 @@ public:
ACGL_SMARTPOINTER_TYPEDEFS
(
UniformMatrix4f
)
//=========================
class
UniformTexture
:
public
UniformData
<
ConstSharedTexture
>
class
UniformTexture
:
public
UniformData
<
ConstSharedTextureBase
>
{
public:
UniformTexture
(
void
)
:
UniformData
<
ConstSharedTexture
>
()
{}
UniformTexture
(
void
)
:
UniformData
<
ConstSharedTexture
Base
>
()
{}
virtual
~
UniformTexture
(
void
)
{}
void
apply
(
GLint
_location
,
GLenum
_unit
)
const
{
glUniform1i
(
_location
,
_unit
);
mValue
->
bind
(
_unit
);
}
};
...
...
include/ACGL/OpenGL/Managers.hh
View file @
67d811a3
...
...
@@ -39,8 +39,10 @@ typedef Resource::MultiFileManager<ShaderProgram> ShaderProgramFileManager;
typedef
Resource
::
NameManager
<
ShaderProgramObject
>
ShaderProgramObjectNameManager
;
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
typedef
Resource
::
NameManager
<
Texture
>
TextureNameManager
;
typedef
Resource
::
FileManager
<
Texture
>
TextureFileManager
;
#endif
typedef
Resource
::
NameManager
<
TextureData
>
TextureDataNameManager
;
typedef
Resource
::
FileManager
<
TextureData
>
TextureDataFileManager
;
...
...
include/ACGL/OpenGL/Objects/FrameBufferObject.hh
View file @
67d811a3
...
...
@@ -87,7 +87,7 @@ public:
ACGL
::
Utils
::
error
()
<<
"could not generate FrameBufferObject!"
<<
std
::
endl
;
return
;
}
mDepthAttachment
.
texture
=
ConstSharedTexture
();
mDepthAttachment
.
texture
=
ConstSharedTexture
Base
();
mDepthAttachment
.
renderBuffer
=
ConstSharedRenderBuffer
();
mDepthAttachment
.
name
=
""
;
// not useful here
mDepthAttachment
.
location
=
0
;
// not useful here
...
...
@@ -133,7 +133,7 @@ public:
*/
inline
bool
attachColorRenderBuffer
(
const
std
::
string
&
_name
,
const
ConstSharedRenderBuffer
&
_renderBuffer
)
{
Attachment
a
=
{
_name
,
SharedTexture
(),
_renderBuffer
,
0xFFFFFFFF
,
Image
()};
Attachment
a
=
{
_name
,
SharedTexture
Base
(),
_renderBuffer
,
0xFFFFFFFF
,
Image
()};
return
attachColorAttachment
(
a
);
}
...
...
@@ -145,7 +145,7 @@ public:
inline
bool
attachColorRenderBuffer
(
const
std
::
string
&
_name
,
const
ConstSharedRenderBuffer
&
_renderBuffer
,
GLuint
_location
)
{
Attachment
a
=
{
_name
,
SharedTexture
(),
_renderBuffer
,
_location
,
Image
()};
Attachment
a
=
{
_name
,
SharedTexture
Base
(),
_renderBuffer
,
_location
,
Image
()};
return
attachColorAttachment
(
a
);
}
...
...
@@ -237,8 +237,12 @@ public:
//! returns the current contents of the default FrameBuffer
//! the format of the returned TextureData will be GL_RGB, the type will be GL_UNSIGNED_INT
//! _readBuffer = GL_INVALID_ENUM will read out the default read buffer
static
SharedTextureData
getImageData
(
GLsizei
_width
,
GLsizei
_height
,
GLint
_x
=
0
,
GLint
_y
=
0
,
GLenum
_readBuffer
=
GL_INVALID_ENUM
);
//! get the part of the framebuffer thats part of the current viewport
static
SharedTextureData
getImageData
();
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
...
...
include/ACGL/OpenGL/Objects/ShaderProgram.hh
View file @
67d811a3
...
...
@@ -238,6 +238,8 @@ public:
//! sets a texture uniform to a given texture unit and also binds the texture to the same unit
inline
void
setTexture
(
GLint
_location
,
const
ConstSharedTextureBase
&
_texture
,
GLint
_unit
)
const
{
glUniform1i
(
_location
,
_unit
);
_texture
->
bind
(
_unit
);
}
inline
void
setTexture
(
const
std
::
string
&
_nameInShader
,
const
ConstSharedTextureBase
&
_texture
,
GLint
_unit
)
const
{
setUniform
(
getUniformLocation
(
_nameInShader
),
(
GLint
)
_unit
);
_texture
->
bind
(
_unit
);
}
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
//! set the texture to the texture unit the uniform is set to.
//! Note: it is not guaranteed that all uniforms for textures are set to unique samplers by default after linking!
void
setTexture
(
const
std
::
string
&
_nameInShader
,
const
ConstSharedTexture
&
_texture
)
const
{
...
...
@@ -248,6 +250,7 @@ public:
_texture
->
bind
(
unit
);
}
}
#endif
#if (ACGL_OPENGL_VERSION >= 41)
// DSA versions:
...
...
include/ACGL/OpenGL/Objects/Texture.hh
View file @
67d811a3
...
...
@@ -438,7 +438,7 @@ ACGL_SMARTPOINTER_TYPEDEFS(TextureCubeMap)
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
//
// Full compatibility with the old Texture class:
//
...
...
@@ -729,7 +729,7 @@ private:
};
ACGL_SMARTPOINTER_TYPEDEFS
(
Texture
)
#endif
}
// OpenGL
}
// ACGL
...
...
src/ACGL/OpenGL/Controller/TextureControlCubeMap.cc
View file @
67d811a3
...
...
@@ -4,6 +4,8 @@
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#include <ACGL/OpenGL/Controller/TextureControlCubeMap.hh>
using
namespace
ACGL
::
Utils
;
...
...
@@ -108,3 +110,4 @@ SharedTexture TextureControlCubeMap::create(void)
return
texture
;
}
#endif
src/ACGL/OpenGL/Controller/TextureControlFile.cc
View file @
67d811a3
...
...
@@ -4,6 +4,8 @@
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#include <ACGL/OpenGL/Controller/TextureControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
...
...
@@ -101,3 +103,5 @@ bool TextureControlFile::update(SharedTexture& texture)
updateFileModificationTime
();
return
true
;
}
#endif
src/ACGL/OpenGL/Controller/TextureDataControlFileJPG.cc
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#include <ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#ifdef ACGL_COMPILE_WITH_QT
#include <QtGui/QImage>
#include <QtOpenGL/QGLWidget>
...
...
@@ -45,3 +47,5 @@ int_t TextureDataControlFileJPG::registerType(void)
sTypeID
=
TextureDataControlFileFactory
::
the
()
->
registerType
(
"jpg"
,
&
TextureDataControlFileJPG
::
creator
);
return
sTypeID
;
}
#endif
src/ACGL/OpenGL/Controller/TextureDataControlFilePNG.cc
View file @
67d811a3
...
...
@@ -7,6 +7,8 @@
#include <ACGL/OpenGL/Controller/TextureDataControlFilePNG.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#ifdef ACGL_COMPILE_WITH_QT
#include <QtGui/QImage>
#include <QtOpenGL/QGLWidget>
...
...
@@ -45,3 +47,5 @@ int_t TextureDataControlFilePNG::registerType(void)
sTypeID
=
TextureDataControlFileFactory
::
the
()
->
registerType
(
"png"
,
&
TextureDataControlFilePNG
::
creator
);
return
sTypeID
;
}
#endif
src/ACGL/OpenGL/Controller/TextureDataControlFilePNM.cc
View file @
67d811a3
...
...
@@ -4,6 +4,8 @@
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#ifdef ACGL_INCLUDE_DEPRECATED_FUNCTIONALITY
#include <ACGL/OpenGL/Controller/TextureDataControlFilePNM.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
#include <ACGL/OpenGL/Tools.hh>
...
...
@@ -215,3 +217,5 @@ int_t TextureDataControlFilePNM::registerType(void)
sTypeID
=
TextureDataControlFileFactory
::
the
()
->
registerType
(
"ppm"
,
&
TextureDataControlFilePNM
::
creator
);
return
sTypeID
;
}
#endif
src/ACGL/OpenGL/Data/TextureDataLoadStore.cc
View file @
67d811a3
...
...
@@ -6,6 +6,12 @@
#include <ACGL/OpenGL/Data/TextureDataLoadStore.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Base/FileHelpers.hh>
// for the screenshot function:
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include <cstdio>
#include <ctime>
#include <fstream>
#include "lodepng/lodepng.h"
...
...
@@ -17,61 +23,74 @@ using namespace ACGL::Utils;
namespace
ACGL
{
namespace
OpenGL
{
bool
saveTextureDataToPPM
(
const
ConstSharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
)
{
if
(
_textureData
->
getFormat
()
!=
GL_RGB
)
{
error
()
<<
"saveTextureDataToPPM: Unsupported texture format, must be GL_RGB"
<<
std
::
endl
;
return
false
;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// generic load/save
///////////////////////////////////////////////////////////////////////////////////////////////////
std
::
ofstream
outFileStream
(
_filename
.
c_str
(),
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
);
SharedTextureData
loadTextureData
(
const
std
::
string
&
_filename
)
{
// lower case file ending:
std
::
string
fileEnding
=
Base
::
FileHelpers
::
getFileEnding
(
_filename
);
if
(
!
outFileStream
.
good
())
{
error
()
<<
"saveTextureDataToPPM: Could not open file "
<<
_filename
<<
std
::
endl
;
return
false
;
if
(
fileEnding
==
"png"
)
{
return
loadTextureDataFromLodepng
(
_filename
);
}
#ifdef ACGL_COMPILE_WITH_QT
else
if
(
fileEnding
==
"bmp"
||
fileEnding
==
"jpg"
||
fileEnding
==
"jpeg"
||
fileEnding
==
"png"
||
fileEnding
==
"pbm"
||
fileEnding
==
"ppm"
||
fileEnding
==
"tif"
||
fileEnding
==
"tiff"
||
fileEnding
==
"xbm"
||
fileEnding
==
"xpm"
||
fileEnding
==
"pgm"
)
{
return
loadTextureDataFromQT
(
_filename
);
}
#endif
else
{
error
()
<<
"file format of "
<<
_filename
<<
" not supported"
<<
std
::
endl
;
}
// Use the binary-encoded RGB texture format
outFileStream
<<
"P6"
<<
std
::
endl
;
return
SharedTextureData
();
}
// Width and height
outFileStream
<<
_textureData
->
getWidth
()
<<
" "
<<
_textureData
->
getHeight
()
<<
std
::
endl
;
bool
saveTextureData
(
const
SharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
)
{
// lower case file ending:
std
::
string
fileEnding
=
Base
::
FileHelpers
::
getFileEnding
(
_filename
);
// Maximum value
uint_t
maxValue
;
if
(
_textureData
->
getType
()
==
GL_UNSIGNED_BYTE
)
{
maxValue
=
255
;
if
(
fileEnding
==
"png"
)
{
return
saveTextureDataToLodepng
(
_textureData
,
_filename
);
}
else
{
error
()
<<
"saveTextureDataToPPM: Unsupported texture type, must be GL_UNSIGNED_BYTE"
<<
std
::
endl
;
return
false
;
#ifdef ACGL_COMPILE_WITH_QT
else
if
(
fileEnding
==
"bmp"
||
fileEnding
==
"jpg"
||
fileEnding
==
"jpeg"
||
fileEnding
==
"png"
||
fileEnding
==
"ppm"
||
fileEnding
==
"tif"
||
fileEnding
==
"tiff"
||
fileEnding
==
"xbm"
||
fileEnding
==
"xpm"
)
{
return
saveTextureDataToQT
(
_textureData
,
_filename
);
}
#endif
else
if
(
fileEnding
==
"ppm"
)
{
return
saveTextureDataToPPM
(
_textureData
,
_filename
);
}
else
{
error
()
<<
"file format of "
<<
_filename
<<
" not supported"
<<
std
::
endl
;
}
outFileStream
<<
maxValue
;
// Single whitespace as a delimiter
outFileStream
<<
"
\n
"
;
return
false
;
}
// Now, write the image data in binary format
for
(
GLsizei
y
=
0
;
y
<
_textureData
->
getHeight
();
++
y
)
{
for
(
GLsizei
x
=
0
;
x
<
_textureData
->
getWidth
();
++
x
)
{
GLsizei
i
=
((
_textureData
->
getHeight
()
-
y
-
1
)
*
_textureData
->
getWidth
())
+
x
;
outFileStream
.
put
(
_textureData
->
getData
()[(
3
*
i
+
0
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
outFileStream
.
put
(
_textureData
->
getData
()[(
3
*
i
+
1
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
outFileStream
.
put
(
_textureData
->
getData
()[(
3
*
i
+
2
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
}
}
bool
saveScreenshot
(
const
std
::
string
&
_prefix
,
const
std
::
string
_fileEnding
)
{
time_t
rawtime
;
time
(
&
rawtime
);
outFileStream
.
close
();
return
true
;
char
timestring
[
30
];
strftime
(
timestring
,
30
,
"_%Y-%m-%d_%H-%M-%S"
,
localtime
(
&
rawtime
)
);
std
::
string
filename
=
_prefix
+
timestring
+
"."
+
_fileEnding
;
return
ACGL
::
OpenGL
::
saveTextureData
(
FrameBufferObject
::
getImageData
(),
filename
);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific load
///////////////////////////////////////////////////////////////////////////////////////////////////
SharedTextureData
loadTextureDataFromLodepng
(
const
std
::
string
&
_filename
)
{
...
...
@@ -149,29 +168,92 @@ SharedTextureData loadTextureDataFromLodepng(const std::string &_filename)
return
data
;
}
// helper for saveTextureDataToLodepng
template
<
typename
T
>
unsigned
char
*
preProcess
(
SharedTextureData
_data
)
#ifdef ACGL_COMPILE_WITH_QT
//! loads from the QT library
SharedTextureData
loadTextureDataFromQT
(
const
std
::
string
&
_filename
)
{
unsigned
int
channelCount
=
getNumberOfChannels
(
_data
->
getFormat
()
)
;
SharedTextureData
data
;
unsigned
int
pixelCount
=
_data
->
getWidth
()
*
_data
->
getHeight
();
T
*
processedrawdata
=
new
T
[
pixelCount
*
channelCount
];
QImage
image
=
QImage
(
QString
(
_filename
.
c_str
())
);
// copy & flip the image:
T
*
originalrawdata
=
(
T
*
)
_data
->
getData
();
if
(
image
.
isNull
())
{
ACGL
::
Utils
::
error
()
<<
"Loading image "
<<
_filename
<<
" has failed!"
<<
std
::
endl
;
return
data
;
}
for
(
int
i
=
0
;
i
<
_data
->
getHeight
();
++
i
)
{
size_t
srcOffset
=
_data
->
getWidth
()
*
i
*
channelCount
;
size_t
dstOffset
=
_data
->
getWidth
()
*
(
_data
->
getHeight
()
-
i
-
1
)
*
channelCount
;
image
=
QGLWidget
::
convertToGLFormat
(
image
);
GLubyte
*
pImageData
=
new
GLubyte
[
image
.
byteCount
()];
memcpy
(
pImageData
,
image
.
bits
(),
image
.
byteCount
());
data
->
setData
(
pImageData
);
data
->
setWidth
(
image
.
width
()
);
data
->
setHeight
(
image
.
height
()
);
memcpy
(
processedrawdata
+
dstOffset
,
originalrawdata
+
srcOffset
,
_data
->
getWidth
()
*
channelCount
*
sizeof
(
T
)
);
return
data
;
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
///////////////////////////////////////////////////////////////////////////////////////////////////
bool
saveTextureDataToPPM
(
const
SharedTextureData
&
_textureData
,
const
std
::
string
&
_filename
)
{
if
(
_textureData
->
getFormat
()
!=
GL_RGB
)
{
error
()
<<
"saveTextureDataToPPM: Unsupported texture format, must be GL_RGB"
<<
std
::
endl
;
return
false
;
}
std
::
ofstream
outFileStream
(
_filename
.
c_str
(),
std
::
ios_base
::
out
|
std
::
ios_base
::
binary
);
if
(
!
outFileStream
.
good
())
{
error
()
<<
"saveTextureDataToPPM: Could not open file "
<<
_filename
<<
std
::
endl
;
return
false
;
}
// Use the binary-encoded RGB texture format
outFileStream
<<
"P6"
<<
std
::
endl
;
// Width and height
outFileStream
<<
_textureData
->
getWidth
()
<<
" "
<<
_textureData
->
getHeight
()
<<
std
::
endl
;
// Maximum value
uint_t
maxValue
;
if
(
_textureData
->
getType
()
==
GL_UNSIGNED_BYTE
)
{
maxValue
=
255
;
}
else
{
error
()
<<
"saveTextureDataToPPM: Unsupported texture type, must be GL_UNSIGNED_BYTE"
<<
std
::
endl
;
return
false
;
}
outFileStream
<<
maxValue
;
// Single whitespace as a delimiter
outFileStream
<<
"
\n
"
;
// Now, write the image data in binary format
for
(
GLsizei
y
=
0
;
y
<
_textureData
->
getHeight
();
++
y
)
{
for
(
GLsizei
x
=
0
;
x
<
_textureData
->
getWidth
();
++
x
)
{
GLsizei
i
=
((
_textureData
->
getHeight
()
-
y
-
1
)
*
_textureData
->
getWidth
())
+
x
;
outFileStream
.
put
(
_textureData
->
getData
()[(
3
*
i
+
0
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
outFileStream
.
put
(
_textureData
->
getData
()[(
3
*
i
+
1
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
outFileStream
.
put
(
_textureData
->
getData
()[(
3
*
i
+
2
)
*
getGLTypeSize
(
_textureData
->
getType
())]);
}
}
return
(
unsigned
char
*
)
processedrawdata
;
outFileStream
.
close
();
return
true
;
}
bool
saveTextureDataToLodepng
(
SharedTextureData
_data
,
const
std
::
string
&
_filename
)
bool
saveTextureDataToLodepng
(
const
SharedTextureData
&
_data
,
const
std
::
string
&
_filename
)
{
GLenum
channelDataType
=
_data
->
getType
();
unsigned
int
channelCount
=
getNumberOfChannels
(
_data
->
getFormat
()
);
...
...
@@ -228,6 +310,13 @@ bool saveTextureDataToLodepng( SharedTextureData _data, const std::string &_file
return
true
;
}
#ifdef ACGL_COMPILE_WITH_QT
bool
saveTextureDataToQT
(
const
SharedTextureData
&
_data
,
const
std
::
string
&
_filename
)
{
// TODO implement me
return
false
;
}
#endif