1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* 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 2, 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 XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
/*!
\file Texture.h
\brief
*/
#ifndef GUILIB_TEXTURE_H
#define GUILIB_TEXTURE_H
#include "gui3d.h"
#include "StdString.h"
#include "XBTF.h"
#pragma pack(1)
struct COLOR {unsigned char b,g,r,x;}; // Windows GDI expects 4bytes per color
#pragma pack()
#ifdef HAS_DX
#include "D3DResource.h"
#endif
class CTexture;
class CGLTexture;
class CDXTexture;
#pragma once
/*!
\ingroup textures
\brief Base texture class, subclasses of which depend on the render spec (DX, GL etc.)
*/
class CBaseTexture
{
public:
CBaseTexture(unsigned int width = 0, unsigned int height = 0, unsigned int format = XB_FMT_A8R8G8B8);
virtual ~CBaseTexture();
bool LoadFromFile(const CStdString& texturePath, unsigned int maxHeight = 0, unsigned int maxWidth = 0,
bool autoRotate = false, unsigned int *originalWidth = NULL, unsigned int *originalHeight = NULL);
bool LoadFromMemory(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, unsigned char* pixels);
bool LoadPaletted(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, const COLOR *palette);
virtual void CreateTextureObject() = 0;
virtual void DestroyTextureObject() = 0;
virtual void LoadToGPU() = 0;
XBMC::TexturePtr GetTextureObject() const
{
#ifdef HAS_DX
return m_texture.Get();
#else
return m_texture;
#endif
}
unsigned char* GetPixels() const { return m_pixels; }
unsigned int GetPitch() const { return GetPitch(m_textureWidth); }
unsigned int GetRows() const { return GetRows(m_textureHeight); }
unsigned int GetTextureWidth() const { return m_textureWidth; }
unsigned int GetTextureHeight() const { return m_textureHeight; }
unsigned int GetWidth() const { return m_imageWidth; }
unsigned int GetHeight() const { return m_imageHeight; }
int GetOrientation() const { return m_orientation; }
void Update(unsigned int width, unsigned int height, unsigned int pitch, unsigned int format, const unsigned char *pixels, bool loadToGPU);
void Allocate(unsigned int width, unsigned int height, unsigned int format);
void ClampToEdge();
static unsigned int PadPow2(unsigned int x);
protected:
// helpers for computation of texture parameters for compressed textures
unsigned int GetPitch(unsigned int width) const;
unsigned int GetRows(unsigned int height) const;
unsigned int GetBlockSize() const;
unsigned int m_imageWidth;
unsigned int m_imageHeight;
unsigned int m_textureWidth;
unsigned int m_textureHeight;
#ifdef HAS_DX
CD3DTexture m_texture;
#else
XBMC::TexturePtr m_texture;
#endif
unsigned char* m_pixels;
bool m_loadedToGPU;
unsigned int m_format;
int m_orientation;
};
#if defined(HAS_GL) || defined(HAS_GLES)
#include "TextureGL.h"
#define CTexture CGLTexture
#elif defined(HAS_DX)
#include "TextureDX.h"
#define CTexture CDXTexture
#endif
#endif
|