added rest of basics in TSE_Core
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include "extern/imgui_impl_glfw.h"
|
||||
#include "extern/imgui_impl_opengl3.h"
|
||||
#include "PathHelper.hpp"
|
||||
#include "elements/Texture.hpp"
|
||||
#include "TextureHelperOpenGL.hpp"
|
||||
|
||||
TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync)
|
||||
: OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ }
|
||||
@@ -32,6 +34,8 @@ TSE::GLFW::OpenGLRenderingBackend::~OpenGLRenderingBackend()
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::InitPreWindow()
|
||||
{
|
||||
Texture::helper = new TextureHelperOpenGL();
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, TSE_OPENGL_VERSION_MAJOR);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, TSE_OPENGL_VERSION_MINOR);
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
|
||||
|
||||
60
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp
Normal file
60
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "TextureHelperOpenGL.hpp"
|
||||
#include <GL/gl3w.h>
|
||||
|
||||
void TSE::GLFW::TextureHelperOpenGL::Bind(const Texture *tex)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, tex->GetTextureId());
|
||||
}
|
||||
|
||||
void TSE::GLFW::TextureHelperOpenGL::UnBind(const Texture *tex)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void TSE::GLFW::TextureHelperOpenGL::Apply(Texture *tex)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, tex->GetTextureId());
|
||||
if(tex->Chanels() == 1)
|
||||
{
|
||||
if (tex->bpp() == 8)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||
}
|
||||
if(tex->Chanels() == 3)
|
||||
{
|
||||
if(tex->bpp() == 24)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_BGR, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||
}
|
||||
else if(tex->Chanels() == 4)
|
||||
{
|
||||
if(tex->bpp() == 32)
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||
if (tex->bpp() == 8) //need to decode it with bitwise operations in shader
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, tex->width(), tex->height(), 0, GL_RED, GL_UNSIGNED_BYTE, tex->GetImagePtr());
|
||||
}
|
||||
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void TSE::GLFW::TextureHelperOpenGL::Regist(Texture *tex)
|
||||
{
|
||||
uint TextureID;
|
||||
|
||||
glGenTextures(1, &TextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, TextureID);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
tex->SetTextureId(TextureID);
|
||||
|
||||
tex->Apply();
|
||||
}
|
||||
|
||||
void TSE::GLFW::TextureHelperOpenGL::PlatromDestroy(Texture *tex)
|
||||
{
|
||||
uint id = tex->GetTextureId();
|
||||
glDeleteTextures(1, &id);
|
||||
}
|
||||
17
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.hpp
Normal file
17
TSE_GlfwOpenGlImpl/src/TextureHelperOpenGL.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "interfaces/ITextureHelper.hpp"
|
||||
#include "elements/Texture.hpp"
|
||||
|
||||
namespace TSE::GLFW
|
||||
{
|
||||
class TextureHelperOpenGL : public ITextureHelper
|
||||
{
|
||||
public:
|
||||
void Bind(const Texture* tex) override;
|
||||
void UnBind(const Texture* tex) override;
|
||||
void Apply(Texture* tex) override;
|
||||
void Regist(Texture* tex) override;
|
||||
void PlatromDestroy(Texture* tex) override;
|
||||
};
|
||||
} // namespace TSE::GLFW
|
||||
Reference in New Issue
Block a user