1 // 2 // Copyright 2016 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // ContextGL: 7 // OpenGL-specific functionality associated with a GL Context. 8 // 9 10 #ifndef LIBANGLE_RENDERER_GL_CONTEXTGL_H_ 11 #define LIBANGLE_RENDERER_GL_CONTEXTGL_H_ 12 13 #include "libANGLE/renderer/ContextImpl.h" 14 #include "libANGLE/renderer/gl/RendererGL.h" 15 16 namespace angle 17 { 18 struct FeaturesGL; 19 } // namespace angle 20 21 namespace sh 22 { 23 struct BlockMemberInfo; 24 } // namespace sh 25 26 namespace rx 27 { 28 class BlitGL; 29 class ClearMultiviewGL; 30 class FunctionsGL; 31 class RendererGL; 32 class StateManagerGL; 33 34 enum class RobustnessVideoMemoryPurgeStatus 35 { 36 NOT_REQUESTED = 0, 37 REQUESTED = 1, 38 }; 39 40 class ContextGL : public ContextImpl 41 { 42 public: 43 ContextGL(const gl::State &state, 44 gl::ErrorSet *errorSet, 45 const std::shared_ptr<RendererGL> &renderer, 46 RobustnessVideoMemoryPurgeStatus robustnessVideoMemoryPurgeStatus); 47 ~ContextGL() override; 48 49 angle::Result initialize() override; 50 51 // Shader creation 52 CompilerImpl *createCompiler() override; 53 ShaderImpl *createShader(const gl::ShaderState &data) override; 54 ProgramImpl *createProgram(const gl::ProgramState &data) override; 55 56 // Framebuffer creation 57 FramebufferImpl *createFramebuffer(const gl::FramebufferState &data) override; 58 59 // Texture creation 60 TextureImpl *createTexture(const gl::TextureState &state) override; 61 62 // Renderbuffer creation 63 RenderbufferImpl *createRenderbuffer(const gl::RenderbufferState &state) override; 64 65 // Buffer creation 66 BufferImpl *createBuffer(const gl::BufferState &state) override; 67 68 // Vertex Array creation 69 VertexArrayImpl *createVertexArray(const gl::VertexArrayState &data) override; 70 71 // Query and Fence creation 72 QueryImpl *createQuery(gl::QueryType type) override; 73 FenceNVImpl *createFenceNV() override; 74 SyncImpl *createSync() override; 75 76 // Transform Feedback creation 77 TransformFeedbackImpl *createTransformFeedback( 78 const gl::TransformFeedbackState &state) override; 79 80 // Sampler object creation 81 SamplerImpl *createSampler(const gl::SamplerState &state) override; 82 83 // Program Pipeline object creation 84 ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override; 85 86 // Memory object creation. 87 MemoryObjectImpl *createMemoryObject() override; 88 89 // Semaphore creation. 90 SemaphoreImpl *createSemaphore() override; 91 92 // Overlay creation. 93 OverlayImpl *createOverlay(const gl::OverlayState &state) override; 94 95 // Flush and finish. 96 angle::Result flush(const gl::Context *context) override; 97 angle::Result finish(const gl::Context *context) override; 98 99 // Drawing methods. 100 angle::Result drawArrays(const gl::Context *context, 101 gl::PrimitiveMode mode, 102 GLint first, 103 GLsizei count) override; 104 angle::Result drawArraysInstanced(const gl::Context *context, 105 gl::PrimitiveMode mode, 106 GLint first, 107 GLsizei count, 108 GLsizei instanceCount) override; 109 angle::Result drawArraysInstancedBaseInstance(const gl::Context *context, 110 gl::PrimitiveMode mode, 111 GLint first, 112 GLsizei count, 113 GLsizei instanceCount, 114 GLuint baseInstance) override; 115 116 angle::Result drawElements(const gl::Context *context, 117 gl::PrimitiveMode mode, 118 GLsizei count, 119 gl::DrawElementsType type, 120 const void *indices) override; 121 angle::Result drawElementsBaseVertex(const gl::Context *context, 122 gl::PrimitiveMode mode, 123 GLsizei count, 124 gl::DrawElementsType type, 125 const void *indices, 126 GLint baseVertex) override; 127 angle::Result drawElementsInstanced(const gl::Context *context, 128 gl::PrimitiveMode mode, 129 GLsizei count, 130 gl::DrawElementsType type, 131 const void *indices, 132 GLsizei instances) override; 133 angle::Result drawElementsInstancedBaseVertex(const gl::Context *context, 134 gl::PrimitiveMode mode, 135 GLsizei count, 136 gl::DrawElementsType type, 137 const void *indices, 138 GLsizei instanceCount, 139 GLint baseVertex) override; 140 angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 141 gl::PrimitiveMode mode, 142 GLsizei count, 143 gl::DrawElementsType type, 144 const void *indices, 145 GLsizei instances, 146 GLint baseVertex, 147 GLuint baseInstance) override; 148 angle::Result drawRangeElements(const gl::Context *context, 149 gl::PrimitiveMode mode, 150 GLuint start, 151 GLuint end, 152 GLsizei count, 153 gl::DrawElementsType type, 154 const void *indices) override; 155 angle::Result drawRangeElementsBaseVertex(const gl::Context *context, 156 gl::PrimitiveMode mode, 157 GLuint start, 158 GLuint end, 159 GLsizei count, 160 gl::DrawElementsType type, 161 const void *indices, 162 GLint baseVertex) override; 163 angle::Result drawArraysIndirect(const gl::Context *context, 164 gl::PrimitiveMode mode, 165 const void *indirect) override; 166 angle::Result drawElementsIndirect(const gl::Context *context, 167 gl::PrimitiveMode mode, 168 gl::DrawElementsType type, 169 const void *indirect) override; 170 171 angle::Result multiDrawArrays(const gl::Context *context, 172 gl::PrimitiveMode mode, 173 const GLint *firsts, 174 const GLsizei *counts, 175 GLsizei drawcount) override; 176 angle::Result multiDrawArraysInstanced(const gl::Context *context, 177 gl::PrimitiveMode mode, 178 const GLint *firsts, 179 const GLsizei *counts, 180 const GLsizei *instanceCounts, 181 GLsizei drawcount) override; 182 angle::Result multiDrawElements(const gl::Context *context, 183 gl::PrimitiveMode mode, 184 const GLsizei *counts, 185 gl::DrawElementsType type, 186 const GLvoid *const *indices, 187 GLsizei drawcount) override; 188 angle::Result multiDrawElementsInstanced(const gl::Context *context, 189 gl::PrimitiveMode mode, 190 const GLsizei *counts, 191 gl::DrawElementsType type, 192 const GLvoid *const *indices, 193 const GLsizei *instanceCounts, 194 GLsizei drawcount) override; 195 angle::Result multiDrawArraysInstancedBaseInstance(const gl::Context *context, 196 gl::PrimitiveMode mode, 197 const GLint *firsts, 198 const GLsizei *counts, 199 const GLsizei *instanceCounts, 200 const GLuint *baseInstances, 201 GLsizei drawcount) override; 202 angle::Result multiDrawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 203 gl::PrimitiveMode mode, 204 const GLsizei *counts, 205 gl::DrawElementsType type, 206 const GLvoid *const *indices, 207 const GLsizei *instanceCounts, 208 const GLint *baseVertices, 209 const GLuint *baseInstances, 210 GLsizei drawcount) override; 211 212 // Device loss 213 gl::GraphicsResetStatus getResetStatus() override; 214 215 // EXT_debug_marker 216 angle::Result insertEventMarker(GLsizei length, const char *marker) override; 217 angle::Result pushGroupMarker(GLsizei length, const char *marker) override; 218 angle::Result popGroupMarker() override; 219 220 // KHR_debug 221 angle::Result pushDebugGroup(const gl::Context *context, 222 GLenum source, 223 GLuint id, 224 const std::string &message) override; 225 angle::Result popDebugGroup(const gl::Context *context) override; 226 227 // State sync with dirty bits. 228 angle::Result syncState(const gl::Context *context, 229 const gl::State::DirtyBits &dirtyBits, 230 const gl::State::DirtyBits &bitMask) override; 231 232 // Disjoint timer queries 233 GLint getGPUDisjoint() override; 234 GLint64 getTimestamp() override; 235 236 // Context switching 237 angle::Result onMakeCurrent(const gl::Context *context) override; 238 angle::Result onUnMakeCurrent(const gl::Context *context) override; 239 240 // Caps queries 241 gl::Caps getNativeCaps() const override; 242 const gl::TextureCapsMap &getNativeTextureCaps() const override; 243 const gl::Extensions &getNativeExtensions() const override; 244 const gl::Limitations &getNativeLimitations() const override; 245 246 // Handle helpers getFunctions()247 ANGLE_INLINE const FunctionsGL *getFunctions() const { return mRenderer->getFunctions(); } 248 249 StateManagerGL *getStateManager(); 250 const angle::FeaturesGL &getFeaturesGL() const; 251 BlitGL *getBlitter() const; 252 ClearMultiviewGL *getMultiviewClearer() const; 253 254 angle::Result dispatchCompute(const gl::Context *context, 255 GLuint numGroupsX, 256 GLuint numGroupsY, 257 GLuint numGroupsZ) override; 258 angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) override; 259 260 angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override; 261 angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override; 262 263 void setMaxShaderCompilerThreads(GLuint count) override; 264 265 void invalidateTexture(gl::TextureType target) override; 266 267 void validateState() const; 268 269 void setNeedsFlushBeforeDeleteTextures(); 270 void flushIfNecessaryBeforeDeleteTextures(); 271 272 void markWorkSubmitted(); 273 getDebug()274 const gl::Debug &getDebug() const { return mState.getDebug(); } 275 276 private: 277 angle::Result setDrawArraysState(const gl::Context *context, 278 GLint first, 279 GLsizei count, 280 GLsizei instanceCount); 281 282 angle::Result setDrawElementsState(const gl::Context *context, 283 GLsizei count, 284 gl::DrawElementsType type, 285 const void *indices, 286 GLsizei instanceCount, 287 const void **outIndices); 288 289 gl::AttributesMask updateAttributesForBaseInstance(const gl::Program *program, 290 GLuint baseInstance); 291 void resetUpdatedAttributes(gl::AttributesMask attribMask); 292 293 protected: 294 std::shared_ptr<RendererGL> mRenderer; 295 296 RobustnessVideoMemoryPurgeStatus mRobustnessVideoMemoryPurgeStatus; 297 }; 298 299 } // namespace rx 300 301 #endif // LIBANGLE_RENDERER_GL_CONTEXTGL_H_ 302