# Khaotic Engine Reborn: texture_class Class Reference

Loading...
Searching...
No Matches
texture_class Class Reference

## Public Member Functions

| texture_class (const texture_class &)
bool | Initialize (ID3D11Device *, ID3D11DeviceContext *, std::string)
void | Shutdown ()
ID3D11ShaderResourceView * | GetTexture ()
int | GetWidth ()
int | GetHeight ()

## Detailed Description

Definition at line 16 of file texture_class.h.

## Constructor & Destructor Documentation

## texture_class() [1/2]

texture_class::texture_class | ( |  | ) |

Definition at line 3 of file texture_class.cpp.

{
m_targaData = 0;
m_texture = 0;
m_textureView = 0;
}

## texture_class() [2/2]

texture_class::texture_class | ( | const texture_class & | other | ) |

Definition at line 11 of file texture_class.cpp.

{
}

## ~texture_class()

texture_class::~texture_class | ( |  | ) |

Definition at line 16 of file texture_class.cpp.

{
}

## Member Function Documentation

## GetHeight()

int texture_class::GetHeight | ( |  | ) |

Definition at line 239 of file texture_class.cpp.

{
return m_height;
}

## GetTexture()

ID3D11ShaderResourceView * texture_class::GetTexture | ( |  | ) |

Definition at line 117 of file texture_class.cpp.

{
return m_textureView;
}

## GetWidth()

int texture_class::GetWidth | ( |  | ) |

Definition at line 233 of file texture_class.cpp.

{
return m_width;
}

## Initialize()

bool texture_class::Initialize | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | std::string | filename )

Definition at line 20 of file texture_class.cpp.

{
Logger::Get().Log(("Iinitializing texture: %s", filename), __FILE__, __LINE__, Logger::LogLevel::Initialize);
bool result;
D3D11_TEXTURE2D_DESC textureDesc;
HRESULT hResult;
unsigned int rowPitch;
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
// Load the targa image data into memory.
result = LoadTarga(filename);
if (!result)
{
Logger::Get().Log("Failed to load targa data", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Setup the description of the texture.
textureDesc.Height = m_height;
textureDesc.Width = m_width;
textureDesc.MipLevels = 0;
textureDesc.ArraySize = 1;
textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.Usage = D3D11_USAGE_DEFAULT;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
textureDesc.CPUAccessFlags = 0;
textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
// Create the empty texture.
hResult = device->CreateTexture2D(&textureDesc, NULL, &m_texture);
if (FAILED(hResult))
{
Logger::Get().Log("Failed to create texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the row pitch of the targa image data.
rowPitch = (m_width * 4) * sizeof(unsigned char);
// Copy the targa image data into the texture.
deviceContext->UpdateSubresource(m_texture, 0, NULL, m_targaData, rowPitch, 0);
// Setup the shader resource view description.
srvDesc.Format = textureDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = -1;
// Create the shader resource view for the texture.
hResult = device->CreateShaderResourceView(m_texture, &srvDesc, &m_textureView);
if (FAILED(hResult))
{
Logger::Get().Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Generate mipmaps for this texture.
deviceContext->GenerateMips(m_textureView);
// Release the targa image data now that the image data has been loaded into the texture.
delete[] m_targaData;
m_targaData = 0;
Logger::Get().Log("Texture initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}

## Shutdown()

void texture_class::Shutdown | ( |  | ) |

Definition at line 87 of file texture_class.cpp.

{
Logger::Get().Log("Shutting down texture", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
// Release the texture view resource.
if (m_textureView)
{
m_textureView->Release();
m_textureView = 0;
}
// Release the texture.
if (m_texture)
{
m_texture->Release();
m_texture = 0;
}
// Release the targa data.
if (m_targaData)
{
delete[] m_targaData;
m_targaData = 0;
}
Logger::Get().Log("Texture shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
return;
}

The documentation for this class was generated from the following files:

- enginecustom/src/inc/system/texture_class.h
- enginecustom/src/src/system/texture_class.cpp