mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-04-19 01:32:58 +02: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
|
target_link_libraries(opengl_primitives
|
||||||
glm
|
glm
|
||||||
stb_image
|
stb_image
|
||||||
|
#sdl
|
||||||
|
sdl_service
|
||||||
|
|
||||||
logger
|
logger
|
||||||
resource_manager
|
resource_manager
|
||||||
|
@ -6,6 +6,7 @@ namespace MM::OpenGL {
|
|||||||
|
|
||||||
struct TextureLoaderFile;
|
struct TextureLoaderFile;
|
||||||
struct TextureLoaderConstBuffer;
|
struct TextureLoaderConstBuffer;
|
||||||
|
struct TextureLoaderSDLSurface;
|
||||||
|
|
||||||
class Texture {
|
class Texture {
|
||||||
private:
|
private:
|
||||||
@ -14,6 +15,7 @@ namespace MM::OpenGL {
|
|||||||
private:
|
private:
|
||||||
friend struct TextureLoaderFile;
|
friend struct TextureLoaderFile;
|
||||||
friend struct TextureLoaderConstBuffer;
|
friend struct TextureLoaderConstBuffer;
|
||||||
|
friend struct TextureLoaderSDLSurface;
|
||||||
|
|
||||||
Texture(
|
Texture(
|
||||||
uint32_t handle,
|
uint32_t handle,
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <mm/services/filesystem.hpp>
|
#include <mm/services/filesystem.hpp>
|
||||||
#include <mm/engine.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));
|
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
|
} // MM::OpenGL
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "./texture.hpp"
|
#include "./texture.hpp"
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
// fwd
|
// fwd
|
||||||
@ -18,6 +21,10 @@ namespace MM::OpenGL {
|
|||||||
std::shared_ptr<Texture> load(const uint8_t* data, size_t size) const;
|
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 {
|
struct TextureLoaderEmpty final {
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
std::shared_ptr<Texture> load(Args&& ... args) const {
|
std::shared_ptr<Texture> load(Args&& ... args) const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user