void BufferRAM2GLConverter::update(const DataRepresentation* source,
                                   DataRepresentation* destination) {
    const BufferRAM* src = static_cast<const BufferRAM*>(source);
    BufferGL* dst = static_cast<BufferGL*>(destination);

    dst->setSize(src->getSize());
    dst->upload(src->getData(), src->getSize() * src->getSizeOfElement());
}
DataRepresentation* BufferRAM2GLConverter::createFrom(const DataRepresentation* source) {
    const BufferRAM* bufferRAM = static_cast<const BufferRAM*>(source);
    BufferGL* buffer =  new BufferGL(bufferRAM->getSize(), bufferRAM->getDataFormat(),
                        bufferRAM->getBufferType(), bufferRAM->getBufferUsage());
    
    buffer->upload(bufferRAM->getData(), bufferRAM->getSize()*bufferRAM->getSizeOfElement());
    
    return buffer;
}
Exemple #3
0
gl::Error BufferGL::copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size)
{
    BufferGL *sourceGL = GetAs<BufferGL>(source);

    mStateManager->bindBuffer(DestBufferOperationTarget, mBufferID);
    mStateManager->bindBuffer(SourceBufferOperationTarget, sourceGL->getBufferID());

    mFunctions->copyBufferSubData(SourceBufferOperationTarget, DestBufferOperationTarget, sourceOffset, destOffset, size);

    return gl::Error(GL_NO_ERROR);
}
Exemple #4
0
gl::Error BufferGL::copySubData(BufferImpl* source, GLintptr sourceOffset, GLintptr destOffset, GLsizeiptr size)
{
    BufferGL *sourceGL = GetAs<BufferGL>(source);

    mStateManager->bindBuffer(DestBufferOperationTarget, mBufferID);
    mStateManager->bindBuffer(SourceBufferOperationTarget, sourceGL->getBufferID());

    mFunctions->copyBufferSubData(SourceBufferOperationTarget, DestBufferOperationTarget, sourceOffset, destOffset, size);

    if (mShadowBufferData && size > 0)
    {
        ASSERT(sourceGL->mShadowBufferData);
        memcpy(mShadowCopy.data() + destOffset, sourceGL->mShadowCopy.data() + sourceOffset, size);
    }

    return gl::Error(GL_NO_ERROR);
}
      void VertexAttributeCache<VertexCacheVBO>::updateGeometryInstanceCacheEntry( GeometryInstanceGLHandle gi, GeometryInstanceCacheEntry& geometryInstanceCacheEntry, AttributeCacheEntry* attributeCacheEntry )
      {
        VertexAttributesGLSharedHandle const& vertexAttributes = gi->getGeometry()->getVertexAttributes();

        VertexDataGLHandle vertexData = vertexAttributes->getVertexDataGLHandle();
        geometryInstanceCacheEntry.m_formatId = registerVertexFormat( vertexAttributes.get(), gi->m_programPipeline->m_activeAttributeMask );
        const VertexFormat &vertexFormat = m_vertexFormats[geometryInstanceCacheEntry.m_formatId];

        for ( unsigned int index = 0; index < vertexFormat.m_numStreams; ++index )
        {
          unsigned int streamId = vertexFormat.m_streamIds[index];
          AttributeCacheEntry& cacheEntry = attributeCacheEntry[index];
          BufferGL *buffer = vertexData->m_data[streamId].m_buffer;

          if ( buffer )
          {
            DP_ASSERT( buffer->getBuffer() );
            cacheEntry.vbo  = buffer->getBuffer()->getGLId();
            cacheEntry.offset = reinterpret_cast<GLvoid *>(vertexData->m_data[streamId].m_offset);
          }
          else
          {
            cacheEntry.vbo = 0;
            cacheEntry.offset = 0;
          }
        }

        // update indices data
        IndicesGLSharedHandle const& indices = gi->getGeometry()->getIndices();
        if ( indices && indices->getBufferHandle() )
        {
          DP_ASSERT( indices->getBufferHandle()->getBuffer() );
          geometryInstanceCacheEntry.m_attributeCacheIndices.vbo = indices->getBufferHandle()->getBuffer()->getGLId();
          geometryInstanceCacheEntry.m_attributeCacheIndices.offset = 0;
        }
        else
        {
          geometryInstanceCacheEntry.m_attributeCacheIndices.vbo = 0;
          geometryInstanceCacheEntry.m_attributeCacheIndices.offset = 0;
        }
        geometryInstanceCacheEntry.m_drawCall.updateDrawCall( gi );
        geometryInstanceCacheEntry.m_attributeCacheEntry = attributeCacheEntry;
        geometryInstanceCacheEntry.m_vertexAttributesHandle = vertexAttributes.get();
        geometryInstanceCacheEntry.m_indicesHandle = indices.get();
      }
Exemple #6
0
void MeshGL::update(bool editable) {
    attributesGL_.clear();
    Mesh* owner = this->getOwner();
    attributesArray_->bind(); // Have to call bind before clear.
    attributesArray_->clear();
    if (editable) {
        for (Buffer* buf : owner->getBuffers()) {
            BufferGL* bufGL = buf->getEditableRepresentation<BufferGL>();
            attributesGL_.push_back(bufGL);
            attributesArray_->attachBufferObject(bufGL->getBufferObject().get());
        }
    } else {
        for (Buffer* buf : owner->getBuffers()) {
            const BufferGL* bufGL = buf->getRepresentation<BufferGL>();
            attributesGL_.push_back(bufGL);
            attributesArray_->attachBufferObject(bufGL->getBufferObject().get());
        }
    }
    attributesArray_->unbind();
}
gl::Error StateManagerGL::setGenericDrawState(const gl::Data &data)
{
    const gl::State &state = *data.state;

    // If the context has changed, pause the previous context's transform feedback and queries
    if (data.context != mPrevDrawContext)
    {
        if (mPrevDrawTransformFeedback != nullptr)
        {
            mPrevDrawTransformFeedback->syncPausedState(true);
        }

        for (QueryGL *prevQuery : mPrevDrawQueries)
        {
            prevQuery->pause();
        }
    }
    mPrevDrawTransformFeedback = nullptr;
    mPrevDrawQueries.clear();

    mPrevDrawContext = data.context;

    // Sync the current program state
    const gl::Program *program = state.getProgram();
    const ProgramGL *programGL = GetImplAs<ProgramGL>(program);
    useProgram(programGL->getProgramID());

    for (size_t uniformBlockIndex = 0; uniformBlockIndex < program->getActiveUniformBlockCount();
         uniformBlockIndex++)
    {
        GLuint binding = program->getUniformBlockBinding(static_cast<GLuint>(uniformBlockIndex));
        const OffsetBindingPointer<gl::Buffer> &uniformBuffer =
            data.state->getIndexedUniformBuffer(binding);

        if (uniformBuffer.get() != nullptr)
        {
            BufferGL *bufferGL = GetImplAs<BufferGL>(uniformBuffer.get());

            if (uniformBuffer.getSize() == 0)
            {
                bindBufferBase(GL_UNIFORM_BUFFER, binding, bufferGL->getBufferID());
            }
            else
            {
                bindBufferRange(GL_UNIFORM_BUFFER, binding, bufferGL->getBufferID(),
                                uniformBuffer.getOffset(), uniformBuffer.getSize());
            }
        }
    }

    const std::vector<SamplerBindingGL> &appliedSamplerUniforms = programGL->getAppliedSamplerUniforms();
    for (const SamplerBindingGL &samplerUniform : appliedSamplerUniforms)
    {
        GLenum textureType = samplerUniform.textureType;
        for (GLuint textureUnitIndex : samplerUniform.boundTextureUnits)
        {
            const gl::Texture *texture = state.getSamplerTexture(textureUnitIndex, textureType);
            if (texture != nullptr)
            {
                const TextureGL *textureGL = GetImplAs<TextureGL>(texture);

                if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
                {
                    activeTexture(textureUnitIndex);
                    bindTexture(textureType, textureGL->getTextureID());
                }

                textureGL->syncState(textureUnitIndex, texture->getTextureState());
            }
            else
            {
                if (mTextures[textureType][textureUnitIndex] != 0)
                {
                    activeTexture(textureUnitIndex);
                    bindTexture(textureType, 0);
                }
            }

            const gl::Sampler *sampler = state.getSampler(textureUnitIndex);
            if (sampler != nullptr)
            {
                const SamplerGL *samplerGL = GetImplAs<SamplerGL>(sampler);
                samplerGL->syncState(sampler->getSamplerState());
                bindSampler(textureUnitIndex, samplerGL->getSamplerID());
            }
            else
            {
                bindSampler(textureUnitIndex, 0);
            }
        }
    }

    const gl::Framebuffer *framebuffer = state.getDrawFramebuffer();
    const FramebufferGL *framebufferGL = GetImplAs<FramebufferGL>(framebuffer);
    bindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferGL->getFramebufferID());
    framebufferGL->syncDrawState();

    // Seamless cubemaps are required for ES3 and higher contexts.
    setTextureCubemapSeamlessEnabled(data.clientVersion >= 3);

    // Set the current transform feedback state
    gl::TransformFeedback *transformFeedback = state.getCurrentTransformFeedback();
    if (transformFeedback)
    {
        TransformFeedbackGL *transformFeedbackGL =
            GetImplAs<TransformFeedbackGL>(transformFeedback);
        bindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedbackGL->getTransformFeedbackID());
        transformFeedbackGL->syncActiveState(transformFeedback->isActive(),
                                             transformFeedback->getPrimitiveMode());
        transformFeedbackGL->syncPausedState(transformFeedback->isPaused());
        mPrevDrawTransformFeedback = transformFeedbackGL;
    }
    else
    {
        bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
        mPrevDrawTransformFeedback = nullptr;
    }

    // Set the current query state
    for (GLenum queryType : QueryTypes)
    {
        gl::Query *query = state.getActiveQuery(queryType);
        if (query != nullptr)
        {
            QueryGL *queryGL = GetImplAs<QueryGL>(query);
            queryGL->resume();

            mPrevDrawQueries.insert(queryGL);
        }
    }

    return gl::Error(GL_NO_ERROR);
}