gl::Error StateManagerGL::setDrawElementsState(const gl::Data &data, GLsizei count, GLenum type, const GLvoid *indices, GLsizei instanceCount, const GLvoid **outIndices) { const gl::State &state = *data.state; const gl::Program *program = state.getProgram(); const gl::VertexArray *vao = state.getVertexArray(); const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao); gl::Error error = vaoGL->syncDrawElementsState(program->getActiveAttribLocationsMask(), count, type, indices, instanceCount, state.isPrimitiveRestartEnabled(), outIndices); if (error.isError()) { return error; } bindVertexArray(vaoGL->getVertexArrayID(), vaoGL->getAppliedElementArrayBufferID()); return setGenericDrawState(data); }
void RenderingSystemOgl::renderGenerated( unsigned int vertexCount, Mesh::PrimitiveTopology primitiveTopology ) { bindVertexArray( *_vertexArrayWithoutData ); ::glDrawArrays( MeshOgl::convertPrimitiveTopology(primitiveTopology), 0, vertexCount ); checkResult( "::glDrawArrays" ); }
virtual void draw(const GLMatrix4 &parentTransform, const GLMatrix4 &parentNormTransform) { const GLMatrix4 &t = parentTransform * transform, &nt = parentNormTransform * normTransform; bindVertexArray(vtx); setTransform(t, nt); glDrawArrays(GL_TRIANGLES, 0, sizeof(vtx)/sizeof(Vtx)); drawChildren(t,nt); }
gl::Error StateManagerGL::setDrawArraysState(const gl::Data &data, GLint first, GLsizei count) { const gl::State &state = *data.state; const gl::VertexArray *vao = state.getVertexArray(); const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao); vaoGL->syncDrawArraysState(first, count); bindVertexArray(vaoGL->getVertexArrayID()); return setGenericDrawState(data); }
void StateManagerGL::deleteVertexArray(GLuint vao) { if (vao != 0) { if (mVAO == vao) { bindVertexArray(0, 0); } mFunctions->deleteVertexArrays(1, &vao); } }
virtual void draw(const GLMatrix4 &parentTransform, const GLMatrix4 &parentNormTransform) { const GLMatrix4 &t = parentTransform * transform, &nt = parentNormTransform * normTransform; bindVertexArray(&vertices[0]); setTransform(t, nt); glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.size()/2); glDrawArrays(GL_TRIANGLE_FAN, vertices.size()/2, vertices.size()/2); drawChildren(t, nt); }
void Context::detachVertexArray(GLuint vertexArray) { // Vertex array detachment is handled by Context, because 0 is a valid // VAO, and a pointer to it must be passed from Context to State at // binding time. // [OpenGL ES 3.0.2] section 2.10 page 43: // If a vertex array object that is currently bound is deleted, the binding // for that object reverts to zero and the default vertex array becomes current. if (mState.removeVertexArrayBinding(vertexArray)) { bindVertexArray(0); } }
virtual void draw(const GLMatrix4 &parentTransform, const GLMatrix4 &parentNormTransform) { const GLMatrix4 &t = parentTransform * transform, &nt = parentNormTransform * normTransform; bindVertexArray(vCylinder); setTransform(t, nt); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); drawChildren(t,nt); //bindVertexArray(vTopCircle); }
gl::Error StateManagerGL::setDrawElementsState(const gl::Data &data, GLsizei count, GLenum type, const GLvoid *indices, const GLvoid **outIndices) { const gl::State &state = *data.state; const gl::VertexArray *vao = state.getVertexArray(); const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao); gl::Error error = vaoGL->syncDrawElementsState(count, type, indices, outIndices); if (error.isError()) { return error; } bindVertexArray(vaoGL->getVertexArrayID()); return setGenericDrawState(data); }
virtual void draw(const GLMatrix4 &parentTransform, const GLMatrix4 &parentNormalTransform) { if(tornado) { for(int i = 0; i < 4; i++) vertices[i].color = 0xFF0033CC; } else { for(int i = 0; i < 4; i++) vertices[i].color = 0xFFCC3300; } const GLMatrix4 &t = parentTransform * transform, &nt = parentNormalTransform * normTransform; bindVertexArray(vertices); setTransform(t, nt); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); drawChildren(t, nt); }
void RenderingSystemOgl::renderMesh( Mesh::Pointer mesh, unsigned count ) { storm_assert( mesh ); auto nativeMesh = std::static_pointer_cast< MeshOgl >( mesh ); bindVertexArray( nativeMesh->getHandle() ); const auto &indexBufferDescription = mesh->getDescription().indexBuffer->getDescription(); storm_assert( indexBufferDescription.elementSize == 2 || indexBufferDescription.elementSize == 4 ); const GLuint primitiveRestartIndex = (indexBufferDescription.elementSize == 2) ? 0xffff : 0xffffffff; if( _primitiveRestartIndex != primitiveRestartIndex ) { _primitiveRestartIndex = primitiveRestartIndex; ::glPrimitiveRestartIndex( _primitiveRestartIndex ); } const GLenum primitiveTopology = nativeMesh->getPrimitiveTopology(); const GLsizei indexCount = static_cast<GLsizei>( indexBufferDescription.size / indexBufferDescription.elementSize ); const GLenum indexFormat = (indexBufferDescription.elementSize == 2) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; const GLvoid *indexOffset = nullptr; if( count == 1 ) { ::glDrawElements( primitiveTopology, indexCount, indexFormat, indexOffset ); checkResult( "::glDrawElements" ); } else { ::glDrawElementsInstanced( primitiveTopology, indexCount, indexFormat, indexOffset, count ); checkResult( "::glDrawElementsInstanced" ); } }
gl::Error StateManagerGL::setDrawArraysState(const gl::Data &data, GLint first, GLsizei count, GLsizei instanceCount) { const gl::State &state = *data.state; const gl::Program *program = state.getProgram(); const gl::VertexArray *vao = state.getVertexArray(); const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao); gl::Error error = vaoGL->syncDrawArraysState(program->getActiveAttribLocationsMask(), first, count, instanceCount); if (error.isError()) { return error; } bindVertexArray(vaoGL->getVertexArrayID(), vaoGL->getAppliedElementArrayBufferID()); return setGenericDrawState(data); }
Context::Context(const egl::Config *config, int clientVersion, const Context *shareContext, rx::Renderer *renderer, bool notifyResets, bool robustAccess) : mRenderer(renderer), mData(clientVersion, mState, mCaps, mTextureCaps, mExtensions, nullptr) { ASSERT(robustAccess == false); // Unimplemented initCaps(clientVersion); mState.initialize(mCaps, clientVersion); mClientVersion = clientVersion; mConfigID = config->configID; mClientType = EGL_OPENGL_ES_API; mFenceNVHandleAllocator.setBaseHandle(0); if (shareContext != NULL) { mResourceManager = shareContext->mResourceManager; mResourceManager->addRef(); } else { mResourceManager = new ResourceManager(mRenderer); } mData.resourceManager = mResourceManager; // [OpenGL ES 2.0.24] section 3.7 page 83: // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional // and cube map texture state vectors respectively associated with them. // In order that access to these initial textures not be lost, they are treated as texture // objects all of whose names are 0. Texture *zeroTexture2D = new Texture(mRenderer->createTexture(GL_TEXTURE_2D), 0, GL_TEXTURE_2D); mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D); Texture *zeroTextureCube = new Texture(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), 0, GL_TEXTURE_CUBE_MAP); mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube); if (mClientVersion >= 3) { // TODO: These could also be enabled via extension Texture *zeroTexture3D = new Texture(mRenderer->createTexture(GL_TEXTURE_3D), 0, GL_TEXTURE_3D); mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D); Texture *zeroTexture2DArray = new Texture(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), 0, GL_TEXTURE_2D_ARRAY); mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray); } mState.initializeZeroTextures(mZeroTextures); // Allocate default FBO mFramebufferMap[0] = new Framebuffer(mCaps, mRenderer, 0); bindVertexArray(0); bindArrayBuffer(0); bindElementArrayBuffer(0); bindReadFramebuffer(0); bindDrawFramebuffer(0); bindRenderbuffer(0); bindGenericUniformBuffer(0); for (unsigned int i = 0; i < mCaps.maxCombinedUniformBlocks; i++) { bindIndexedUniformBuffer(0, i, 0, -1); } bindCopyReadBuffer(0); bindCopyWriteBuffer(0); bindPixelPackBuffer(0); bindPixelUnpackBuffer(0); // [OpenGL ES 3.0.2] section 2.14.1 pg 85: // In the initial state, a default transform feedback object is bound and treated as // a transform feedback object with a name of zero. That object is bound any time // BindTransformFeedback is called with id of zero mTransformFeedbackZero.set(new TransformFeedback(mRenderer->createTransformFeedback(), 0, mCaps)); bindTransformFeedback(0); mHasBeenCurrent = false; mContextLost = false; mResetStatus = GL_NO_ERROR; mResetStrategy = (notifyResets ? GL_LOSE_CONTEXT_ON_RESET_EXT : GL_NO_RESET_NOTIFICATION_EXT); mRobustAccess = robustAccess; mCompiler = new Compiler(mRenderer->createCompiler(getData())); }
GraphicsContext3D::GraphicsContext3D(GraphicsContext3DAttributes attributes, HostWindow*, GraphicsContext3D::RenderStyle renderStyle) : m_currentWidth(0) , m_currentHeight(0) , m_attrs(attributes) , m_texture(0) , m_compositorTexture(0) , m_fbo(0) #if USE(COORDINATED_GRAPHICS_THREADED) , m_intermediateTexture(0) #endif , m_depthStencilBuffer(0) , m_layerComposited(false) , m_multisampleFBO(0) , m_multisampleDepthStencilBuffer(0) , m_multisampleColorBuffer(0) , m_private(std::make_unique<GraphicsContext3DPrivate>(this, renderStyle)) { makeContextCurrent(); validateAttributes(); if (renderStyle == RenderOffscreen) { // Create a texture to render into. ::glGenTextures(1, &m_texture); ::glBindTexture(GL_TEXTURE_2D, m_texture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glBindTexture(GL_TEXTURE_2D, 0); // Create an FBO. ::glGenFramebuffers(1, &m_fbo); ::glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); #if USE(COORDINATED_GRAPHICS_THREADED) ::glGenTextures(1, &m_compositorTexture); ::glBindTexture(GL_TEXTURE_2D, m_compositorTexture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glGenTextures(1, &m_intermediateTexture); ::glBindTexture(GL_TEXTURE_2D, m_intermediateTexture); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); ::glBindTexture(GL_TEXTURE_2D, 0); #endif m_state.boundFBO = m_fbo; if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) ::glGenRenderbuffers(1, &m_depthStencilBuffer); // Create a multisample FBO. if (m_attrs.antialias) { ::glGenFramebuffers(1, &m_multisampleFBO); ::glBindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO); m_state.boundFBO = m_multisampleFBO; ::glGenRenderbuffers(1, &m_multisampleColorBuffer); if (m_attrs.stencil || m_attrs.depth) ::glGenRenderbuffers(1, &m_multisampleDepthStencilBuffer); } } #if !USE(OPENGL_ES_2) ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); if (GLContext::current()->version() >= 320) { // From version 3.2 on we use the OpenGL Core profile, so request that ouput to the shader compiler. // OpenGL version 3.2 uses GLSL version 1.50. m_compiler = ANGLEWebKitBridge(SH_GLSL_150_CORE_OUTPUT); // From version 3.2 on we use the OpenGL Core profile, and we need a VAO for rendering. // A VAO could be created and bound by each component using GL rendering (TextureMapper, WebGL, etc). This is // a simpler solution: the first GraphicsContext3D created on a GLContext will create and bind a VAO for that context. GC3Dint currentVAO = 0; getIntegerv(GraphicsContext3D::VERTEX_ARRAY_BINDING, ¤tVAO); if (!currentVAO) { m_vao = createVertexArray(); bindVertexArray(m_vao); } } else { // For lower versions request the compatibility output to the shader compiler. m_compiler = ANGLEWebKitBridge(SH_GLSL_COMPATIBILITY_OUTPUT); // GL_POINT_SPRITE is needed in lower versions. ::glEnable(GL_POINT_SPRITE); } #else m_compiler = ANGLEWebKitBridge(SH_ESSL_OUTPUT); #endif // ANGLE initialization. ShBuiltInResources ANGLEResources; ShInitBuiltInResources(&ANGLEResources); getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs); getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors); getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors); getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits); getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors); // Always set to 1 for OpenGL ES. ANGLEResources.MaxDrawBuffers = 1; GC3Dint range[2], precision; getShaderPrecisionFormat(GraphicsContext3D::FRAGMENT_SHADER, GraphicsContext3D::HIGH_FLOAT, range, &precision); ANGLEResources.FragmentPrecisionHigh = (range[0] || range[1] || precision); m_compiler.setResources(ANGLEResources); ::glClearColor(0, 0, 0, 0); }