Fixed vita textures, broke non-vita textures
This commit is contained in:
		| @@ -33,11 +33,12 @@ void BackBufferRenderTarget::setClearColor(struct Color color) { | ||||
| } | ||||
|  | ||||
| void BackBufferRenderTarget::clear(flag8_t clearFlags) { | ||||
|   auto clear = this->clearColor.precision(); | ||||
|   glClearColor( | ||||
|     this->clearColor.r, | ||||
|     this->clearColor.g, | ||||
|     this->clearColor.b, | ||||
|     this->clearColor.a | ||||
|     clear.r, | ||||
|     clear.g, | ||||
|     clear.b, | ||||
|     clear.a | ||||
|   ); | ||||
|   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||
| } | ||||
|   | ||||
| @@ -45,7 +45,7 @@ void Texture::setSize(int32_t width, int32_t height) { | ||||
|   glTexImage2D( | ||||
|     GL_TEXTURE_2D, 0, GL_RGBA, | ||||
|     width, height, | ||||
|     0, GL_RGBA, GL_FLOAT, NULL | ||||
|     0, GL_RGBA, GL_UNSIGNED_BYTE, NULL | ||||
|   ); | ||||
| } | ||||
|  | ||||
| @@ -69,7 +69,7 @@ void Texture::buffer(struct Color pixels[]) { | ||||
|   glTexImage2D( | ||||
|     GL_TEXTURE_2D, 0, GL_RGBA, | ||||
|     this->width, this->height, | ||||
|     0, GL_RGBA, GL_FLOAT, (void *)pixels | ||||
|     0, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pixels | ||||
|   ); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -67,11 +67,12 @@ void TextureRenderTarget::setClearColor(struct Color color) { | ||||
| } | ||||
|  | ||||
| void TextureRenderTarget::clear(flag8_t clearFlags) { | ||||
|   auto clear = this->clearColor.precision(); | ||||
|   glClearColor( | ||||
|     this->clearColor.r, | ||||
|     this->clearColor.g, | ||||
|     this->clearColor.b, | ||||
|     this->clearColor.a | ||||
|     clear.r, | ||||
|     clear.g, | ||||
|     clear.b, | ||||
|     clear.a | ||||
|   ); | ||||
|   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||
| } | ||||
|   | ||||
| @@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME} | ||||
|   PRIVATE | ||||
|     ShaderProgram.cpp | ||||
|     SimpleTexturedShader.cpp | ||||
|     SimpleTexturedShaderProgram.cpp | ||||
| ) | ||||
| @@ -8,6 +8,7 @@ | ||||
| using namespace Dawn; | ||||
|  | ||||
| void ShaderProgram::compileShader( | ||||
|   std::map<std::string, int32_t> attributeLocations, | ||||
|   std::string vertexShader, | ||||
|   std::string fragmentShader | ||||
| ) { | ||||
| @@ -51,6 +52,15 @@ void ShaderProgram::compileShader( | ||||
|   glAttachShader(this->shaderProgram, this->shaderVertex); | ||||
|   glAttachShader(this->shaderProgram, this->shaderFrag); | ||||
|  | ||||
|   // Now parse out the variables. | ||||
|   #if DAWN_OPENGL_HLSL | ||||
|     auto itAttr = attributeLocations.begin(); | ||||
|     while(itAttr != attributeLocations.end()) { | ||||
|       this->bindAttributeLocation(itAttr->first, itAttr->second); | ||||
|       ++itAttr; | ||||
|     } | ||||
|   #endif | ||||
|  | ||||
|   //Bind, Verify & Use the shader program | ||||
|   glLinkProgram(this->shaderProgram); | ||||
|   glGetProgramiv(this->shaderProgram, GL_LINK_STATUS, &isSuccess); | ||||
| @@ -63,10 +73,6 @@ void ShaderProgram::compileShader( | ||||
|     debugMessage(error); | ||||
|     throw error; | ||||
|   } | ||||
|  | ||||
|   // Now parse out the variables. | ||||
| 	glBindAttribLocation(this->shaderProgram, 0, "aPos"); | ||||
| 	glBindAttribLocation(this->shaderProgram, 1, "aTexCoord"); | ||||
| } | ||||
|  | ||||
| void ShaderProgram::bindAttributeLocation(std::string name, int32_t location) { | ||||
|   | ||||
| @@ -31,7 +31,11 @@ namespace Dawn { | ||||
|        * @param vertexShader The string source of the vertex shader. | ||||
|        * @param fragmentShader The string source of the fragment shader. | ||||
|        */ | ||||
|       void compileShader(std::string vertexShader, std::string fragmentShader); | ||||
|       void compileShader( | ||||
|         std::map<std::string, int32_t> attributeLocations, | ||||
|         std::string vertexShader, | ||||
|         std::string fragmentShader | ||||
|       ); | ||||
|  | ||||
|       /** | ||||
|        * Typically HLSL only, this method allows you to specify where vbo  | ||||
|   | ||||
| @@ -0,0 +1,95 @@ | ||||
| // Copyright (c) 2023 Dominic Masters | ||||
| //  | ||||
| // This software is released under the MIT License. | ||||
| // https://opensource.org/licenses/MIT | ||||
|  | ||||
| #include "SimpleTexturedShaderProgram.hpp" | ||||
|  | ||||
| using namespace Dawn; | ||||
|  | ||||
| void SimpleTexturedShaderProgram::compile() { | ||||
|   #if DAWN_OPENGL_GLSL | ||||
|     this->compileShader( | ||||
|       { | ||||
|         { "aPos", 0 }, | ||||
|         { "aTexCoord", 1 } | ||||
|       }, | ||||
|       // Vertex Shader | ||||
|       "#version 330 core\n" | ||||
|       "layout (location = 0) in vec3 aPos;\n" | ||||
|       "layout (location = 1) in vec2 aTexCoord;\n" | ||||
|  | ||||
|       "uniform mat4 u_Proj;\n" | ||||
|       "uniform mat4 u_View;\n" | ||||
|       "uniform mat4 u_Model;\n" | ||||
|  | ||||
|       "out vec2 o_TextCoord;\n" | ||||
|       "void main() {\n" | ||||
|         "gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n" | ||||
|         "o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n" | ||||
|       "}", | ||||
|  | ||||
|       // Fragment Shader | ||||
|       "#version 330 core\n" | ||||
|       "in vec2 o_TextCoord;\n" | ||||
|       "out vec4 o_Color;\n" | ||||
|       "uniform vec4 u_Color;\n" | ||||
|       "uniform bool u_HasTexture;\n" | ||||
|       "uniform sampler2D u_Text;\n" | ||||
|  | ||||
|       "void main() {\n" | ||||
|         "if(u_HasTexture) {\n" | ||||
|           "o_Color = texture(u_Text, o_TextCoord) * u_Color;\n" | ||||
|         "} else {\n" | ||||
|           "o_Color = u_Color;" | ||||
|         "}\n" | ||||
|       "}\n" | ||||
|     ); | ||||
|   #elif DAWN_OPENGL_HLSL | ||||
|     this->compileShader( | ||||
|       { | ||||
|         { "aPos", 0 }, | ||||
|         { "aTexCoord", 1 } | ||||
|       }, | ||||
|       // Vertex Shader | ||||
|       "uniform float4x4 u_Proj;\n" | ||||
|       "uniform float4x4 u_View;\n" | ||||
|       "uniform float4x4 u_Model;\n" | ||||
|       "void main(" | ||||
|         "float3 aPos,\n" | ||||
|         "float2 aTexCoord,\n" | ||||
|         "float2 out o_TextCoord : TEXCOORD0,\n" | ||||
|         "float4 out gl_Position : POSITION\n" | ||||
|       ") {\n"  | ||||
|         "o_TextCoord = aTexCoord;\n" | ||||
|         "gl_Position = mul(mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj);\n" | ||||
|       "}", | ||||
|  | ||||
|       // Fragment Shader | ||||
|       "uniform float4 u_Color;\n" | ||||
|       "uniform bool u_HasTexture;\n" | ||||
|       "uniform sampler2D u_Text : TEXUNIT0;\n" | ||||
|  | ||||
|       "float4 main(\n" | ||||
|         "float2 o_TextCoord : TEXCOORD0\n" | ||||
|       ") {\n" | ||||
|         "float4 o_Color;\n" | ||||
|         "if(u_HasTexture) {\n" | ||||
|           "o_Color = float4(tex2D(u_Text, o_TextCoord).xyz, 1.0);\n" | ||||
|         "} else {\n" | ||||
|           "o_Color = u_Color;\n" | ||||
|         "}\n" | ||||
|         "return o_Color;\n" | ||||
|       "}\n" | ||||
|     ); | ||||
|   #else | ||||
|     #error Shader Type must be either GLSL or HLSL | ||||
|   #endif | ||||
|  | ||||
|   this->paramProjection = this->getParameterByName("u_Proj"); | ||||
|   this->paramView = this->getParameterByName("u_View"); | ||||
|   this->paramModel = this->getParameterByName("u_Model"); | ||||
|   this->paramColor = this->getParameterByName("u_Color"); | ||||
|   this->paramTexture = this->getParameterByName("u_Text"); | ||||
|   this->paramHasTexture = this->getParameterByName("u_HasTexture"); | ||||
| } | ||||
| @@ -16,86 +16,6 @@ namespace Dawn { | ||||
|       shaderparameter_t paramTexture; | ||||
|       shaderparameter_t paramHasTexture; | ||||
|  | ||||
|       void compile() override { | ||||
|         #if DAWN_OPENGL_GLSL | ||||
|           this->compileShader( | ||||
|             // Vertex Shader | ||||
|             "#version 330 core\n" | ||||
|             "layout (location = 0) in vec3 aPos;\n" | ||||
|             "layout (location = 1) in vec2 aTexCoord;\n" | ||||
|  | ||||
|             "uniform mat4 u_Proj;\n" | ||||
|             "uniform mat4 u_View;\n" | ||||
|             "uniform mat4 u_Model;\n" | ||||
|  | ||||
|             "out vec2 o_TextCoord;\n" | ||||
|             "void main() {\n" | ||||
|               "gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n" | ||||
|               "o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n" | ||||
|             "}", | ||||
|  | ||||
|             // Fragment Shader | ||||
|             "#version 330 core\n" | ||||
|             "in vec2 o_TextCoord;\n" | ||||
|             "out vec4 o_Color;\n" | ||||
|             "uniform vec4 u_Color;\n" | ||||
|             "uniform bool u_HasTexture;\n" | ||||
|             "uniform sampler2D u_Text;\n" | ||||
|  | ||||
|             "void main() {\n" | ||||
|               "if(u_HasTexture) {\n" | ||||
|                 "o_Color = texture(u_Text, o_TextCoord) * u_Color;\n" | ||||
|               "} else {\n" | ||||
|                 "o_Color = u_Color;" | ||||
|               "}\n" | ||||
|             "}\n" | ||||
|           ); | ||||
|         #elif DAWN_OPENGL_HLSL | ||||
|           this->compileShader( | ||||
|             // Vertex Shader | ||||
|             "uniform float4x4 u_Proj;\n" | ||||
|             "uniform float4x4 u_View;\n" | ||||
|             "uniform float4x4 u_Model;\n" | ||||
|             "void main(" | ||||
|               "float3 aPos,\n" | ||||
|               // "float2 aTexCoord,\n" | ||||
|               "float3 out o_TextCoord : TEXCOORD0,\n" | ||||
|               "float4 out gl_Position : POSITION\n" | ||||
|             ") {\n" | ||||
|               // "o_TextCoord = float3(aTexCoord.x, 0.0, 1.0);\n" | ||||
|               "gl_Position = mul(mul(mul(float4(aPos, 1.0), u_Model), u_View), u_Proj);\n" | ||||
|             "}", | ||||
|  | ||||
|             // Fragment Shader | ||||
|             "uniform float4 u_Color;\n" | ||||
|             "uniform bool u_HasTexture;\n" | ||||
|             "uniform sampler2D u_Text;\n" | ||||
|  | ||||
|             "float4 main(\n" | ||||
|               "float3 o_TextCoord : TEXCOORD0\n" | ||||
|             ") {\n" | ||||
|               "float4 o_Color;\n" | ||||
|               "if(u_HasTexture) {\n" | ||||
|                 // "o_Color = mul(tex2D(u_Text, o_TextCoord), u_Color);\n" | ||||
|               "} else {\n" | ||||
|                 "o_Color = u_Color;\n" | ||||
|               "}\n" | ||||
|               "return o_Color;\n" | ||||
|             "}\n" | ||||
|           ); | ||||
|  | ||||
|           this->bindAttributeLocation("aPos", 0); | ||||
|           this->bindAttributeLocation("aTexCoord", 1); | ||||
|         #else | ||||
|           #error Shader Type must be either GLSL or HLSL | ||||
|         #endif | ||||
|  | ||||
|         this->paramProjection = this->getParameterByName("u_Proj"); | ||||
|         this->paramView = this->getParameterByName("u_View"); | ||||
|         this->paramModel = this->getParameterByName("u_Model"); | ||||
|         this->paramColor = this->getParameterByName("u_Color"); | ||||
|         this->paramTexture = this->getParameterByName("u_Text"); | ||||
|         this->paramHasTexture = this->getParameterByName("u_HasTexture"); | ||||
|       } | ||||
|       void compile() override ; | ||||
|   }; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user