tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Color.h (2159B)


      1 //
      2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 // Color.h : Defines the Color type used throughout the ANGLE libraries
      8 
      9 #ifndef COMMON_COLOR_H_
     10 #define COMMON_COLOR_H_
     11 
     12 #include <cstdint>
     13 
     14 namespace angle
     15 {
     16 
     17 template <typename T>
     18 struct Color
     19 {
     20    Color();
     21    constexpr Color(T r, T g, T b, T a);
     22 
     23    const T *data() const { return &red; }
     24    T *ptr() { return &red; }
     25 
     26    static Color fromData(const T *data) { return Color(data[0], data[1], data[2], data[3]); }
     27    void writeData(T *data) const
     28    {
     29        data[0] = red;
     30        data[1] = green;
     31        data[2] = blue;
     32        data[3] = alpha;
     33    }
     34 
     35    T red;
     36    T green;
     37    T blue;
     38    T alpha;
     39 };
     40 
     41 template <typename T>
     42 bool operator==(const Color<T> &a, const Color<T> &b);
     43 
     44 template <typename T>
     45 bool operator!=(const Color<T> &a, const Color<T> &b);
     46 
     47 typedef Color<float> ColorF;
     48 typedef Color<int> ColorI;
     49 typedef Color<unsigned int> ColorUI;
     50 
     51 struct ColorGeneric
     52 {
     53    inline ColorGeneric();
     54    inline ColorGeneric(const ColorF &color);
     55    inline ColorGeneric(const ColorI &color);
     56    inline ColorGeneric(const ColorUI &color);
     57 
     58    enum class Type : uint8_t
     59    {
     60        Float = 0,
     61        Int   = 1,
     62        UInt  = 2
     63    };
     64 
     65    union
     66    {
     67        ColorF colorF;
     68        ColorI colorI;
     69        ColorUI colorUI;
     70    };
     71 
     72    Type type;
     73 };
     74 
     75 inline bool operator==(const ColorGeneric &a, const ColorGeneric &b);
     76 
     77 inline bool operator!=(const ColorGeneric &a, const ColorGeneric &b);
     78 
     79 struct DepthStencil
     80 {
     81    DepthStencil() : depth(0), stencil(0) {}
     82 
     83    // Double is needed to represent the 32-bit integer range of GL_DEPTH_COMPONENT32.
     84    double depth;
     85    uint32_t stencil;
     86 };
     87 }  // namespace angle
     88 
     89 // TODO: Move this fully into the angle namespace
     90 namespace gl
     91 {
     92 
     93 template <typename T>
     94 using Color        = angle::Color<T>;
     95 using ColorF       = angle::ColorF;
     96 using ColorI       = angle::ColorI;
     97 using ColorUI      = angle::ColorUI;
     98 using ColorGeneric = angle::ColorGeneric;
     99 
    100 }  // namespace gl
    101 
    102 #include "Color.inc"
    103 
    104 #endif  // COMMON_COLOR_H_