File: render.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (104 lines) | stat: -rw-r--r-- 2,942 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once

#include <ostream>

#include "render/Colour4.h"

namespace debug
{
    namespace detail
    {
        inline bool boolFromGLBool(GLboolean b)
        {
            return b == GL_TRUE;
        }
    }

    /// Streamable object to insert render state flags
    struct StateFlagsInserter
    {
        int flags;
        StateFlagsInserter(int f): flags(f) { }
    };

    inline std::ostream& operator<<(std::ostream& os,
                                    const StateFlagsInserter& s)
    {
        #define OUTPUT_RENDERFLAG(x) if (s.flags & (x)) { os << "|" << #x; }
        OUTPUT_RENDERFLAG(RENDER_LINESTIPPLE);
        OUTPUT_RENDERFLAG(RENDER_POLYGONSTIPPLE);
        OUTPUT_RENDERFLAG(RENDER_ALPHATEST);
        OUTPUT_RENDERFLAG(RENDER_DEPTHTEST);
        OUTPUT_RENDERFLAG(RENDER_DEPTHWRITE);
        OUTPUT_RENDERFLAG(RENDER_MASKCOLOUR);
        OUTPUT_RENDERFLAG(RENDER_CULLFACE);
        OUTPUT_RENDERFLAG(RENDER_SCALED);
        OUTPUT_RENDERFLAG(RENDER_SMOOTH);
        OUTPUT_RENDERFLAG(RENDER_LIGHTING);
        OUTPUT_RENDERFLAG(RENDER_BLEND);
        OUTPUT_RENDERFLAG(RENDER_OFFSETLINE);
        OUTPUT_RENDERFLAG(RENDER_FILL);
        OUTPUT_RENDERFLAG(RENDER_VERTEX_COLOUR);
        OUTPUT_RENDERFLAG(RENDER_TEXTURE_2D);
        OUTPUT_RENDERFLAG(RENDER_TEXTURE_CUBEMAP);
        OUTPUT_RENDERFLAG(RENDER_BUMP);
        OUTPUT_RENDERFLAG(RENDER_PROGRAM);
        OUTPUT_RENDERFLAG(RENDER_OVERRIDE);
        return os;
    }

    /// Streamable object to insert glColorMask value
    class ColorMaskInserter { };

    inline std::ostream& operator<<(std::ostream& os,
                                    const ColorMaskInserter& i)
    {
        using namespace detail;

        GLboolean vals[4];
        glGetBooleanv(GL_COLOR_WRITEMASK, &vals[0]);

        os << "{ R = " << boolFromGLBool(vals[0])
           << ", G = " << boolFromGLBool(vals[1])
           << ", B = " << boolFromGLBool(vals[2])
           << ", A = " << boolFromGLBool(vals[3]) << " }";
        return os;
    }

    /// Streamable object to insert glDepthMask value
    class DepthMaskInserter { };

    inline std::ostream& operator<<(std::ostream& os,
                                    const DepthMaskInserter& i)
    {
        GLboolean mask;
        glGetBooleanv(GL_DEPTH_WRITEMASK, &mask);

        os << detail::boolFromGLBool(mask);
        return os;
    }

    /// Get the current GL_COLOR as a Colour4 for debugging
    inline Colour4 getGLColor()
    {
        Colour4 result;
        glGetFloatv(GL_CURRENT_COLOR, &result[0]);
        return result;
    }

    /// Get a GL integer for debugging
    inline int getGLInt(GLenum name)
    {
        int result;
        glGetIntegerv(name, &result);
        return result;
    }

    /// Get a GL boolean for debugging
    inline bool getGLBool(GLenum name)
    {
        GLboolean result;
        glGetBooleanv(name, &result);
        return result == GL_TRUE;
    }
}