summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar bunnei2018-08-31 23:54:31 -0400
committerGravatar bunnei2018-09-08 02:53:37 -0400
commitb56e5edafcc18901c08634b1730f1e1870a14891 (patch)
treeb91531252b3743a2d62df9cf7b86a3e89a011ad7 /src/video_core
parentMerge pull request #1257 from lioncash/process (diff)
downloadyuzu-b56e5edafcc18901c08634b1730f1e1870a14891.tar.gz
yuzu-b56e5edafcc18901c08634b1730f1e1870a14891.tar.xz
yuzu-b56e5edafcc18901c08634b1730f1e1870a14891.zip
gl_state: Keep track of texture target.
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp6
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp12
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp8
-rw-r--r--src/video_core/renderer_opengl/gl_state.h8
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp20
5 files changed, 28 insertions, 26 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 6e89fa6e3..d5bbfbd1c 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -692,14 +692,14 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
692 const auto texture = maxwell3d.GetStageTexture(entry.GetStage(), entry.GetOffset()); 692 const auto texture = maxwell3d.GetStageTexture(entry.GetStage(), entry.GetOffset());
693 693
694 if (!texture.enabled) { 694 if (!texture.enabled) {
695 state.texture_units[current_bindpoint].texture_2d = 0; 695 state.texture_units[current_bindpoint].texture = 0;
696 continue; 696 continue;
697 } 697 }
698 698
699 texture_samplers[current_bindpoint].SyncWithConfig(texture.tsc); 699 texture_samplers[current_bindpoint].SyncWithConfig(texture.tsc);
700 Surface surface = res_cache.GetTextureSurface(texture); 700 Surface surface = res_cache.GetTextureSurface(texture);
701 if (surface != nullptr) { 701 if (surface != nullptr) {
702 state.texture_units[current_bindpoint].texture_2d = surface->Texture().handle; 702 state.texture_units[current_bindpoint].texture = surface->Texture().handle;
703 state.texture_units[current_bindpoint].swizzle.r = 703 state.texture_units[current_bindpoint].swizzle.r =
704 MaxwellToGL::SwizzleSource(texture.tic.x_source); 704 MaxwellToGL::SwizzleSource(texture.tic.x_source);
705 state.texture_units[current_bindpoint].swizzle.g = 705 state.texture_units[current_bindpoint].swizzle.g =
@@ -710,7 +710,7 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
710 MaxwellToGL::SwizzleSource(texture.tic.w_source); 710 MaxwellToGL::SwizzleSource(texture.tic.w_source);
711 } else { 711 } else {
712 // Can occur when texture addr is null or its memory is unmapped/invalid 712 // Can occur when texture addr is null or its memory is unmapped/invalid
713 state.texture_units[current_bindpoint].texture_2d = 0; 713 state.texture_units[current_bindpoint].texture = 0;
714 } 714 }
715 } 715 }
716 716
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index f6b2c5a86..ea2e6a3a2 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -363,8 +363,8 @@ static void AllocateSurfaceTexture(GLuint texture, const FormatTuple& format_tup
363 OpenGLState cur_state = OpenGLState::GetCurState(); 363 OpenGLState cur_state = OpenGLState::GetCurState();
364 364
365 // Keep track of previous texture bindings 365 // Keep track of previous texture bindings
366 GLuint old_tex = cur_state.texture_units[0].texture_2d; 366 GLuint old_tex = cur_state.texture_units[0].texture;
367 cur_state.texture_units[0].texture_2d = texture; 367 cur_state.texture_units[0].texture = texture;
368 cur_state.Apply(); 368 cur_state.Apply();
369 glActiveTexture(GL_TEXTURE0); 369 glActiveTexture(GL_TEXTURE0);
370 370
@@ -380,7 +380,7 @@ static void AllocateSurfaceTexture(GLuint texture, const FormatTuple& format_tup
380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
381 381
382 // Restore previous texture bindings 382 // Restore previous texture bindings
383 cur_state.texture_units[0].texture_2d = old_tex; 383 cur_state.texture_units[0].texture = old_tex;
384 cur_state.Apply(); 384 cur_state.Apply();
385} 385}
386 386
@@ -600,8 +600,8 @@ void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle
600 GLuint target_tex = texture.handle; 600 GLuint target_tex = texture.handle;
601 OpenGLState cur_state = OpenGLState::GetCurState(); 601 OpenGLState cur_state = OpenGLState::GetCurState();
602 602
603 GLuint old_tex = cur_state.texture_units[0].texture_2d; 603 GLuint old_tex = cur_state.texture_units[0].texture;
604 cur_state.texture_units[0].texture_2d = target_tex; 604 cur_state.texture_units[0].texture = target_tex;
605 cur_state.Apply(); 605 cur_state.Apply();
606 606
607 // Ensure no bad interactions with GL_UNPACK_ALIGNMENT 607 // Ensure no bad interactions with GL_UNPACK_ALIGNMENT
@@ -622,7 +622,7 @@ void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle
622 622
623 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 623 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
624 624
625 cur_state.texture_units[0].texture_2d = old_tex; 625 cur_state.texture_units[0].texture = old_tex;
626 cur_state.Apply(); 626 cur_state.Apply();
627} 627}
628 628
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index 60a4defd1..6f70deb96 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -200,9 +200,9 @@ void OpenGLState::Apply() const {
200 const auto& texture_unit = texture_units[i]; 200 const auto& texture_unit = texture_units[i];
201 const auto& cur_state_texture_unit = cur_state.texture_units[i]; 201 const auto& cur_state_texture_unit = cur_state.texture_units[i];
202 202
203 if (texture_unit.texture_2d != cur_state_texture_unit.texture_2d) { 203 if (texture_unit.texture != cur_state_texture_unit.texture) {
204 glActiveTexture(TextureUnits::MaxwellTexture(static_cast<int>(i)).Enum()); 204 glActiveTexture(TextureUnits::MaxwellTexture(static_cast<int>(i)).Enum());
205 glBindTexture(GL_TEXTURE_2D, texture_unit.texture_2d); 205 glBindTexture(texture_unit.target, texture_unit.texture);
206 } 206 }
207 if (texture_unit.sampler != cur_state_texture_unit.sampler) { 207 if (texture_unit.sampler != cur_state_texture_unit.sampler) {
208 glBindSampler(static_cast<GLuint>(i), texture_unit.sampler); 208 glBindSampler(static_cast<GLuint>(i), texture_unit.sampler);
@@ -214,7 +214,7 @@ void OpenGLState::Apply() const {
214 texture_unit.swizzle.a != cur_state_texture_unit.swizzle.a) { 214 texture_unit.swizzle.a != cur_state_texture_unit.swizzle.a) {
215 std::array<GLint, 4> mask = {texture_unit.swizzle.r, texture_unit.swizzle.g, 215 std::array<GLint, 4> mask = {texture_unit.swizzle.r, texture_unit.swizzle.g,
216 texture_unit.swizzle.b, texture_unit.swizzle.a}; 216 texture_unit.swizzle.b, texture_unit.swizzle.a};
217 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, mask.data()); 217 glTexParameteriv(texture_unit.target, GL_TEXTURE_SWIZZLE_RGBA, mask.data());
218 } 218 }
219 } 219 }
220 220
@@ -287,7 +287,7 @@ void OpenGLState::Apply() const {
287 287
288OpenGLState& OpenGLState::UnbindTexture(GLuint handle) { 288OpenGLState& OpenGLState::UnbindTexture(GLuint handle) {
289 for (auto& unit : texture_units) { 289 for (auto& unit : texture_units) {
290 if (unit.texture_2d == handle) { 290 if (unit.texture == handle) {
291 unit.Unbind(); 291 unit.Unbind();
292 } 292 }
293 } 293 }
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 46e96a97d..e3e24b9e7 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -94,8 +94,9 @@ public:
94 94
95 // 3 texture units - one for each that is used in PICA fragment shader emulation 95 // 3 texture units - one for each that is used in PICA fragment shader emulation
96 struct TextureUnit { 96 struct TextureUnit {
97 GLuint texture_2d; // GL_TEXTURE_BINDING_2D 97 GLuint texture; // GL_TEXTURE_BINDING_2D
98 GLuint sampler; // GL_SAMPLER_BINDING 98 GLuint sampler; // GL_SAMPLER_BINDING
99 GLenum target;
99 struct { 100 struct {
100 GLint r; // GL_TEXTURE_SWIZZLE_R 101 GLint r; // GL_TEXTURE_SWIZZLE_R
101 GLint g; // GL_TEXTURE_SWIZZLE_G 102 GLint g; // GL_TEXTURE_SWIZZLE_G
@@ -104,7 +105,7 @@ public:
104 } swizzle; 105 } swizzle;
105 106
106 void Unbind() { 107 void Unbind() {
107 texture_2d = 0; 108 texture = 0;
108 swizzle.r = GL_RED; 109 swizzle.r = GL_RED;
109 swizzle.g = GL_GREEN; 110 swizzle.g = GL_GREEN;
110 swizzle.b = GL_BLUE; 111 swizzle.b = GL_BLUE;
@@ -114,6 +115,7 @@ public:
114 void Reset() { 115 void Reset() {
115 Unbind(); 116 Unbind();
116 sampler = 0; 117 sampler = 0;
118 target = GL_TEXTURE_2D;
117 } 119 }
118 }; 120 };
119 std::array<TextureUnit, 32> texture_units; 121 std::array<TextureUnit, 32> texture_units;
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 411a73d50..ccff3e342 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -177,7 +177,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf
177 Memory::GetPointer(framebuffer_addr), 177 Memory::GetPointer(framebuffer_addr),
178 gl_framebuffer_data.data(), true); 178 gl_framebuffer_data.data(), true);
179 179
180 state.texture_units[0].texture_2d = screen_info.texture.resource.handle; 180 state.texture_units[0].texture = screen_info.texture.resource.handle;
181 state.Apply(); 181 state.Apply();
182 182
183 glActiveTexture(GL_TEXTURE0); 183 glActiveTexture(GL_TEXTURE0);
@@ -194,7 +194,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf
194 194
195 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 195 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
196 196
197 state.texture_units[0].texture_2d = 0; 197 state.texture_units[0].texture = 0;
198 state.Apply(); 198 state.Apply();
199 } 199 }
200} 200}
@@ -205,7 +205,7 @@ void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuf
205 */ 205 */
206void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a, 206void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
207 const TextureInfo& texture) { 207 const TextureInfo& texture) {
208 state.texture_units[0].texture_2d = texture.resource.handle; 208 state.texture_units[0].texture = texture.resource.handle;
209 state.Apply(); 209 state.Apply();
210 210
211 glActiveTexture(GL_TEXTURE0); 211 glActiveTexture(GL_TEXTURE0);
@@ -214,7 +214,7 @@ void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color
214 // Update existing texture 214 // Update existing texture
215 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, framebuffer_data); 215 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, framebuffer_data);
216 216
217 state.texture_units[0].texture_2d = 0; 217 state.texture_units[0].texture = 0;
218 state.Apply(); 218 state.Apply();
219} 219}
220 220
@@ -260,7 +260,7 @@ void RendererOpenGL::InitOpenGLObjects() {
260 // Allocation of storage is deferred until the first frame, when we 260 // Allocation of storage is deferred until the first frame, when we
261 // know the framebuffer size. 261 // know the framebuffer size.
262 262
263 state.texture_units[0].texture_2d = screen_info.texture.resource.handle; 263 state.texture_units[0].texture = screen_info.texture.resource.handle;
264 state.Apply(); 264 state.Apply();
265 265
266 glActiveTexture(GL_TEXTURE0); 266 glActiveTexture(GL_TEXTURE0);
@@ -272,7 +272,7 @@ void RendererOpenGL::InitOpenGLObjects() {
272 272
273 screen_info.display_texture = screen_info.texture.resource.handle; 273 screen_info.display_texture = screen_info.texture.resource.handle;
274 274
275 state.texture_units[0].texture_2d = 0; 275 state.texture_units[0].texture = 0;
276 state.Apply(); 276 state.Apply();
277 277
278 // Clear screen to black 278 // Clear screen to black
@@ -305,14 +305,14 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
305 UNREACHABLE(); 305 UNREACHABLE();
306 } 306 }
307 307
308 state.texture_units[0].texture_2d = texture.resource.handle; 308 state.texture_units[0].texture = texture.resource.handle;
309 state.Apply(); 309 state.Apply();
310 310
311 glActiveTexture(GL_TEXTURE0); 311 glActiveTexture(GL_TEXTURE0);
312 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, texture.width, texture.height, 0, 312 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, texture.width, texture.height, 0,
313 texture.gl_format, texture.gl_type, nullptr); 313 texture.gl_format, texture.gl_type, nullptr);
314 314
315 state.texture_units[0].texture_2d = 0; 315 state.texture_units[0].texture = 0;
316 state.Apply(); 316 state.Apply();
317} 317}
318 318
@@ -354,14 +354,14 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
354 ScreenRectVertex(x + w, y + h, texcoords.bottom * scale_u, right * scale_v), 354 ScreenRectVertex(x + w, y + h, texcoords.bottom * scale_u, right * scale_v),
355 }}; 355 }};
356 356
357 state.texture_units[0].texture_2d = screen_info.display_texture; 357 state.texture_units[0].texture = screen_info.display_texture;
358 state.texture_units[0].swizzle = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA}; 358 state.texture_units[0].swizzle = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
359 state.Apply(); 359 state.Apply();
360 360
361 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices.data()); 361 glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices.data());
362 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 362 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
363 363
364 state.texture_units[0].texture_2d = 0; 364 state.texture_units[0].texture = 0;
365 state.Apply(); 365 state.Apply();
366} 366}
367 367