VN System improved.
This commit is contained in:
		| @@ -1,76 +1,76 @@ | ||||
| // Copyright (c) 2022 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "Texture.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void Texture::bind(textureslot_t slot) { | ||||
|   if(this->id == -1) throw "Texture has not been initialized, cannot bind."; | ||||
|   glActiveTexture(GL_TEXTURE0 + slot); | ||||
|   glBindTexture(GL_TEXTURE_2D, this->id); | ||||
| } | ||||
|  | ||||
| int32_t Texture::getWidth() { | ||||
|   return this->width; | ||||
| } | ||||
|  | ||||
| int32_t Texture::getHeight() { | ||||
|   return this->height; | ||||
| } | ||||
|  | ||||
| void Texture::setSize(int32_t width, int32_t height) { | ||||
|   if(this->id != -1) glDeleteTextures(1, &this->id); | ||||
|  | ||||
|   this->width = width; | ||||
|   this->height = height; | ||||
|  | ||||
|   glGenTextures(1, &this->id); | ||||
|   if(this->id <= 0) throw "Texture generation failed!"; | ||||
|    | ||||
|   glActiveTexture(GL_TEXTURE0); | ||||
|   glBindTexture(GL_TEXTURE_2D, this->id); | ||||
|  | ||||
|   // Setup our preferred texture params, later this will be configurable. | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||
|  | ||||
|   // Initialize the texture to blank | ||||
|   glTexImage2D( | ||||
|     GL_TEXTURE_2D, 0, GL_RGBA, | ||||
|     width, height, | ||||
|     0, GL_RGBA, GL_FLOAT, NULL | ||||
|   ); | ||||
| } | ||||
|  | ||||
| void Texture::fill(struct Color color) { | ||||
|   struct Color *pixels = (struct Color *)memoryAllocate( | ||||
|     sizeof(struct Color) * this->width * this->height | ||||
|   ); | ||||
|  | ||||
|   this->buffer(pixels); | ||||
|  | ||||
|   memoryFree(pixels); | ||||
| } | ||||
|  | ||||
| bool_t Texture::isReady() { | ||||
|   return this->id != -1; | ||||
| } | ||||
|        | ||||
| void Texture::buffer(struct Color pixels[]) { | ||||
|   glBindTexture(GL_TEXTURE_2D, this->id); | ||||
|  | ||||
|   glTexImage2D( | ||||
|     GL_TEXTURE_2D, 0, GL_RGBA, | ||||
|     this->width, this->height, | ||||
|     0, GL_RGBA, GL_FLOAT, (void *)pixels | ||||
|   ); | ||||
| } | ||||
|  | ||||
| Texture::~Texture() { | ||||
|   if(this->id != -1) glDeleteTextures(1, &this->id); | ||||
| // Copyright (c) 2022 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "Texture.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void Texture::bind(textureslot_t slot) { | ||||
|   assertTrue(this->id != -1); | ||||
|   glActiveTexture(GL_TEXTURE0 + slot); | ||||
|   glBindTexture(GL_TEXTURE_2D, this->id); | ||||
| } | ||||
|  | ||||
| int32_t Texture::getWidth() { | ||||
|   return this->width; | ||||
| } | ||||
|  | ||||
| int32_t Texture::getHeight() { | ||||
|   return this->height; | ||||
| } | ||||
|  | ||||
| void Texture::setSize(int32_t width, int32_t height) { | ||||
|   if(this->id != -1) glDeleteTextures(1, &this->id); | ||||
|  | ||||
|   this->width = width; | ||||
|   this->height = height; | ||||
|  | ||||
|   glGenTextures(1, &this->id); | ||||
|   if(this->id <= 0) throw "Texture generation failed!"; | ||||
|    | ||||
|   glActiveTexture(GL_TEXTURE0); | ||||
|   glBindTexture(GL_TEXTURE_2D, this->id); | ||||
|  | ||||
|   // Setup our preferred texture params, later this will be configurable. | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
|   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||
|  | ||||
|   // Initialize the texture to blank | ||||
|   glTexImage2D( | ||||
|     GL_TEXTURE_2D, 0, GL_RGBA, | ||||
|     width, height, | ||||
|     0, GL_RGBA, GL_FLOAT, NULL | ||||
|   ); | ||||
| } | ||||
|  | ||||
| void Texture::fill(struct Color color) { | ||||
|   struct Color *pixels = (struct Color *)memoryAllocate( | ||||
|     sizeof(struct Color) * this->width * this->height | ||||
|   ); | ||||
|  | ||||
|   this->buffer(pixels); | ||||
|  | ||||
|   memoryFree(pixels); | ||||
| } | ||||
|  | ||||
| bool_t Texture::isReady() { | ||||
|   return this->id != -1; | ||||
| } | ||||
|        | ||||
| void Texture::buffer(struct Color pixels[]) { | ||||
|   glBindTexture(GL_TEXTURE_2D, this->id); | ||||
|  | ||||
|   glTexImage2D( | ||||
|     GL_TEXTURE_2D, 0, GL_RGBA, | ||||
|     this->width, this->height, | ||||
|     0, GL_RGBA, GL_FLOAT, (void *)pixels | ||||
|   ); | ||||
| } | ||||
|  | ||||
| Texture::~Texture() { | ||||
|   if(this->id != -1) glDeleteTextures(1, &this->id); | ||||
| } | ||||
| @@ -5,6 +5,7 @@ | ||||
|  | ||||
| #pragma once | ||||
| #include "dawnopengl.hpp" | ||||
| #include "assert/assert.hpp" | ||||
| #include "display/_Texture.hpp" | ||||
| #include "util/memory.hpp" | ||||
|  | ||||
|   | ||||
| @@ -45,7 +45,7 @@ namespace Dawn { | ||||
|         shaderparameter_t param, | ||||
|         Texture *texture | ||||
|       ) override { | ||||
|         if(texture == nullptr) { | ||||
|         if(texture == nullptr || !texture->isReady()) { | ||||
|           this->setBoolean(this->paramHasTexture, false); | ||||
|         } else { | ||||
|           this->setBoolean(this->paramHasTexture, true); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user