#pragma once #include #include namespace frostbite2D { // ============================================================================ // 像素格式枚举 // ============================================================================ enum class PixelFormat { R8, // 单通道灰度 RG8, // 双通道 RGB8, // RGB RGBA8, // RGBA R16F, // 半精度浮点单通道 RG16F, // 半精度浮点双通道 RGB16F, // 半精度浮点RGB RGBA16F, // 半精度浮点RGBA R32F, // 单精度浮点单通道 RG32F, // 单精度浮点双通道 RGB32F, // 单精度浮点RGB RGBA32F, // 单精度浮点RGBA // 压缩格式 ETC2_RGB8, ETC2_RGBA8, ASTC_4x4, ASTC_6x6, ASTC_8x8, }; // ============================================================================ // 纹理抽象基类 // ============================================================================ class Texture { public: virtual ~Texture() = default; /** * @brief 获取纹理宽度 * @return 纹理宽度(像素) */ virtual int getWidth() const = 0; /** * @brief 获取纹理高度 * @return 纹理高度(像素) */ virtual int getHeight() const = 0; /** * @brief 获取纹理尺寸 * @return 纹理尺寸 */ virtual Size getSize() const = 0; /** * @brief 获取颜色通道数 * @return 颜色通道数 */ virtual int getChannels() const = 0; /** * @brief 获取像素格式 * @return 像素格式 */ virtual PixelFormat getFormat() const = 0; /** * @brief 获取原生句柄 * @return 原生句柄(如OpenGL纹理ID) */ virtual void *getNativeHandle() const = 0; /** * @brief 检查纹理是否有效 * @return 有效返回true,否则返回false */ virtual bool isValid() const = 0; /** * @brief 设置纹理过滤模式 * @param linear true使用线性过滤,false使用最近邻过滤 */ virtual void setFilter(bool linear) = 0; /** * @brief 设置纹理环绕模式 * @param repeat true使用重复模式,false使用边缘拉伸模式 */ virtual void setWrap(bool repeat) = 0; }; // ============================================================================ // Alpha遮罩 - 用于像素级碰撞检测 // ============================================================================ class AlphaMask { public: AlphaMask() = default; AlphaMask(AlphaMask &&) = default; AlphaMask &operator=(AlphaMask &&) = default; /** * @brief 从像素数据创建Alpha遮罩 * @param pixels 像素数据指针 * @param width 宽度 * @param height 高度 * @param channels 通道数 * @return 创建的AlphaMask */ static AlphaMask createFromPixels(const uint8_t *pixels, int width, int height, int channels); /** * @brief 检查遮罩是否有效 * @return 有效返回true */ bool isValid() const { return !data_.empty() && width_ > 0 && height_ > 0; } /** * @brief 获取指定位置的透明度 * @param x X坐标 * @param y Y坐标 * @return 透明度值(0-255) */ uint8_t getAlpha(int x, int y) const; /** * @brief 检查指定位置是否不透明 * @param x X坐标 * @param y Y坐标 * @return 不透明返回true */ bool isOpaque(int x, int y) const; /** * @brief 获取宽度 * @return 宽度 */ int getWidth() const { return width_; } /** * @brief 获取高度 * @return 高度 */ int getHeight() const { return height_; } private: std::vector data_; int width_ = 0; int height_ = 0; }; } // namespace frostbite2D