mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2024-12-04 19:23:28 +01:00
add opengl texture from sdl_surface
This commit is contained in:
parent
07df333e3e
commit
4e2dd51ad1
@ -11,6 +11,8 @@ target_include_directories(opengl_primitives PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}
|
||||
target_link_libraries(opengl_primitives
|
||||
glm
|
||||
stb_image
|
||||
#sdl
|
||||
sdl_service
|
||||
|
||||
logger
|
||||
resource_manager
|
||||
|
@ -6,6 +6,7 @@ namespace MM::OpenGL {
|
||||
|
||||
struct TextureLoaderFile;
|
||||
struct TextureLoaderConstBuffer;
|
||||
struct TextureLoaderSDLSurface;
|
||||
|
||||
class Texture {
|
||||
private:
|
||||
@ -14,6 +15,7 @@ namespace MM::OpenGL {
|
||||
private:
|
||||
friend struct TextureLoaderFile;
|
||||
friend struct TextureLoaderConstBuffer;
|
||||
friend struct TextureLoaderSDLSurface;
|
||||
|
||||
Texture(
|
||||
uint32_t handle,
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <glad/glad.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <mm/services/filesystem.hpp>
|
||||
#include <mm/engine.hpp>
|
||||
|
||||
@ -129,5 +128,31 @@ std::shared_ptr<Texture> TextureLoaderConstBuffer::load(const uint8_t* data, siz
|
||||
return std::shared_ptr<Texture>(new Texture(handle, width, height, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE));
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> TextureLoaderSDLSurface::load(SDL_Surface* surface) const {
|
||||
uint32_t handle;
|
||||
|
||||
glGenTextures(1, &handle);
|
||||
glBindTexture(GL_TEXTURE_2D, handle);
|
||||
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
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);
|
||||
|
||||
SDL_LockSurface(surface);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
SDL_UnlockSurface(surface);
|
||||
|
||||
return std::shared_ptr<Texture>(new Texture(handle, surface->w, surface->h, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE));
|
||||
}
|
||||
|
||||
} // MM::OpenGL
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "./texture.hpp"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
// fwd
|
||||
@ -18,6 +21,10 @@ namespace MM::OpenGL {
|
||||
std::shared_ptr<Texture> load(const uint8_t* data, size_t size) const;
|
||||
};
|
||||
|
||||
struct TextureLoaderSDLSurface final {
|
||||
std::shared_ptr<Texture> load(SDL_Surface* surface) const;
|
||||
};
|
||||
|
||||
struct TextureLoaderEmpty final {
|
||||
template<typename... Args>
|
||||
std::shared_ptr<Texture> load(Args&& ... args) const {
|
||||
|
Loading…
Reference in New Issue
Block a user