World of Might and Magic
0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
TextureOpenGL.cpp
См. документацию.
1
#include "
Engine/Graphics/OpenGL/TextureOpenGL.h
"
2
#include "
Engine/Graphics/IRender.h
"
3
#include "
Engine/Graphics/ImageLoader.h
"
4
#include "
Engine/ErrorHandling.h
"
5
6
Texture
*
TextureOpenGL::Create
(
unsigned
int
width
,
unsigned
int
height
,
7
IMAGE_FORMAT
format
,
const
void
*
pixels
=
nullptr
) {
8
9
auto
tex =
new
TextureOpenGL
(
false
);
10
if
(tex) {
11
tex->initialized =
true
;
12
tex->width =
width
;
13
tex->height =
height
;
14
tex->native_format =
format
;
15
unsigned
int
num_pixels = tex->GetWidth() * tex->GetHeight();
16
unsigned
int
num_pixels_bytes =
17
num_pixels *
IMAGE_FORMAT_BytesPerPixel
(
format
);
18
tex->pixels[
format
] =
new
unsigned
char
[num_pixels_bytes];
19
if
(
pixels
) {
20
memcpy(tex->pixels[
format
],
pixels
, num_pixels_bytes);
21
}
else
{
22
memset(tex->pixels[
format
], 0, num_pixels_bytes);
23
}
24
25
if
(tex->initialized && tex->native_format !=
IMAGE_INVALID_FORMAT
) {
26
// tex->pixels[format] = pixels;
27
tex->initialized =
render
->MoveTextureToDevice(tex);
28
if
(!tex->initialized) {
29
__debugbreak
();
30
}
31
}
32
}
33
34
return
tex;
35
}
36
37
Texture
*
TextureOpenGL::Create
(
ImageLoader
*loader) {
38
auto
tex =
new
TextureOpenGL
();
39
if
(tex) {
40
tex->loader =
loader
;
41
}
42
43
return
tex;
44
}
45
46
int
TextureOpenGL::GetOpenGlTexture
() {
47
if
(!this->
initialized
) {
48
this->
LoadImageData
();
49
}
50
51
if
(this->
ogl_texture
< 0) {
52
__debugbreak
();
// prob not loaded in as texture and recast so problems
53
}
54
55
return
this->
ogl_texture
;
56
}
57
58
bool
TextureOpenGL::LoadImageData
() {
59
if
(!this->
initialized
) {
60
void
*
pixels
;
61
62
this->
initialized
=
63
this->
loader
->
Load
(&
width
, &
height
, &
pixels
, &
native_format
);
64
if
(this->
initialized
&& this->
native_format
!=
IMAGE_INVALID_FORMAT
) {
65
this->pixels[
native_format
] =
pixels
;
66
this->
initialized
=
render
->MoveTextureToDevice(
this
);
67
if
(!this->
initialized
) {
68
__debugbreak
();
69
}
70
}
71
}
72
73
return
this->
initialized
;
74
}
75
76
TextureOpenGL::~TextureOpenGL
() {
77
if
(this->
ogl_texture
!= -1)
render
->DeleteTexture(
this
);
78
}
TextureOpenGL::ogl_texture
int ogl_texture
Definition:
TextureOpenGL.h:22
TextureOpenGL::LoadImageData
virtual bool LoadImageData()
Definition:
TextureOpenGL.cpp:58
Image::native_format
IMAGE_FORMAT native_format
Definition:
Image.h:51
Image::width
unsigned int width
Definition:
Image.h:49
TextureOpenGL::TextureOpenGL
TextureOpenGL(bool lazy_initialization=true)
Definition:
TextureOpenGL.h:19
Image::loader
ImageLoader * loader
Definition:
Image.h:47
height
EGLSurface EGLint EGLint EGLint EGLint height
Definition:
SDL_egl.h:1596
Texture
Definition:
Texture.h:4
IMAGE_FORMAT_BytesPerPixel
unsigned int IMAGE_FORMAT_BytesPerPixel(IMAGE_FORMAT format)
Definition:
Image.cpp:46
ImageLoader.h
IMAGE_INVALID_FORMAT
@ IMAGE_INVALID_FORMAT
Definition:
Image.h:12
TextureOpenGL::~TextureOpenGL
~TextureOpenGL()
Definition:
TextureOpenGL.cpp:76
format
SDL_AudioFormat format
Definition:
SDL_audio.h:194
IRender.h
ErrorHandling.h
width
EGLSurface EGLint EGLint EGLint width
Definition:
SDL_egl.h:1596
Image::height
unsigned int height
Definition:
Image.h:50
TextureOpenGL::GetOpenGlTexture
int GetOpenGlTexture()
Definition:
TextureOpenGL.cpp:46
ImageLoader
Definition:
ImageLoader.h:10
IMAGE_FORMAT
IMAGE_FORMAT
Definition:
Image.h:4
TextureOpenGL::Create
static Texture * Create(unsigned int width, unsigned int height, IMAGE_FORMAT format, const void *pixels)
Definition:
TextureOpenGL.cpp:6
Image::initialized
bool initialized
Definition:
Image.h:46
ImageLoader::Load
virtual bool Load(unsigned int *width, unsigned int *height, void **pixels, IMAGE_FORMAT *format)=0
__debugbreak
void __cdecl __debugbreak(void)
TextureOpenGL.h
Image::pixels
void * pixels[IMAGE_NUM_FORMATS]
Definition:
Image.h:52
pixels
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition:
SDL_opengl.h:1572
render
std::shared_ptr< IRender > render
Definition:
RenderOpenGL.cpp:52
Engine
Graphics
OpenGL
TextureOpenGL.cpp
Документация по World of Might and Magic. Последние изменения: Вт 7 Апр 2020 22:03:29. Создано системой
1.8.17