Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libprojectM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ target_link_libraries(projectM_main
MilkdropPreset
Renderer
hlslparser
SOIL2
stb_image
libprojectM::API
${PROJECTM_FILESYSTEM_LIBRARY}
)
Expand Down Expand Up @@ -67,7 +67,7 @@ add_library(projectM
$<TARGET_OBJECTS:Renderer>
$<TARGET_OBJECTS:UserSprites>
$<TARGET_OBJECTS:hlslparser>
$<TARGET_OBJECTS:SOIL2>
$<TARGET_OBJECTS:stb_image>
$<TARGET_OBJECTS:projectM_main>
$<TARGET_OBJECTS:projectM::Eval>
)
Expand Down
3 changes: 2 additions & 1 deletion src/libprojectM/Renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ target_link_libraries(Renderer
PUBLIC
GLM::GLM
hlslparser
SOIL2
stb_image
${PROJECTM_OPENGL_LIBRARIES}
)

set_target_properties(Renderer PROPERTIES
Expand Down
71 changes: 8 additions & 63 deletions src/libprojectM/Renderer/MilkdropNoise.cpp
Original file line number Diff line number Diff line change
@@ -1,98 +1,43 @@
#include "Renderer/MilkdropNoise.hpp"

#include "Renderer/OpenGL.h"
#include "Renderer/Texture.hpp"

#include <chrono>
#include <memory>
#include <random>

namespace libprojectM {
namespace Renderer {

auto MilkdropNoise::LowQuality() -> std::shared_ptr<Texture>
{
GLuint texture{};
{
auto textureData = generate2D(256, 1);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
}
return std::make_shared<Texture>("noise_lq", texture, GL_TEXTURE_2D, 256, 256, false);
return std::make_shared<Texture>("noise_lq", generate2D(256, 1).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
}

auto MilkdropNoise::LowQualityLite() -> std::shared_ptr<Texture>
{
GLuint texture{};

{
auto textureData = generate2D(32, 1);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
}

return std::make_shared<Texture>("noise_lq_lite", texture, GL_TEXTURE_2D, 32, 32, false);
return std::make_shared<Texture>("noise_lq_lite", generate2D(32, 1).data(), GL_TEXTURE_2D, 32, 32, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
}

auto MilkdropNoise::MediumQuality() -> std::shared_ptr<Texture>
{
GLuint texture{};

{
auto textureData = generate2D(256, 4);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
}
return std::make_shared<Texture>("noise_mq", texture, GL_TEXTURE_2D, 256, 256, false);
return std::make_shared<Texture>("noise_mq", generate2D(256, 4).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
}

auto MilkdropNoise::HighQuality() -> std::shared_ptr<Texture>
{
GLuint texture{};

{
auto textureData = generate2D(256, 8);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
}

return std::make_shared<Texture>("noise_hq", texture, GL_TEXTURE_2D, 256, 256, false);
return std::make_shared<Texture>("noise_hq", generate2D(256, 8).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
}

auto MilkdropNoise::LowQualityVolume() -> std::shared_ptr<Texture>
{
GLuint texture{};

{
auto textureData = generate3D(32, 1);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
}

return std::make_shared<Texture>("noisevol_lq", texture, GL_TEXTURE_3D, 32, 32, false);
return std::make_shared<Texture>("noisevol_lq", generate3D(32, 1).data(), GL_TEXTURE_3D, 32, 32, 32, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
}

auto MilkdropNoise::HighQualityVolume() -> std::shared_ptr<Texture>
{
GLuint texture{};

{
auto textureData = generate3D(32, 4);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
}

return std::make_shared<Texture>("noisevol_hq", texture, GL_TEXTURE_3D, 32, 32, false);
return std::make_shared<Texture>("noisevol_hq", generate3D(32, 4).data(), GL_TEXTURE_3D, 32, 32, 32, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
}

auto MilkdropNoise::GetPreferredInternalFormat() -> int
Expand Down
56 changes: 53 additions & 3 deletions src/libprojectM/Renderer/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Texture::Texture(std::string name, const int width, const int height, const bool
CreateNewTexture();
}

Texture::Texture(std::string name, int width, int height,
Texture::Texture(std::string name, GLenum target, int width, int height, int depth,
GLint internalFormat, GLenum format, GLenum type, bool isUserTexture)
: m_target(GL_TEXTURE_2D)
: m_target(target)
, m_name(std::move(name))
, m_width(width)
, m_height(height)
, m_depth(depth)
, m_isUserTexture(isUserTexture)
, m_internalFormat(internalFormat)
, m_format(format)
Expand All @@ -43,6 +44,21 @@ Texture::Texture(std::string name, const GLuint texID, const GLenum target,
{
}

Texture::Texture(std::string name, const void* data, GLenum target, int width, int height, int depth, GLint internalFormat, GLenum format, GLenum type, bool isUserTexture)
: m_target(target)
, m_name(std::move(name))
, m_width(width)
, m_height(height)
, m_depth(depth)
, m_isUserTexture(isUserTexture)
, m_internalFormat(internalFormat)
, m_format(format)
, m_type(type)
{
glGenTextures(1, &m_textureId);
Update(data);
}

Texture::~Texture()
{
if (m_textureId > 0)
Expand Down Expand Up @@ -94,6 +110,11 @@ auto Texture::Height() const -> int
return m_height;
}

auto Texture::Depth() const -> int
{
return m_depth;
}

auto Texture::IsUserTexture() const -> bool
{
return m_isUserTexture;
Expand All @@ -104,11 +125,40 @@ auto Texture::Empty() const -> bool
return m_textureId == 0;
}

void Texture::Update(const void* data) const
{
glBindTexture(m_target, m_textureId);
switch (m_target)
{
case GL_TEXTURE_2D:
glTexImage2D(m_target, 0, m_internalFormat, m_width, m_height, 0, m_format, m_type, data);
break;
case GL_TEXTURE_3D:
glTexImage3D(m_target, 0, m_internalFormat, m_width, m_height, m_depth, 0, m_format, m_type, data);
break;
default:
// Unsupported, do nothing.
break;
}
glBindTexture(m_target, 0);
}

void Texture::CreateNewTexture()
{
glGenTextures(1, &m_textureId);
glBindTexture(m_target, m_textureId);
glTexImage2D(m_target, 0, m_internalFormat, m_width, m_height, 0, m_format, m_type, nullptr);
switch (m_target)
{
case GL_TEXTURE_2D:
glTexImage2D(m_target, 0, m_internalFormat, m_width, m_height, 0, m_format, m_type, nullptr);
break;
case GL_TEXTURE_3D:
glTexImage3D(m_target, 0, m_internalFormat, m_width, m_height, m_depth, 0, m_format, m_type, nullptr);
break;
default:
// Unsupported, do nothing.
break;
}
glBindTexture(m_target, 0);
}

Expand Down
37 changes: 36 additions & 1 deletion src/libprojectM/Renderer/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ class Texture
/**
* @brief Constructor. Allocates a new, empty texture with the given size and format.
* @param name Optional name of the texture for referencing in Milkdrop shaders.
* @param target The texture target, either TEXTURE_2D or TEXTURE_3D.
* @param width Width in pixels.
* @param height Height in pixels.
* @param depth Depth in pixels (for 3D textures).
* @param internalFormat OpenGL internal texture format.
* @param format OpenGL texture format.
* @param type Storage type for each color channel.
* @param isUserTexture true if the texture is an externally-loaded image, false if it's an internal texture.
*/
explicit Texture(std::string name, int width, int height,
explicit Texture(std::string name, GLenum target, int width, int height, int depth,
GLint internalFormat, GLenum format, GLenum type, bool isUserTexture);

/**
Expand All @@ -60,6 +65,22 @@ class Texture
int width, int height,
bool isUserTexture);

/**
* @brief Constructor. Creates a new texture from image data with the given size and format.
* @param name Optional name of the texture for referencing in Milkdrop shaders.
* @param data The texture data to upload.
* @param target The texture target, either TEXTURE_2D or TEXTURE_3D.
* @param width Width in pixels.
* @param height Height in pixels.
* @param depth Depth in pixels (for 3D textures).
* @param internalFormat OpenGL internal texture format.
* @param format OpenGL texture format.
* @param type Storage type for each color channel.
* @param isUserTexture true if the texture is an externally-loaded image, false if it's an internal texture.
*/
explicit Texture(std::string name, const void* data, GLenum target, int width, int height, int depth,
GLint internalFormat, GLenum format, GLenum type, bool isUserTexture);

Texture(Texture&& other) = default;
auto operator=(Texture&& other) -> Texture& = default;

Expand Down Expand Up @@ -109,6 +130,12 @@ class Texture
*/
auto Height() const -> int;

/**
* @brief Returns the depth of the texture image in pixels.
* @return The depth of the texture image in pixels.
*/
auto Depth() const -> int;

/**
* @brief Returns if the texture is user-defined, e.g. loaded from an image.
* @return true if the texture is a user texture, false if it's an internally generated texture.
Expand All @@ -121,6 +148,13 @@ class Texture
*/
auto Empty() const -> bool;

/**
* @brief Uploads new image data for the texture.
* @note Automatically binds and unbinds the texture.
* @param data The new texture image data. Must match the size and format used to create the texture.
*/
void Update(const void* data) const;

private:
/**
* @brief Creates a new, blank texture with the given size.
Expand All @@ -133,6 +167,7 @@ class Texture
std::string m_name; //!< The texture name for identifying it in shaders.
int m_width{0}; //!< Texture width in pixels.
int m_height{0}; //!< Texture height in pixels.
int m_depth{0}; //!< Texture depth in pixels. Only used for 3D textures.
bool m_isUserTexture{false}; //!< true if it's a user texture, false if an internal one.

GLint m_internalFormat{}; //!< OpenGL internal format, e.g. GL_RGBA8
Expand Down
Loading
Loading