Added NzTexture

Added levelCount parameter to NzImageParams
Added NzPixelFormat::HasAlpha
Reformatted OpenGL debug messages
This commit is contained in:
Lynix
2012-06-05 10:54:06 +02:00
parent 49353cb636
commit a176648265
19 changed files with 1807 additions and 64 deletions

View File

@@ -38,6 +38,7 @@ class NAZARA_API NzOpenGL
FP64,
FrameBufferObject,
Texture3D,
TextureCompression_s3tc,
TextureStorage,
VertexArrayObject,
@@ -120,6 +121,8 @@ NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource;
NAZARA_API extern PFNGLGETSTRINGPROC glGetString;
NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi;
NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage;
NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv;
NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv;
NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv;
NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv;
NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;

View File

@@ -32,6 +32,7 @@ enum nzShaderType
class NzRenderer;
class NzShaderImpl;
class NzTexture;
class NAZARA_API NzShader : public NzResource, NzNonCopyable
{
@@ -65,6 +66,7 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
bool SendInteger(const NzString& name, int value);
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
bool SendTexture(const NzString& name, NzTexture* texture);
void Unlock();

View File

@@ -0,0 +1,98 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_TEXTURE_HPP
#define NAZARA_TEXTURE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
enum nzTextureFilter
{
nzTextureFilter_Bilinear,
nzTextureFilter_Nearest,
nzTextureFilter_Trilinear,
nzTextureFilter_Unknown
};
enum nzTextureWrap
{
nzTextureWrap_Clamp,
nzTextureWrap_Repeat,
nzTextureWrap_Unknown
};
class NzRenderWindow; ///TODO: Screenshot
struct NzTextureImpl;
class NAZARA_API NzTexture : public NzResource, NzNonCopyable
{
friend class NzShader;
public:
NzTexture();
explicit NzTexture(const NzImage& image);
~NzTexture();
bool Bind();
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false);
void Destroy();
bool Download(NzImage* image) const;
bool EnableMipmapping(bool enable);
unsigned int GetAnisotropyLevel() const;
nzUInt8 GetBPP() const;
unsigned int GetDepth() const;
nzTextureFilter GetFilterMode() const;
nzPixelFormat GetFormat() const;
unsigned int GetHeight() const;
nzImageType GetType() const;
unsigned int GetWidth() const;
nzTextureWrap GetWrapMode() const;
bool IsCompressed() const;
bool IsCubemap() const;
bool IsValid() const;
bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams());
bool LoadFromImage(const NzImage& image);
bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams());
bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams());
bool Lock();
bool SetAnisotropyLevel(unsigned int anistropyLevel);
bool SetFilterMode(nzTextureFilter filter);
bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel);
bool SetWrapMode(nzTextureWrap wrap);
bool Update(const NzImage& image, nzUInt8 level = 0);
bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
//bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
//bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0);
void Unlock();
static unsigned int GetValidSize(unsigned int size);
static bool IsFormatSupported(nzPixelFormat format);
static bool IsTypeSupported(nzImageType type);
private:
NzTextureImpl* m_impl;
};
#endif // NAZARA_TEXTURE_HPP

View File

@@ -31,18 +31,22 @@ enum nzImageType
nzImageType_1D,
nzImageType_2D,
nzImageType_3D,
nzImageType_Cubemap
nzImageType_Cubemap,
nzImageType_Count
};
struct NzImageParams
{
// GCC 4.7 je te veux
NzImageParams() :
loadFormat(nzPixelFormat_Undefined)
loadFormat(nzPixelFormat_Undefined),
levelCount(0)
{
}
nzPixelFormat loadFormat;
nzUInt8 levelCount;
bool IsValid() const
{

View File

@@ -53,6 +53,8 @@ class NzPixelFormat
static nzUInt8 GetBPP(nzPixelFormat format);
static bool HasAlpha(nzPixelFormat format);
static bool IsCompressed(nzPixelFormat format);
static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat);
static bool IsValid(nzPixelFormat format);
@@ -65,7 +67,7 @@ class NzPixelFormat
static bool Initialize();
static void Uninitialize();
static ConvertFunction s_convertFunctions[nzPixelFormat_Count][nzPixelFormat_Count];
static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Count][nzPixelFormat_Count];
};
#include <Nazara/Utility/PixelFormat.inl>

View File

@@ -139,6 +139,24 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
return 0;
}
inline bool NzPixelFormat::HasAlpha(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_BGRA8:
case nzPixelFormat_DXT3:
case nzPixelFormat_DXT5:
case nzPixelFormat_LA8:
case nzPixelFormat_RGB5A1:
case nzPixelFormat_RGBA4:
case nzPixelFormat_RGBA8:
return true;
default:
return false;
}
}
inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
{
switch (format)