summaryrefslogtreecommitdiff
path: root/src/gl/init.h
blob: ad58ac60ec682d6df4a0e9e866fed317fe16aaae (plain)
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
// Copyright 2021 Benjamin Barenblat
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

// OpenGL initialization.

#ifndef GLPLANET_SRC_GL_INIT_H_
#define GLPLANET_SRC_GL_INIT_H_

#include "src/gl/error.h"
#include "src/util.h"
#include "third_party/glew/include/GL/glew.h"

namespace gl {

// OpenGL capabilities
enum class Capability : GLenum {
  kBlend = GL_BLEND,
  kClipDistance0 = GL_CLIP_DISTANCE0,
  kClipDistance1 = GL_CLIP_DISTANCE1,
  kClipDistance2 = GL_CLIP_DISTANCE2,
  kClipDistance3 = GL_CLIP_DISTANCE3,
  kClipDistance4 = GL_CLIP_DISTANCE4,
  kClipDistance5 = GL_CLIP_DISTANCE5,
  kColorLogicOp = GL_COLOR_LOGIC_OP,
  kCullFace = GL_CULL_FACE,
  kDepthClamp = GL_DEPTH_CLAMP,
  kDepthTest = GL_DEPTH_TEST,
  kDither = GL_DITHER,
  kFramebufferSrgb = GL_FRAMEBUFFER_SRGB,
  kLineSmooth = GL_LINE_SMOOTH,
  kMultisample = GL_MULTISAMPLE,
  kPolygonOffsetFill = GL_POLYGON_OFFSET_FILL,
  kPolygonOffsetLine = GL_POLYGON_OFFSET_LINE,
  kPolygonOffsetPoint = GL_POLYGON_OFFSET_POINT,
  kPolygonSmooth = GL_POLYGON_SMOOTH,
  kRasterizerDiscard = GL_RASTERIZER_DISCARD,
  kSampleAlphaToCoverage = GL_SAMPLE_ALPHA_TO_COVERAGE,
  kSampleAlphaToOne = GL_SAMPLE_ALPHA_TO_ONE,
  kSampleCoverage = GL_SAMPLE_COVERAGE,
  kSampleShading = GL_SAMPLE_SHADING,
  kSampleMask = GL_SAMPLE_MASK,
  kScissorTest = GL_SCISSOR_TEST,
  kStencilTest = GL_STENCIL_TEST,
  kProgramPointSize = GL_PROGRAM_POINT_SIZE,

  // Added in GL 3.1
  kPrimitiveRestart = GL_PRIMITIVE_RESTART,

  // Added in GL 3.2
  kTextureCubeMapSeamless = GL_TEXTURE_CUBE_MAP_SEAMLESS,
};

// Initializes the OpenGL state machine in the current thread. The current
// thread must have an OpenGL context bound.
//
// You must call this function exactly once in your program. Once you do so, you
// may not call any other function in this namespace from any other thread.
void InitializeForThisThread();

// Enables the specified OpenGL capability.
inline void Enable(Capability cap) noexcept(
    !(gl_internal::kThreadSafetyChecks ||
      gl_internal::kAggressiveErrorChecking)) {
  gl_internal::CheckThreadSafety();
  glEnable(FromEnum(cap));
  gl_internal::UnnecessaryErrorCheck();
}

// Sets the clear color for the active framebuffer. Color coordinates should be
// in the range [0, 1].
void SetClearColor(float red, float green, float blue, float alpha);

}  // namespace gl

#endif  // GLPLANET_SRC_GL_INIT_H_