~ changed readTexture for containers to produce a CTexture file ready to be used (simplifies loading textures)

~ fixed a write to null error on CDirectory that wasn't taking into account that length can be null

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2021-09-05 14:29:11 +02:00
parent 5c56d68a69
commit 113d84173e
6 changed files with 14 additions and 21 deletions

View File

@ -5,12 +5,14 @@
using namespace WallpaperEngine::Assets;
void* CContainer::readTexture (std::string filename, uint32_t* length)
CTexture* CContainer::readTexture (std::string filename)
{
// get the texture's filename (usually .tex)
filename = "materials/" + filename + ".tex";
return this->readFile (filename, length);
void* textureContents = this->readFile (filename, nullptr);
return new CTexture (textureContents);
}
std::string CContainer::readVertexShader (const std::string& filename)

View File

@ -5,6 +5,7 @@
#pragma once
#include <string>
#include "WallpaperEngine/Assets/CTexture.h"
namespace WallpaperEngine::Assets
{
@ -26,17 +27,15 @@ namespace WallpaperEngine::Assets
* Wrapper for readFile, appends the texture extension at the end of the filename
*
* @param filename The texture name (without the .tex)
* @param length The file's length after it's been read
*
* @return
*/
void* readTexture (std::string filename, uint32_t* length);
CTexture* readTexture (std::string filename);
/**
* Wrapper for readFile, appends the .vert extension at the end and opens the given shader file
*
* @param filename
* @param length
*
* @return The shader code as an string to be used
*/
@ -46,7 +45,6 @@ namespace WallpaperEngine::Assets
* Wrapper for readFile, appends the .frag extension at the end and opens the given shader file
*
* @param filename
* @param length
*
* @return The shader code as an string to be used
*/
@ -56,7 +54,6 @@ namespace WallpaperEngine::Assets
* Wrapper for readFile, appends the .h extension at the end and opens the given shader file
*
* @param filename
* @param length
*
* @return The shader code as an string to be used
*/

View File

@ -22,7 +22,9 @@ void* CDirectory::readFile (std::string filename, uint32_t* length)
if (it != this->m_cache.end ())
{
if (length != nullptr)
*length = (*it).second.length;
return (*it).second.address;
}

View File

@ -37,11 +37,9 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) :
uint32_t textureSize = 0;
// get the first texture on the first pass (this one represents the image assigned to this object)
void* textureData = this->getScene ()->getContainer ()->readTexture (
(*(*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ()), &textureSize
this->m_texture = this->getScene ()->getContainer ()->readTexture (
(*(*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ())
);
// now generate our opengl texture
this->m_texture = new CTexture (textureData);
// build a list of vertices, these might need some change later (or maybe invert the camera)
GLfloat data [] = {

View File

@ -450,11 +450,9 @@ void CPass::setupTextures ()
uint32_t textureSize = 0;
// get the first texture on the first pass (this one represents the image assigned to this object)
void* textureData = this->m_material->getImage ()->getContainer ()->readTexture (
(*cur), &textureSize
this->m_textures.emplace_back (
this->m_material->getImage ()->getContainer ()->readTexture ((*cur))
);
// load a new texture and push it into the list
this->m_textures.emplace_back (new CTexture (textureData));
}
}

View File

@ -599,12 +599,8 @@ namespace WallpaperEngine::Render::Shaders
// TODO: CHECK WHAT TEXTURE THIS REFERS TO
// add the new combo to the list
this->m_combos.insert (std::make_pair<std::string, int> (*combo, 1));
uint32_t textureSize = 0;
// also ensure that the textureName is loaded and we know about it
void* textureData = this->m_container->readTexture ((*textureName).get <std::string> (), &textureSize);
// now generate our opengl textureName
CTexture* texture = new CTexture (textureData);
CTexture* texture = this->m_container->readTexture ((*textureName).get <std::string> ());
// extract the texture number from the name
char value = name.at (std::string("g_Texture").length ());
// now convert it to integer