diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index fae9abd19..41e4ece1e 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -142,37 +142,55 @@ RasterizerOpenGL::~RasterizerOpenGL() { | |||
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | static constexpr std::array<GLenum, 4> vs_attrib_types{ | ||
| 146 | GL_BYTE, // VertexAttributeFormat::BYTE | ||
| 147 | GL_UNSIGNED_BYTE, // VertexAttributeFormat::UBYTE | ||
| 148 | GL_SHORT, // VertexAttributeFormat::SHORT | ||
| 149 | GL_FLOAT // VertexAttributeFormat::FLOAT | ||
| 150 | }; | ||
| 151 | |||
| 152 | void RasterizerOpenGL::AnalyzeVertexArray(bool is_indexed) { | 145 | void RasterizerOpenGL::AnalyzeVertexArray(bool is_indexed) { |
| 153 | const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; | 146 | const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; |
| 154 | const auto& vertex_attributes = regs.vertex_attrib_format; | ||
| 155 | 147 | ||
| 156 | if (is_indexed) { | 148 | if (is_indexed) { |
| 157 | UNREACHABLE(); | 149 | UNREACHABLE(); |
| 158 | } | 150 | } |
| 159 | const u32 vertex_num = regs.vertex_buffer.count; | ||
| 160 | 151 | ||
| 161 | vs_input_size = 0; | 152 | // TODO(bunnei): Add support for 1+ vertex arrays |
| 162 | u32 max_offset{}; | 153 | vs_input_size = regs.vertex_buffer.count * regs.vertex_array[0].stride; |
| 163 | for (const auto& attrib : vertex_attributes) { | ||
| 164 | if (max_offset >= attrib.offset) { | ||
| 165 | continue; | ||
| 166 | } | ||
| 167 | max_offset = attrib.offset; | ||
| 168 | vs_input_size = max_offset + attrib.SizeInBytes(); | ||
| 169 | } | ||
| 170 | vs_input_size *= vertex_num; | ||
| 171 | } | 154 | } |
| 172 | 155 | ||
| 173 | void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset) { | 156 | void RasterizerOpenGL::SetupVertexArray(u8* array_ptr, GLintptr buffer_offset) { |
| 174 | MICROPROFILE_SCOPE(OpenGL_VAO); | 157 | MICROPROFILE_SCOPE(OpenGL_VAO); |
| 175 | UNIMPLEMENTED(); | 158 | const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs; |
| 159 | const auto& memory_manager = Core::System().GetInstance().GPU().memory_manager; | ||
| 160 | |||
| 161 | state.draw.vertex_array = hw_vao.handle; | ||
| 162 | state.draw.vertex_buffer = stream_buffer->GetHandle(); | ||
| 163 | state.Apply(); | ||
| 164 | |||
| 165 | // TODO(bunnei): Add support for 1+ vertex arrays | ||
| 166 | const auto& vertex_array{regs.vertex_array[0]}; | ||
| 167 | ASSERT_MSG(vertex_array.enable, "vertex array 0 is disabled?"); | ||
| 168 | ASSERT_MSG(!vertex_array.divisor, "vertex array 0 divisor is unimplemented!"); | ||
| 169 | for (unsigned index = 1; index < Maxwell::NumVertexArrays; ++index) { | ||
| 170 | ASSERT_MSG(!regs.vertex_array[index].enable, "vertex array %d is unimplemented!", index); | ||
| 171 | } | ||
| 172 | |||
| 173 | // Use the vertex array as-is, assumes that the data is formatted correctly for OpenGL. | ||
| 174 | // Enables the first 16 vertex attributes always, as we don't know which ones are actually used | ||
| 175 | // until shader time. Note, Tegra technically supports 32, but we're cappinig this to 16 for now | ||
| 176 | // to avoid OpenGL errors. | ||
| 177 | for (unsigned index = 0; index < 16; ++index) { | ||
| 178 | auto& attrib = regs.vertex_attrib_format[index]; | ||
| 179 | glVertexAttribPointer(index, attrib.ComponentCount(), MaxwellToGL::VertexType(attrib), | ||
| 180 | GL_FALSE, vertex_array.stride, | ||
| 181 | reinterpret_cast<GLvoid*>(buffer_offset + attrib.offset)); | ||
| 182 | glEnableVertexAttribArray(index); | ||
| 183 | hw_vao_enabled_attributes[index] = true; | ||
| 184 | } | ||
| 185 | |||
| 186 | // Copy vertex array data | ||
| 187 | const u32 data_size{vertex_array.stride * regs.vertex_buffer.count}; | ||
| 188 | const VAddr data_addr{memory_manager->PhysicalToVirtualAddress(vertex_array.StartAddress())}; | ||
| 189 | res_cache.FlushRegion(data_addr, data_size, nullptr); | ||
| 190 | std::memcpy(array_ptr, Memory::GetPointer(data_addr), data_size); | ||
| 191 | |||
| 192 | array_ptr += data_size; | ||
| 193 | buffer_offset += data_size; | ||
| 176 | } | 194 | } |
| 177 | 195 | ||
| 178 | void RasterizerOpenGL::SetupVertexShader(VSUniformData* ub_ptr, GLintptr buffer_offset) { | 196 | void RasterizerOpenGL::SetupVertexShader(VSUniformData* ub_ptr, GLintptr buffer_offset) { |