World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
TextureD3D.cpp
См. документацию.
4 
5 
6 Texture *TextureD3D::Create(unsigned int width, unsigned int height,
7  IMAGE_FORMAT format, const void *pixels = nullptr) {
8 
9  if (width == 0 || height == 0) __debugbreak();
10 
11  auto tex = new TextureD3D();
12  if (tex) {
13  tex->initialized = true;
14  tex->width = width;
15  tex->height = height;
16  tex->native_format = format;
17  unsigned int num_pixels = tex->GetWidth() * tex->GetHeight();
18  unsigned int num_pixels_bytes =
19  num_pixels * IMAGE_FORMAT_BytesPerPixel(format);
20  tex->pixels[format] = new unsigned char[num_pixels_bytes];
21  if (pixels) {
22  memcpy(tex->pixels[format], pixels, num_pixels_bytes);
23  } else {
24  memset(tex->pixels[format], 0, num_pixels_bytes);
25  }
26 
27  if (tex->initialized && tex->native_format != IMAGE_INVALID_FORMAT) {
28  // tex->pixels[format] = pixels;
29  // tex->initialized = render->MoveTextureToDevice(tex); nope
30  if (!tex->initialized) {
32  }
33  }
34  }
35 
36  return tex;
37 }
38 
39 
41  auto tex = new TextureD3D();
42  if (tex) {
43  tex->loader = loader;
44  }
45 
46  return tex;
47 }
48 
49 IDirectDrawSurface *TextureD3D::GetDirectDrawSurface() {
50  if (!this->initialized) {
51  this->LoadImageData();
52  }
53 
54  return this->dds;
55 }
56 
57 IDirect3DTexture2 *TextureD3D::GetDirect3DTexture() {
58  if (!this->initialized) {
59  this->LoadImageData();
60  }
61 
62  return this->d3dt;
63 }
64 
66  if (!this->initialized) {
67  void *pixels;
68 
69  this->initialized =
70  this->loader->Load(&width, &height, &pixels, &native_format);
71 
72  if (width == 0 || height == 0) __debugbreak();
73 
74  if (this->initialized && this->native_format != IMAGE_INVALID_FORMAT) {
75  this->pixels[native_format] = pixels;
76 
77  // check power of two - temporary
78  if ( (this->width & (this->width - 1)) == 0 && (this->height & (this->height - 1)) == 0 ) {
79  this->initialized = render->MoveTextureToDevice(this);
80  }
81  }
82  }
83 
84  return this->initialized;
85 }
86 
88  render->RemoveTextureFromDevice(this);
89  this->d3dt = NULL;
90  this->dds = NULL;
91 }
Image::native_format
IMAGE_FORMAT native_format
Definition: Image.h:51
Image::width
unsigned int width
Definition: Image.h:49
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
TextureD3D::TextureD3D
TextureD3D(bool lazy_initialization=true)
Definition: TextureD3D.h:21
TextureD3D::dds
IDirectDrawSurface * dds
Definition: TextureD3D.h:24
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
format
SDL_AudioFormat format
Definition: SDL_audio.h:194
IRender.h
width
EGLSurface EGLint EGLint EGLint width
Definition: SDL_egl.h:1596
Image::height
unsigned int height
Definition: Image.h:50
TextureD3D::GetDirect3DTexture
IDirect3DTexture2 * GetDirect3DTexture()
Definition: TextureD3D.cpp:57
ImageLoader
Definition: ImageLoader.h:10
IMAGE_FORMAT
IMAGE_FORMAT
Definition: Image.h:4
TextureD3D::~TextureD3D
~TextureD3D()
Definition: TextureD3D.cpp:87
TextureD3D.h
TextureD3D::d3dt
IDirect3DTexture2 * d3dt
Definition: TextureD3D.h:25
TextureD3D::LoadImageData
virtual bool LoadImageData()
Definition: TextureD3D.cpp:65
TextureD3D::GetDirectDrawSurface
IDirectDrawSurface * GetDirectDrawSurface()
Definition: TextureD3D.cpp:49
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)
Image::pixels
void * pixels[IMAGE_NUM_FORMATS]
Definition: Image.h:52
TextureD3D::Create
static Texture * Create(unsigned int width, unsigned int height, IMAGE_FORMAT format, const void *pixels)
Definition: TextureD3D.cpp:6
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