Skip to content

Commit 99bfcf9

Browse files
committed
Simplify texture creation in MilkdropNoise
1 parent ba8023e commit 99bfcf9

1 file changed

Lines changed: 8 additions & 63 deletions

File tree

src/libprojectM/Renderer/MilkdropNoise.cpp

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,43 @@
11
#include "Renderer/MilkdropNoise.hpp"
22

33
#include "Renderer/OpenGL.h"
4+
#include "Renderer/Texture.hpp"
45

56
#include <chrono>
7+
#include <memory>
68
#include <random>
79

810
namespace libprojectM {
911
namespace Renderer {
1012

1113
auto MilkdropNoise::LowQuality() -> std::shared_ptr<Texture>
1214
{
13-
GLuint texture{};
14-
{
15-
auto textureData = generate2D(256, 1);
16-
17-
glGenTextures(1, &texture);
18-
glBindTexture(GL_TEXTURE_2D, texture);
19-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
20-
}
21-
return std::make_shared<Texture>("noise_lq", texture, GL_TEXTURE_2D, 256, 256, false);
15+
return std::make_shared<Texture>("noise_lq", generate2D(256, 1).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
2216
}
2317

2418
auto MilkdropNoise::LowQualityLite() -> std::shared_ptr<Texture>
2519
{
26-
GLuint texture{};
27-
28-
{
29-
auto textureData = generate2D(32, 1);
30-
31-
glGenTextures(1, &texture);
32-
glBindTexture(GL_TEXTURE_2D, texture);
33-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
34-
}
35-
36-
return std::make_shared<Texture>("noise_lq_lite", texture, GL_TEXTURE_2D, 32, 32, false);
20+
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);
3721
}
3822

3923
auto MilkdropNoise::MediumQuality() -> std::shared_ptr<Texture>
4024
{
41-
GLuint texture{};
42-
43-
{
44-
auto textureData = generate2D(256, 4);
45-
46-
glGenTextures(1, &texture);
47-
glBindTexture(GL_TEXTURE_2D, texture);
48-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
49-
}
50-
return std::make_shared<Texture>("noise_mq", texture, GL_TEXTURE_2D, 256, 256, false);
25+
return std::make_shared<Texture>("noise_mq", generate2D(256, 4).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
5126
}
5227

5328
auto MilkdropNoise::HighQuality() -> std::shared_ptr<Texture>
5429
{
55-
GLuint texture{};
56-
57-
{
58-
auto textureData = generate2D(256, 8);
59-
60-
glGenTextures(1, &texture);
61-
glBindTexture(GL_TEXTURE_2D, texture);
62-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 256, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
63-
}
64-
65-
return std::make_shared<Texture>("noise_hq", texture, GL_TEXTURE_2D, 256, 256, false);
30+
return std::make_shared<Texture>("noise_hq", generate2D(256, 8).data(), GL_TEXTURE_2D, 256, 256, 0, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
6631
}
6732

6833
auto MilkdropNoise::LowQualityVolume() -> std::shared_ptr<Texture>
6934
{
70-
GLuint texture{};
71-
72-
{
73-
auto textureData = generate3D(32, 1);
74-
75-
glGenTextures(1, &texture);
76-
glBindTexture(GL_TEXTURE_3D, texture);
77-
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
78-
}
79-
80-
return std::make_shared<Texture>("noisevol_lq", texture, GL_TEXTURE_3D, 32, 32, false);
35+
return std::make_shared<Texture>("noisevol_lq", generate3D(32, 1).data(), GL_TEXTURE_3D, 32, 32, 32, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
8136
}
8237

8338
auto MilkdropNoise::HighQualityVolume() -> std::shared_ptr<Texture>
8439
{
85-
GLuint texture{};
86-
87-
{
88-
auto textureData = generate3D(32, 4);
89-
90-
glGenTextures(1, &texture);
91-
glBindTexture(GL_TEXTURE_3D, texture);
92-
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 32, 32, 32, 0, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, textureData.data());
93-
}
94-
95-
return std::make_shared<Texture>("noisevol_hq", texture, GL_TEXTURE_3D, 32, 32, false);
40+
return std::make_shared<Texture>("noisevol_hq", generate3D(32, 4).data(), GL_TEXTURE_3D, 32, 32, 32, GL_RGBA8, GetPreferredInternalFormat(), GL_UNSIGNED_BYTE, false);
9641
}
9742

9843
auto MilkdropNoise::GetPreferredInternalFormat() -> int

0 commit comments

Comments
 (0)