summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/OGL/OGLPipeline.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2017-09-08 19:42:56 +1000
committerStenzek <stenzek@gmail.com>2018-02-22 22:02:34 +1000
commitfec6bb4d5676de8834c90d93127c1459f46f8dcb (patch)
treef484dbc96cc5bdc49282a63b973c98e93ec2bfad /Source/Core/VideoBackends/OGL/OGLPipeline.cpp
parent31111ef1432bc5d6d653fbef175e8ca3ac2c152d (diff)
VideoBackends: Add AbstractShader and AbstractPipeline classes
Diffstat (limited to 'Source/Core/VideoBackends/OGL/OGLPipeline.cpp')
-rw-r--r--Source/Core/VideoBackends/OGL/OGLPipeline.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/Source/Core/VideoBackends/OGL/OGLPipeline.cpp b/Source/Core/VideoBackends/OGL/OGLPipeline.cpp
new file mode 100644
index 0000000000..9d93381d46
--- /dev/null
+++ b/Source/Core/VideoBackends/OGL/OGLPipeline.cpp
@@ -0,0 +1,62 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "Common/Assert.h"
+
+#include "VideoBackends/OGL/OGLPipeline.h"
+#include "VideoBackends/OGL/OGLShader.h"
+#include "VideoBackends/OGL/ProgramShaderCache.h"
+#include "VideoBackends/OGL/Render.h"
+#include "VideoBackends/OGL/VertexManager.h"
+
+namespace OGL
+{
+static GLenum MapToGLPrimitive(PrimitiveType primitive_type)
+{
+ switch (primitive_type)
+ {
+ case PrimitiveType::Points:
+ return GL_POINTS;
+ case PrimitiveType::Lines:
+ return GL_LINES;
+ case PrimitiveType::Triangles:
+ return GL_TRIANGLES;
+ case PrimitiveType::TriangleStrip:
+ return GL_TRIANGLE_STRIP;
+ default:
+ return 0;
+ }
+}
+OGLPipeline::OGLPipeline(const GLVertexFormat* vertex_format,
+ const RasterizationState& rasterization_state,
+ const DepthState& depth_state, const BlendingState& blending_state,
+ const PipelineProgram* program, GLuint gl_primitive)
+ : m_vertex_format(vertex_format), m_rasterization_state(rasterization_state),
+ m_depth_state(depth_state), m_blending_state(blending_state), m_program(program),
+ m_gl_primitive(gl_primitive)
+{
+}
+
+OGLPipeline::~OGLPipeline()
+{
+ // We don't want to destroy the shaders.
+ ProgramShaderCache::ReleasePipelineProgram(m_program);
+}
+
+std::unique_ptr<OGLPipeline> OGLPipeline::Create(const AbstractPipelineConfig& config)
+{
+ const PipelineProgram* program =
+ ProgramShaderCache::GetPipelineProgram(static_cast<const OGLShader*>(config.vertex_shader),
+ static_cast<const OGLShader*>(config.geometry_shader),
+ static_cast<const OGLShader*>(config.pixel_shader));
+ if (!program)
+ return nullptr;
+
+ const GLVertexFormat* vertex_format = static_cast<const GLVertexFormat*>(config.vertex_format);
+ GLenum gl_primitive = MapToGLPrimitive(config.rasterization_state.primitive);
+ return std::make_unique<OGLPipeline>(vertex_format, config.rasterization_state,
+ config.depth_state, config.blending_state, program,
+ gl_primitive);
+}
+} // namespace OGL