Fixes in texture loading
- added other texture formats: BGR and BGRA - fixed texture loading in model viewer - moved code from texture.cpp module to texture.hdev-ui
parent
54f4da8792
commit
68a7bafe37
|
@ -52,7 +52,6 @@ graphics/common/planet.cpp
|
||||||
graphics/common/pyro.cpp
|
graphics/common/pyro.cpp
|
||||||
graphics/common/terrain.cpp
|
graphics/common/terrain.cpp
|
||||||
graphics/common/text.cpp
|
graphics/common/text.cpp
|
||||||
graphics/common/texture.cpp
|
|
||||||
graphics/common/water.cpp
|
graphics/common/water.cpp
|
||||||
graphics/opengl/gldevice.cpp
|
graphics/opengl/gldevice.cpp
|
||||||
graphics/opengl/glengine.cpp
|
graphics/opengl/glengine.cpp
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
// * This file is part of the COLOBOT source code
|
|
||||||
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
|
|
||||||
// *
|
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
|
||||||
// * it under the terms of the GNU General Public License as published by
|
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// * (at your option) any later version.
|
|
||||||
// *
|
|
||||||
// * This program is distributed in the hope that it will be useful,
|
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// * GNU General Public License for more details.
|
|
||||||
// *
|
|
||||||
// * You should have received a copy of the GNU General Public License
|
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
||||||
|
|
||||||
// texture.cpp
|
|
||||||
|
|
||||||
#include "graphics/common/texture.h"
|
|
||||||
|
|
||||||
|
|
||||||
void Gfx::TextureCreateParams::LoadDefault()
|
|
||||||
{
|
|
||||||
alpha = false;
|
|
||||||
mipmap = false;
|
|
||||||
|
|
||||||
minFilter = Gfx::TEX_MIN_FILTER_NEAREST;
|
|
||||||
magFilter = Gfx::TEX_MAG_FILTER_NEAREST;
|
|
||||||
|
|
||||||
wrapS = Gfx::TEX_WRAP_REPEAT;
|
|
||||||
wrapT = Gfx::TEX_WRAP_REPEAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gfx::TextureParams::LoadDefault()
|
|
||||||
{
|
|
||||||
colorOperation = Gfx::TEX_MIX_OPER_MODULATE;
|
|
||||||
colorArg1 = Gfx::TEX_MIX_ARG_CURRENT;
|
|
||||||
colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE;
|
|
||||||
|
|
||||||
alphaOperation = Gfx::TEX_MIX_OPER_MODULATE;
|
|
||||||
alphaArg1 = Gfx::TEX_MIX_ARG_CURRENT;
|
|
||||||
alphaArg2 = Gfx::TEX_MIX_ARG_TEXTURE;
|
|
||||||
}
|
|
|
@ -20,6 +20,17 @@
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
/**
|
||||||
|
\enum TexImgFormat
|
||||||
|
\brief Format of image data */
|
||||||
|
enum TexImgFormat
|
||||||
|
{
|
||||||
|
TEX_IMG_RGB,
|
||||||
|
TEX_IMG_BGR,
|
||||||
|
TEX_IMG_RGBA,
|
||||||
|
TEX_IMG_BGRA
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\enum TexMinFilter
|
\enum TexMinFilter
|
||||||
\brief Minification texture filter
|
\brief Minification texture filter
|
||||||
|
@ -81,10 +92,10 @@ enum TexMixArgument
|
||||||
*/
|
*/
|
||||||
struct TextureCreateParams
|
struct TextureCreateParams
|
||||||
{
|
{
|
||||||
//! Whether the texture image contains alpha
|
|
||||||
bool alpha;
|
|
||||||
//! Whether to generate mipmaps
|
//! Whether to generate mipmaps
|
||||||
bool mipmap;
|
bool mipmap;
|
||||||
|
//! Format of source image data
|
||||||
|
Gfx::TexImgFormat format;
|
||||||
//! Minification filter
|
//! Minification filter
|
||||||
Gfx::TexMinFilter minFilter;
|
Gfx::TexMinFilter minFilter;
|
||||||
//! Magnification filter
|
//! Magnification filter
|
||||||
|
@ -99,7 +110,17 @@ struct TextureCreateParams
|
||||||
{ LoadDefault(); }
|
{ LoadDefault(); }
|
||||||
|
|
||||||
//! Loads the default values
|
//! Loads the default values
|
||||||
void LoadDefault();
|
inline void LoadDefault()
|
||||||
|
{
|
||||||
|
format = Gfx::TEX_IMG_RGB;
|
||||||
|
mipmap = false;
|
||||||
|
|
||||||
|
minFilter = Gfx::TEX_MIN_FILTER_NEAREST;
|
||||||
|
magFilter = Gfx::TEX_MAG_FILTER_NEAREST;
|
||||||
|
|
||||||
|
wrapS = Gfx::TEX_WRAP_REPEAT;
|
||||||
|
wrapT = Gfx::TEX_WRAP_REPEAT;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +147,16 @@ struct TextureParams
|
||||||
{ LoadDefault(); }
|
{ LoadDefault(); }
|
||||||
|
|
||||||
//! Loads the default values
|
//! Loads the default values
|
||||||
void LoadDefault();
|
inline void LoadDefault()
|
||||||
|
{
|
||||||
|
colorOperation = Gfx::TEX_MIX_OPER_MODULATE;
|
||||||
|
colorArg1 = Gfx::TEX_MIX_ARG_CURRENT;
|
||||||
|
colorArg2 = Gfx::TEX_MIX_ARG_TEXTURE;
|
||||||
|
|
||||||
|
alphaOperation = Gfx::TEX_MIX_OPER_MODULATE;
|
||||||
|
alphaArg1 = Gfx::TEX_MIX_ARG_CURRENT;
|
||||||
|
alphaArg2 = Gfx::TEX_MIX_ARG_TEXTURE;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \struct Texture*/
|
/** \struct Texture*/
|
||||||
|
|
|
@ -393,10 +393,16 @@ Gfx::Texture* Gfx::CGLDevice::CreateTexture(CImage *image, const Gfx::TextureCre
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
|
||||||
|
|
||||||
GLenum sourceFormat = 0;
|
GLenum sourceFormat = 0;
|
||||||
if (params.alpha)
|
if (params.format == Gfx::TEX_IMG_RGB)
|
||||||
sourceFormat = GL_RGBA;
|
|
||||||
else
|
|
||||||
sourceFormat = GL_RGB;
|
sourceFormat = GL_RGB;
|
||||||
|
else if (params.format == Gfx::TEX_IMG_BGR)
|
||||||
|
sourceFormat = GL_BGR;
|
||||||
|
else if (params.format == Gfx::TEX_IMG_RGBA)
|
||||||
|
sourceFormat = GL_RGBA;
|
||||||
|
else if (params.format == Gfx::TEX_IMG_BGRA)
|
||||||
|
sourceFormat = GL_BGRA;
|
||||||
|
else
|
||||||
|
assert(false);
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->surface->w, data->surface->h,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->surface->w, data->surface->h,
|
||||||
0, sourceFormat, GL_UNSIGNED_BYTE, data->surface->pixels);
|
0, sourceFormat, GL_UNSIGNED_BYTE, data->surface->pixels);
|
||||||
|
|
|
@ -8,6 +8,8 @@ find_package(PNG REQUIRED)
|
||||||
set(CMAKE_BUILD_TYPE debug)
|
set(CMAKE_BUILD_TYPE debug)
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0")
|
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0")
|
||||||
|
|
||||||
|
set(ADD_LIBS "")
|
||||||
|
|
||||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
set(PLATFORM_WINDOWS 1)
|
set(PLATFORM_WINDOWS 1)
|
||||||
set(PLATFORM_LINUX 0)
|
set(PLATFORM_LINUX 0)
|
||||||
|
@ -16,6 +18,7 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
set(PLATFORM_WINDOWS 0)
|
set(PLATFORM_WINDOWS 0)
|
||||||
set(PLATFORM_LINUX 1)
|
set(PLATFORM_LINUX 1)
|
||||||
set(PLATFORM_OTHER 0)
|
set(PLATFORM_OTHER 0)
|
||||||
|
set(ADD_LIBS "-lrt")
|
||||||
else()
|
else()
|
||||||
set(PLATFORM_WINDOWS 0)
|
set(PLATFORM_WINDOWS 0)
|
||||||
set(PLATFORM_LINUX 0)
|
set(PLATFORM_LINUX 0)
|
||||||
|
@ -28,7 +31,6 @@ configure_file(../../../common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common
|
||||||
set(TEXTURE_SOURCES
|
set(TEXTURE_SOURCES
|
||||||
../gldevice.cpp
|
../gldevice.cpp
|
||||||
../../common/device.cpp
|
../../common/device.cpp
|
||||||
../../common/texture.cpp
|
|
||||||
../../../common/logger.cpp
|
../../../common/logger.cpp
|
||||||
../../../common/image.cpp
|
../../../common/image.cpp
|
||||||
texture_test.cpp
|
texture_test.cpp
|
||||||
|
@ -38,7 +40,6 @@ set(MODEL_SOURCES
|
||||||
../gldevice.cpp
|
../gldevice.cpp
|
||||||
../../common/device.cpp
|
../../common/device.cpp
|
||||||
../../common/modelfile.cpp
|
../../common/modelfile.cpp
|
||||||
../../common/texture.cpp
|
|
||||||
../../../common/logger.cpp
|
../../../common/logger.cpp
|
||||||
../../../common/image.cpp
|
../../../common/image.cpp
|
||||||
../../../common/iman.cpp
|
../../../common/iman.cpp
|
||||||
|
@ -54,6 +55,7 @@ ${SDL_LIBRARY}
|
||||||
${SDLIMAGE_LIBRARY}
|
${SDLIMAGE_LIBRARY}
|
||||||
${OPENGL_LIBRARY}
|
${OPENGL_LIBRARY}
|
||||||
${PNG_LIBRARIES}
|
${PNG_LIBRARIES}
|
||||||
|
${ADD_LIBS}
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(texture_test ${TEXTURE_SOURCES})
|
add_executable(texture_test ${TEXTURE_SOURCES})
|
||||||
|
|
|
@ -66,8 +66,11 @@ void LoadTexture(Gfx::CGLDevice *device, const std::string &name)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Gfx::TextureCreateParams texCreateParams;
|
Gfx::TextureCreateParams texCreateParams;
|
||||||
texCreateParams.alpha = false;
|
|
||||||
texCreateParams.mipmap = true;
|
texCreateParams.mipmap = true;
|
||||||
|
if (img.GetData()->surface->format->Amask == 0)
|
||||||
|
texCreateParams.format = Gfx::TEX_IMG_BGR;
|
||||||
|
else
|
||||||
|
texCreateParams.format = Gfx::TEX_IMG_BGRA;
|
||||||
texCreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
|
texCreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
|
||||||
texCreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
|
texCreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
|
||||||
texCreateParams.wrapT = Gfx::TEX_WRAP_CLAMP;
|
texCreateParams.wrapT = Gfx::TEX_WRAP_CLAMP;
|
||||||
|
|
|
@ -27,15 +27,15 @@ void Init(Gfx::CGLDevice *device)
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::TextureCreateParams tex1CreateParams;
|
Gfx::TextureCreateParams tex1CreateParams;
|
||||||
tex1CreateParams.alpha = true;
|
|
||||||
tex1CreateParams.mipmap = true;
|
tex1CreateParams.mipmap = true;
|
||||||
|
tex1CreateParams.format = Gfx::TEX_IMG_RGBA;
|
||||||
tex1CreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
|
tex1CreateParams.minFilter = Gfx::TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR;
|
||||||
tex1CreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
|
tex1CreateParams.magFilter = Gfx::TEX_MAG_FILTER_LINEAR;
|
||||||
tex1CreateParams.wrapT = Gfx::TEX_WRAP_CLAMP;
|
tex1CreateParams.wrapT = Gfx::TEX_WRAP_CLAMP;
|
||||||
|
|
||||||
Gfx::TextureCreateParams tex2CreateParams;
|
Gfx::TextureCreateParams tex2CreateParams;
|
||||||
tex2CreateParams.alpha = true;
|
|
||||||
tex2CreateParams.mipmap = true;
|
tex2CreateParams.mipmap = true;
|
||||||
|
tex2CreateParams.format = Gfx::TEX_IMG_RGBA;
|
||||||
tex2CreateParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST;
|
tex2CreateParams.minFilter = Gfx::TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST;
|
||||||
tex2CreateParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST;
|
tex2CreateParams.magFilter = Gfx::TEX_MAG_FILTER_NEAREST;
|
||||||
tex2CreateParams.wrapS = Gfx::TEX_WRAP_CLAMP;
|
tex2CreateParams.wrapS = Gfx::TEX_WRAP_CLAMP;
|
||||||
|
|
Loading…
Reference in New Issue