summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp99
-rw-r--r--src/video_core/renderer_opengl/gl_state.h146
2 files changed, 75 insertions, 170 deletions
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index bf86b5a0b..88c32bd4f 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -80,104 +80,7 @@ void Enable(GLenum cap, GLuint index, bool& current_value, bool new_value) {
80 80
81} // namespace 81} // namespace
82 82
83OpenGLState::OpenGLState() { 83OpenGLState::OpenGLState() = default;
84 // These all match default OpenGL values
85 framebuffer_srgb.enabled = false;
86
87 multisample_control.alpha_to_coverage = false;
88 multisample_control.alpha_to_one = false;
89
90 cull.enabled = false;
91 cull.mode = GL_BACK;
92 cull.front_face = GL_CCW;
93
94 depth.test_enabled = false;
95 depth.test_func = GL_LESS;
96 depth.write_mask = GL_TRUE;
97
98 primitive_restart.enabled = false;
99 primitive_restart.index = 0;
100
101 for (auto& item : color_mask) {
102 item.red_enabled = GL_TRUE;
103 item.green_enabled = GL_TRUE;
104 item.blue_enabled = GL_TRUE;
105 item.alpha_enabled = GL_TRUE;
106 }
107
108 const auto ResetStencil = [](auto& config) {
109 config.test_func = GL_ALWAYS;
110 config.test_ref = 0;
111 config.test_mask = 0xFFFFFFFF;
112 config.write_mask = 0xFFFFFFFF;
113 config.action_depth_fail = GL_KEEP;
114 config.action_depth_pass = GL_KEEP;
115 config.action_stencil_fail = GL_KEEP;
116 };
117 stencil.test_enabled = false;
118 ResetStencil(stencil.front);
119 ResetStencil(stencil.back);
120
121 for (auto& item : viewports) {
122 item.x = 0;
123 item.y = 0;
124 item.width = 0;
125 item.height = 0;
126 item.depth_range_near = 0.0f;
127 item.depth_range_far = 1.0f;
128 item.scissor.enabled = false;
129 item.scissor.x = 0;
130 item.scissor.y = 0;
131 item.scissor.width = 0;
132 item.scissor.height = 0;
133 }
134
135 for (auto& item : blend) {
136 item.enabled = true;
137 item.rgb_equation = GL_FUNC_ADD;
138 item.a_equation = GL_FUNC_ADD;
139 item.src_rgb_func = GL_ONE;
140 item.dst_rgb_func = GL_ZERO;
141 item.src_a_func = GL_ONE;
142 item.dst_a_func = GL_ZERO;
143 }
144
145 independant_blend.enabled = false;
146
147 blend_color.red = 0.0f;
148 blend_color.green = 0.0f;
149 blend_color.blue = 0.0f;
150 blend_color.alpha = 0.0f;
151
152 logic_op.enabled = false;
153 logic_op.operation = GL_COPY;
154
155 draw.read_framebuffer = 0;
156 draw.draw_framebuffer = 0;
157 draw.vertex_array = 0;
158 draw.shader_program = 0;
159 draw.program_pipeline = 0;
160
161 clip_distance = {};
162
163 point.size = 1;
164
165 fragment_color_clamp.enabled = false;
166
167 depth_clamp.far_plane = false;
168 depth_clamp.near_plane = false;
169
170 polygon_offset.fill_enable = false;
171 polygon_offset.line_enable = false;
172 polygon_offset.point_enable = false;
173 polygon_offset.factor = 0.0f;
174 polygon_offset.units = 0.0f;
175 polygon_offset.clamp = 0.0f;
176
177 alpha_test.enabled = false;
178 alpha_test.func = GL_ALWAYS;
179 alpha_test.ref = 0.0f;
180}
181 84
182void OpenGLState::SetDefaultViewports() { 85void OpenGLState::SetDefaultViewports() {
183 for (auto& item : viewports) { 86 for (auto& item : viewports) {
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index c358d3b38..27ea98246 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <type_traits>
8#include <glad/glad.h> 9#include <glad/glad.h>
9#include "video_core/engines/maxwell_3d.h" 10#include "video_core/engines/maxwell_3d.h"
10 11
@@ -36,137 +37,137 @@ constexpr TextureUnit ProcTexDiffLUT{9};
36class OpenGLState { 37class OpenGLState {
37public: 38public:
38 struct { 39 struct {
39 bool enabled; // GL_FRAMEBUFFER_SRGB 40 bool enabled = false; // GL_FRAMEBUFFER_SRGB
40 } framebuffer_srgb; 41 } framebuffer_srgb;
41 42
42 struct { 43 struct {
43 bool alpha_to_coverage; // GL_ALPHA_TO_COVERAGE 44 bool alpha_to_coverage = false; // GL_ALPHA_TO_COVERAGE
44 bool alpha_to_one; // GL_ALPHA_TO_ONE 45 bool alpha_to_one = false; // GL_ALPHA_TO_ONE
45 } multisample_control; 46 } multisample_control;
46 47
47 struct { 48 struct {
48 bool enabled; // GL_CLAMP_FRAGMENT_COLOR_ARB 49 bool enabled = false; // GL_CLAMP_FRAGMENT_COLOR_ARB
49 } fragment_color_clamp; 50 } fragment_color_clamp;
50 51
51 struct { 52 struct {
52 bool far_plane; 53 bool far_plane = false;
53 bool near_plane; 54 bool near_plane = false;
54 } depth_clamp; // GL_DEPTH_CLAMP 55 } depth_clamp; // GL_DEPTH_CLAMP
55 56
56 struct { 57 struct {
57 bool enabled; // GL_CULL_FACE 58 bool enabled = false; // GL_CULL_FACE
58 GLenum mode; // GL_CULL_FACE_MODE 59 GLenum mode = GL_BACK; // GL_CULL_FACE_MODE
59 GLenum front_face; // GL_FRONT_FACE 60 GLenum front_face = GL_CCW; // GL_FRONT_FACE
60 } cull; 61 } cull;
61 62
62 struct { 63 struct {
63 bool test_enabled; // GL_DEPTH_TEST 64 bool test_enabled = false; // GL_DEPTH_TEST
64 GLenum test_func; // GL_DEPTH_FUNC 65 GLboolean write_mask = GL_TRUE; // GL_DEPTH_WRITEMASK
65 GLboolean write_mask; // GL_DEPTH_WRITEMASK 66 GLenum test_func = GL_LESS; // GL_DEPTH_FUNC
66 } depth; 67 } depth;
67 68
68 struct { 69 struct {
69 bool enabled; 70 bool enabled = false;
70 GLuint index; 71 GLuint index = 0;
71 } primitive_restart; // GL_PRIMITIVE_RESTART 72 } primitive_restart; // GL_PRIMITIVE_RESTART
72 73
73 struct ColorMask { 74 struct ColorMask {
74 GLboolean red_enabled; 75 GLboolean red_enabled = GL_TRUE;
75 GLboolean green_enabled; 76 GLboolean green_enabled = GL_TRUE;
76 GLboolean blue_enabled; 77 GLboolean blue_enabled = GL_TRUE;
77 GLboolean alpha_enabled; 78 GLboolean alpha_enabled = GL_TRUE;
78 }; 79 };
79 std::array<ColorMask, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> 80 std::array<ColorMask, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets>
80 color_mask; // GL_COLOR_WRITEMASK 81 color_mask; // GL_COLOR_WRITEMASK
81 struct { 82 struct {
82 bool test_enabled; // GL_STENCIL_TEST 83 bool test_enabled = false; // GL_STENCIL_TEST
83 struct { 84 struct {
84 GLenum test_func; // GL_STENCIL_FUNC 85 GLenum test_func = GL_ALWAYS; // GL_STENCIL_FUNC
85 GLint test_ref; // GL_STENCIL_REF 86 GLint test_ref = 0; // GL_STENCIL_REF
86 GLuint test_mask; // GL_STENCIL_VALUE_MASK 87 GLuint test_mask = 0xFFFFFFFF; // GL_STENCIL_VALUE_MASK
87 GLuint write_mask; // GL_STENCIL_WRITEMASK 88 GLuint write_mask = 0xFFFFFFFF; // GL_STENCIL_WRITEMASK
88 GLenum action_stencil_fail; // GL_STENCIL_FAIL 89 GLenum action_stencil_fail = GL_KEEP; // GL_STENCIL_FAIL
89 GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL 90 GLenum action_depth_fail = GL_KEEP; // GL_STENCIL_PASS_DEPTH_FAIL
90 GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS 91 GLenum action_depth_pass = GL_KEEP; // GL_STENCIL_PASS_DEPTH_PASS
91 } front, back; 92 } front, back;
92 } stencil; 93 } stencil;
93 94
94 struct Blend { 95 struct Blend {
95 bool enabled; // GL_BLEND 96 bool enabled = true; // GL_BLEND
96 GLenum rgb_equation; // GL_BLEND_EQUATION_RGB 97 GLenum rgb_equation = GL_FUNC_ADD; // GL_BLEND_EQUATION_RGB
97 GLenum a_equation; // GL_BLEND_EQUATION_ALPHA 98 GLenum a_equation = GL_FUNC_ADD; // GL_BLEND_EQUATION_ALPHA
98 GLenum src_rgb_func; // GL_BLEND_SRC_RGB 99 GLenum src_rgb_func = GL_ONE; // GL_BLEND_SRC_RGB
99 GLenum dst_rgb_func; // GL_BLEND_DST_RGB 100 GLenum dst_rgb_func = GL_ZERO; // GL_BLEND_DST_RGB
100 GLenum src_a_func; // GL_BLEND_SRC_ALPHA 101 GLenum src_a_func = GL_ONE; // GL_BLEND_SRC_ALPHA
101 GLenum dst_a_func; // GL_BLEND_DST_ALPHA 102 GLenum dst_a_func = GL_ZERO; // GL_BLEND_DST_ALPHA
102 }; 103 };
103 std::array<Blend, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> blend; 104 std::array<Blend, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> blend;
104 105
105 struct { 106 struct {
106 bool enabled; 107 bool enabled = false;
107 } independant_blend; 108 } independant_blend;
108 109
109 struct { 110 struct {
110 GLclampf red; 111 GLclampf red = 0.0f;
111 GLclampf green; 112 GLclampf green = 0.0f;
112 GLclampf blue; 113 GLclampf blue = 0.0f;
113 GLclampf alpha; 114 GLclampf alpha = 0.0f;
114 } blend_color; // GL_BLEND_COLOR 115 } blend_color; // GL_BLEND_COLOR
115 116
116 struct { 117 struct {
117 bool enabled; // GL_LOGIC_OP_MODE 118 bool enabled = false; // GL_LOGIC_OP_MODE
118 GLenum operation; 119 GLenum operation = GL_COPY;
119 } logic_op; 120 } logic_op;
120 121
121 std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> textures{}; 122 std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> textures = {};
122 std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> samplers{}; 123 std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> samplers = {};
123 std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumImages> images{}; 124 std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumImages> images = {};
124 125
125 struct { 126 struct {
126 GLuint read_framebuffer; // GL_READ_FRAMEBUFFER_BINDING 127 GLuint read_framebuffer = 0; // GL_READ_FRAMEBUFFER_BINDING
127 GLuint draw_framebuffer; // GL_DRAW_FRAMEBUFFER_BINDING 128 GLuint draw_framebuffer = 0; // GL_DRAW_FRAMEBUFFER_BINDING
128 GLuint vertex_array; // GL_VERTEX_ARRAY_BINDING 129 GLuint vertex_array = 0; // GL_VERTEX_ARRAY_BINDING
129 GLuint shader_program; // GL_CURRENT_PROGRAM 130 GLuint shader_program = 0; // GL_CURRENT_PROGRAM
130 GLuint program_pipeline; // GL_PROGRAM_PIPELINE_BINDING 131 GLuint program_pipeline = 0; // GL_PROGRAM_PIPELINE_BINDING
131 } draw; 132 } draw;
132 133
133 struct viewport { 134 struct Viewport {
134 GLint x; 135 GLint x = 0;
135 GLint y; 136 GLint y = 0;
136 GLint width; 137 GLint width = 0;
137 GLint height; 138 GLint height = 0;
138 GLfloat depth_range_near; // GL_DEPTH_RANGE 139 GLfloat depth_range_near = 0.0f; // GL_DEPTH_RANGE
139 GLfloat depth_range_far; // GL_DEPTH_RANGE 140 GLfloat depth_range_far = 1.0f; // GL_DEPTH_RANGE
140 struct { 141 struct {
141 bool enabled; // GL_SCISSOR_TEST 142 bool enabled = false; // GL_SCISSOR_TEST
142 GLint x; 143 GLint x = 0;
143 GLint y; 144 GLint y = 0;
144 GLsizei width; 145 GLsizei width = 0;
145 GLsizei height; 146 GLsizei height = 0;
146 } scissor; 147 } scissor;
147 }; 148 };
148 std::array<viewport, Tegra::Engines::Maxwell3D::Regs::NumViewports> viewports; 149 std::array<Viewport, Tegra::Engines::Maxwell3D::Regs::NumViewports> viewports;
149 150
150 struct { 151 struct {
151 float size; // GL_POINT_SIZE 152 float size = 1.0f; // GL_POINT_SIZE
152 } point; 153 } point;
153 154
154 struct { 155 struct {
155 bool point_enable; 156 bool point_enable = false;
156 bool line_enable; 157 bool line_enable = false;
157 bool fill_enable; 158 bool fill_enable = false;
158 GLfloat units; 159 GLfloat units = 0.0f;
159 GLfloat factor; 160 GLfloat factor = 0.0f;
160 GLfloat clamp; 161 GLfloat clamp = 0.0f;
161 } polygon_offset; 162 } polygon_offset;
162 163
163 struct { 164 struct {
164 bool enabled; // GL_ALPHA_TEST 165 bool enabled = false; // GL_ALPHA_TEST
165 GLenum func; // GL_ALPHA_TEST_FUNC 166 GLenum func = GL_ALWAYS; // GL_ALPHA_TEST_FUNC
166 GLfloat ref; // GL_ALPHA_TEST_REF 167 GLfloat ref = 0.0f; // GL_ALPHA_TEST_REF
167 } alpha_test; 168 } alpha_test;
168 169
169 std::array<bool, 8> clip_distance; // GL_CLIP_DISTANCE 170 std::array<bool, 8> clip_distance = {}; // GL_CLIP_DISTANCE
170 171
171 OpenGLState(); 172 OpenGLState();
172 173
@@ -253,5 +254,6 @@ private:
253 bool color_mask; 254 bool color_mask;
254 } dirty{}; 255 } dirty{};
255}; 256};
257static_assert(std::is_trivially_copyable_v<OpenGLState>);
256 258
257} // namespace OpenGL 259} // namespace OpenGL