summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-07-06 19:00:22 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-07-06 19:00:22 +0200
commit32043605153543bd72eb012ff310367299ad4e8f (patch)
tree91371b113a60d6069dd7d90d0819e4ea3bfdf58d /src/graphics
parente8c9945e13fca88a6f8232838682df0654437f3e (diff)
downloadcolobot-32043605153543bd72eb012ff310367299ad4e8f.tar.gz
colobot-32043605153543bd72eb012ff310367299ad4e8f.tar.bz2
colobot-32043605153543bd72eb012ff310367299ad4e8f.zip
Refactoring in math & texture modules
- moved texture-related structs to texture.h & code to texture.cpp - cleaned up texture test code - added Math:: namespace qualifiers to math modules for clarity
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/common/device.cpp23
-rw-r--r--src/graphics/common/device.h109
-rw-r--r--src/graphics/common/texture.cpp43
-rw-r--r--src/graphics/common/texture.h109
-rw-r--r--src/graphics/opengl/gldevice.cpp2
-rw-r--r--src/graphics/opengl/test/texture_test.cpp186
6 files changed, 154 insertions, 318 deletions
diff --git a/src/graphics/common/device.cpp b/src/graphics/common/device.cpp
index 79102b2..fcd4318 100644
--- a/src/graphics/common/device.cpp
+++ b/src/graphics/common/device.cpp
@@ -31,26 +31,3 @@ void Gfx::DeviceConfig::LoadDefault()
doubleBuf = true;
noFrame = false;
}
-
-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;
-}
diff --git a/src/graphics/common/device.h b/src/graphics/common/device.h
index 41181aa..6a71a8a 100644
--- a/src/graphics/common/device.h
+++ b/src/graphics/common/device.h
@@ -181,115 +181,6 @@ enum PrimitiveType
PRIMITIVE_TRIANGLE_STRIP
};
-/**
- \enum TexMinFilter
- \brief Minification texture filter
-
- Corresponds to OpenGL modes but should translate to DirectX too. */
-enum TexMinFilter
-{
- TEX_MIN_FILTER_NEAREST,
- TEX_MIN_FILTER_LINEAR,
- TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST,
- TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST,
- TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR,
- TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR
-};
-
-/**
- \enum TexMagFilter
- \brief Magnification texture filter */
-enum TexMagFilter
-{
- TEX_MAG_FILTER_NEAREST,
- TEX_MAG_FILTER_LINEAR
-};
-
-/**
- \enum TexWrapMode
- \brief Wrapping mode for texture coords */
-enum TexWrapMode
-{
- TEX_WRAP_CLAMP,
- TEX_WRAP_REPEAT
-};
-
-/**
- \enum TexMixOperation
- \brief Multitexture mixing operation
- */
-enum TexMixOperation
-{
- TEX_MIX_OPER_MODULATE,
- TEX_MIX_OPER_ADD
-};
-
-/**
- \enum TexMixArgument
- \brief Multitexture mixing argument
- */
-enum TexMixArgument
-{
- TEX_MIX_ARG_CURRENT,
- TEX_MIX_ARG_TEXTURE,
- TEX_MIX_ARG_DIFFUSE,
- TEX_MIX_ARG_FACTOR
-};
-
-/**
- \struct TextureCreateParams
- \brief Parameters for texture creation
- */
-struct TextureCreateParams
-{
- //! Whether the texture image contains alpha
- bool alpha;
- //! Whether to generate mipmaps
- bool mipmap;
- //! Minification filter
- Gfx::TexMinFilter minFilter;
- //! Magnification filter
- Gfx::TexMagFilter magFilter;
- //! Wrap S coord mode
- Gfx::TexWrapMode wrapS;
- //! Wrap T coord mode
- Gfx::TexWrapMode wrapT;
-
- //! Constructor; calls LoadDefault()
- TextureCreateParams()
- { LoadDefault(); }
-
- //! Loads the default values
- void LoadDefault();
-};
-
-/**
- \struct TextureParams
- \brief Parameters for texture creation
- */
-struct TextureParams
-{
- //! Mixing operation done on color values
- Gfx::TexMixOperation colorOperation;
- //! 1st argument of color operations
- Gfx::TexMixArgument colorArg1;
- //! 2nd argument of color operations
- Gfx::TexMixArgument colorArg2;
- //! Mixing operation done on alpha values
- Gfx::TexMixOperation alphaOperation;
- //! 1st argument of alpha operations
- Gfx::TexMixArgument alphaArg1;
- //! 2nd argument of alpha operations
- Gfx::TexMixArgument alphaArg2;
-
- //! Constructor; calls LoadDefault()
- TextureParams()
- { LoadDefault(); }
-
- //! Loads the default values
- void LoadDefault();
-};
-
/*
Notes for rewriting DirectX code:
diff --git a/src/graphics/common/texture.cpp b/src/graphics/common/texture.cpp
new file mode 100644
index 0000000..50e71cd
--- /dev/null
+++ b/src/graphics/common/texture.cpp
@@ -0,0 +1,43 @@
+// * 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;
+}
diff --git a/src/graphics/common/texture.h b/src/graphics/common/texture.h
index 55d5c70..55b2fc2 100644
--- a/src/graphics/common/texture.h
+++ b/src/graphics/common/texture.h
@@ -20,6 +20,115 @@
namespace Gfx {
+/**
+ \enum TexMinFilter
+ \brief Minification texture filter
+
+ Corresponds to OpenGL modes but should translate to DirectX too. */
+enum TexMinFilter
+{
+ TEX_MIN_FILTER_NEAREST,
+ TEX_MIN_FILTER_LINEAR,
+ TEX_MIN_FILTER_NEAREST_MIPMAP_NEAREST,
+ TEX_MIN_FILTER_LINEAR_MIPMAP_NEAREST,
+ TEX_MIN_FILTER_NEAREST_MIPMAP_LINEAR,
+ TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR
+};
+
+/**
+ \enum TexMagFilter
+ \brief Magnification texture filter */
+enum TexMagFilter
+{
+ TEX_MAG_FILTER_NEAREST,
+ TEX_MAG_FILTER_LINEAR
+};
+
+/**
+ \enum TexWrapMode
+ \brief Wrapping mode for texture coords */
+enum TexWrapMode
+{
+ TEX_WRAP_CLAMP,
+ TEX_WRAP_REPEAT
+};
+
+/**
+ \enum TexMixOperation
+ \brief Multitexture mixing operation
+ */
+enum TexMixOperation
+{
+ TEX_MIX_OPER_MODULATE,
+ TEX_MIX_OPER_ADD
+};
+
+/**
+ \enum TexMixArgument
+ \brief Multitexture mixing argument
+ */
+enum TexMixArgument
+{
+ TEX_MIX_ARG_CURRENT,
+ TEX_MIX_ARG_TEXTURE,
+ TEX_MIX_ARG_DIFFUSE,
+ TEX_MIX_ARG_FACTOR
+};
+
+/**
+ \struct TextureCreateParams
+ \brief Parameters for texture creation
+ */
+struct TextureCreateParams
+{
+ //! Whether the texture image contains alpha
+ bool alpha;
+ //! Whether to generate mipmaps
+ bool mipmap;
+ //! Minification filter
+ Gfx::TexMinFilter minFilter;
+ //! Magnification filter
+ Gfx::TexMagFilter magFilter;
+ //! Wrap S coord mode
+ Gfx::TexWrapMode wrapS;
+ //! Wrap T coord mode
+ Gfx::TexWrapMode wrapT;
+
+ //! Constructor; calls LoadDefault()
+ TextureCreateParams()
+ { LoadDefault(); }
+
+ //! Loads the default values
+ void LoadDefault();
+};
+
+/**
+ \struct TextureParams
+ \brief Parameters for texture creation
+ */
+struct TextureParams
+{
+ //! Mixing operation done on color values
+ Gfx::TexMixOperation colorOperation;
+ //! 1st argument of color operations
+ Gfx::TexMixArgument colorArg1;
+ //! 2nd argument of color operations
+ Gfx::TexMixArgument colorArg2;
+ //! Mixing operation done on alpha values
+ Gfx::TexMixOperation alphaOperation;
+ //! 1st argument of alpha operations
+ Gfx::TexMixArgument alphaArg1;
+ //! 2nd argument of alpha operations
+ Gfx::TexMixArgument alphaArg2;
+
+ //! Constructor; calls LoadDefault()
+ TextureParams()
+ { LoadDefault(); }
+
+ //! Loads the default values
+ void LoadDefault();
+};
+
/** \struct Texture*/
struct Texture
{
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 3182dfc..f253568 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -135,7 +135,7 @@ bool Gfx::CGLDevice::Create()
int maxTextures = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextures);
- m_textures = std::vector<Gfx::Texture*> (maxTextures, NULL);
+ m_textures = std::vector<Gfx::Texture*> (maxTextures, (Gfx::Texture*)(NULL));
m_texturesEnabled = std::vector<bool> (maxTextures, false);
m_texturesParams = std::vector<Gfx::TextureParams>(maxTextures, Gfx::TextureParams());
diff --git a/src/graphics/opengl/test/texture_test.cpp b/src/graphics/opengl/test/texture_test.cpp
index 022cf87..764e127 100644
--- a/src/graphics/opengl/test/texture_test.cpp
+++ b/src/graphics/opengl/test/texture_test.cpp
@@ -7,11 +7,6 @@
#include <SDL/SDL_image.h>
#include <unistd.h>
-#include <GL/gl.h>
-
-
-#define DEV 1
-
void Init(Gfx::CGLDevice *device)
{
@@ -68,8 +63,6 @@ void Render(Gfx::CGLDevice *device)
{
device->BeginScene();
- glFlush();
-
Math::Matrix ortho;
Math::LoadOrthoProjectionMatrix(ortho, -10, 10, -10, 10);
device->SetTransform(Gfx::TRANSFORM_PROJECTION, ortho);
@@ -119,172 +112,6 @@ void Render(Gfx::CGLDevice *device)
device->EndScene();
}
-void InitGL()
-{
- CImage img1;
- if (! img1.Load("tex1.png"))
- {
- std::string err = img1.GetError();
- GetLogger()->Error("texture 1 not loaded, error: %d!\n", err.c_str());
- }
- CImage img2;
- if (! img2.Load("tex2.png"))
- {
- std::string err = img2.GetError();
- GetLogger()->Error("texture 2 not loaded, error: %d!\n", err.c_str());
- }
-
- unsigned int textureHandle1 = 0;
-
- glActiveTexture(GL_TEXTURE0_ARB);
- glEnable(GL_TEXTURE_2D);
-
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
-
- glGenTextures(1, &textureHandle1);
- glBindTexture(GL_TEXTURE_2D, textureHandle1);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img1.GetData()->surface->w, img1.GetData()->surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img1.GetData()->surface->pixels);
-
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
-
- glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_RGB, GL_REPLACE);
- glTexEnvi(GL_TEXTURE_2D, GL_SRC0_RGB, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_ALPHA, GL_REPLACE);
- glTexEnvi(GL_TEXTURE_2D, GL_SRC0_ALPHA, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
-
-
-
- unsigned int textureHandle2 = 0;
-
- glActiveTexture(GL_TEXTURE1_ARB);
- glEnable(GL_TEXTURE_2D);
-
- glPixelStorei(GL_UNPACK_ALIGNMENT,1);
-
- glGenTextures(1, &textureHandle2);
- glBindTexture(GL_TEXTURE_2D, textureHandle2);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img2.GetData()->surface->w, img2.GetData()->surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, img2.GetData()->surface->pixels);
-
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
-
- glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_RGB, GL_MODULATE);
- glTexEnvi(GL_TEXTURE_2D, GL_SRC0_RGB, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_ALPHA, GL_MODULATE);
- glTexEnvi(GL_TEXTURE_2D, GL_SRC0_ALPHA, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
-
-
-
- glMatrixMode(GL_PROJECTION);
- glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, -1.0f, 1.0f);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-void RenderGL()
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glLoadIdentity();
-
- glColor3f(1.0f, 1.0f, 1.0f);
-
- glPushMatrix();
- glTranslatef(-4.0f, 4.0f, 0.0f);
-
- glActiveTextureARB(GL_TEXTURE0_ARB);
- glEnable(GL_TEXTURE_2D);
- glActiveTextureARB(GL_TEXTURE1_ARB);
- glDisable(GL_TEXTURE_2D);
-
- glBegin(GL_QUADS);
- {
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 1.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 1.0f);
- glVertex2f(-2.0f, -2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 1.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 1.0f);
- glVertex2f(2.0f, -2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 0.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 0.0f);
- glVertex2f(2.0f, 2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 0.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 0.0f);
- glVertex2f(-2.0f, 2.0f);
- }
- glEnd();
-
- glPopMatrix();
- glPushMatrix();
- glTranslatef( 4.0f, 4.0f, 0.0f);
-
- glActiveTextureARB(GL_TEXTURE0_ARB);
- glDisable(GL_TEXTURE_2D);
- glActiveTextureARB(GL_TEXTURE1_ARB);
- glEnable(GL_TEXTURE_2D);
-
- glBegin(GL_QUADS);
- {
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 1.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 1.0f);
- glVertex2f(-2.0f, -2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 1.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 1.0f);
- glVertex2f(2.0f, -2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 0.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 0.0f);
- glVertex2f(2.0f, 2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 0.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 0.0f);
- glVertex2f(-2.0f, 2.0f);
- }
- glEnd();
-
- glPopMatrix();
- glPushMatrix();
- glTranslatef( 0.0f, -4.0f, 0.0f);
-
- glActiveTextureARB(GL_TEXTURE0_ARB);
- glEnable(GL_TEXTURE_2D);
- glActiveTextureARB(GL_TEXTURE1_ARB);
- glEnable(GL_TEXTURE_2D);
-
- glBegin(GL_QUADS);
- {
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 1.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 1.0f);
- glVertex2f(-2.0f, -2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 1.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 1.0f);
- glVertex2f(2.0f, -2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 1.0f, 0.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 1.0f, 0.0f);
- glVertex2f(2.0f, 2.0f);
- glMultiTexCoord2f(GL_TEXTURE0_ARB, 0.0f, 0.0f);
- glMultiTexCoord2f(GL_TEXTURE1_ARB, 0.0f, 0.0f);
- glVertex2f(-2.0f, 2.0f);
- }
- glEnd();
-
- glPopMatrix();
-
- glFlush();
-}
-
-
int main()
{
CLogger();
@@ -322,24 +149,15 @@ int main()
SDL_WM_SetCaption("Texture Test", "Texture Test");
-
- #if DEV
Gfx::CGLDevice *device = new Gfx::CGLDevice();
device->Create();
Init(device);
- #else
- InitGL();
- #endif
bool done = false;
while (! done)
{
- #if DEV
Render(device);
- #else
- RenderGL();
- #endif
SDL_GL_SwapBuffers();
@@ -348,12 +166,10 @@ int main()
if (event.type == SDL_QUIT)
done = true;
- usleep(50000);
+ usleep(10000);
}
- #if DEV
device->Destroy();
- #endif
SDL_FreeSurface(surface);