// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3

#pragma once

#ifndef GLAD_GL_H_
typedef unsigned int GLuint;
typedef int          GLint;
typedef unsigned int GLenum;
typedef int          GLsizei;
#endif
#include <cstdint>

namespace dragonx {
namespace ui {
namespace effects {

/**
 * @brief Generates procedural noise textures for acrylic grain effect
 * 
 * Creates a tileable noise texture that adds subtle grain to acrylic surfaces,
 * matching Microsoft's Fluent Design acrylic material.
 */
class NoiseTexture {
public:
    NoiseTexture();
    ~NoiseTexture();
    
    // Non-copyable
    NoiseTexture(const NoiseTexture&) = delete;
    NoiseTexture& operator=(const NoiseTexture&) = delete;
    
    /**
     * @brief Generate a noise texture
     * @param size Texture size (width = height, should be power of 2)
     * @param intensity Noise intensity (0.0 - 1.0, typical: 0.02 - 0.04)
     * @return true if successful
     */
    bool generate(int size = 128, float intensity = 0.04f);
    
    /**
     * @brief Release texture resources
     */
    void destroy();
    
    /**
     * @brief Get the OpenGL texture ID
     */
    GLuint getTexture() const { return texture_; }
    
    /**
     * @brief Check if texture is valid
     */
    bool isValid() const { return texture_ != 0; }
    
    /**
     * @brief Get texture size
     */
    int getSize() const { return size_; }

    /**
     * @brief Simple pseudo-random number generator
     * @param seed Seed value (modified in place)
     * @return Random float in range [0, 1]
     */
    static float random(uint32_t& seed);
    
    /**
     * @brief Generate tileable Perlin-style noise value
     */
    static float noise2D(float x, float y, int wrap);

private:
    GLuint texture_ = 0;
    int size_ = 0;
};

/**
 * @brief Static utility functions for noise generation
 */
namespace NoiseUtils {

/**
 * @brief Create a simple white noise texture
 * @param size Texture dimensions (square)
 * @return OpenGL texture ID (0 on failure)
 */
GLuint createWhiteNoiseTexture(int size);

/**
 * @brief Create a blue noise texture (better for dithering)
 * @param size Texture dimensions (square)
 * @return OpenGL texture ID (0 on failure)
 */
GLuint createBlueNoiseTexture(int size);

/**
 * @brief Create a pre-computed acrylic noise texture
 * 
 * This creates a specially tuned noise texture that matches
 * Microsoft's acrylic material appearance.
 * 
 * @param size Texture dimensions (128 recommended)
 * @return OpenGL texture ID (0 on failure)
 */
GLuint createAcrylicNoiseTexture(int size = 128);

} // namespace NoiseUtils

} // namespace effects
} // namespace ui
} // namespace dragonx
