示例#1
0
void
WebGL2Context::EndQuery(GLenum target)
{
    if (IsContextLost())
        return;

    if (!ValidateQueryTarget(target, "endQuery"))
        return;

    WebGLRefPtr<WebGLQuery>& querySlot = GetQuerySlotByTarget(target);
    WebGLQuery* activeQuery = querySlot.get();

    if (!activeQuery || target != activeQuery->mType)
    {
        /* From GLES's EXT_occlusion_query_boolean:
         *     marks the end of the sequence of commands to be tracked for the
         *     query type given by <target>. The active query object for
         *     <target> is updated to indicate that query results are not
         *     available, and the active query object name for <target> is reset
         *     to zero. When the commands issued prior to EndQueryEXT have
         *     completed and a final query result is available, the query object
         *     active when EndQueryEXT is called is updated by the GL. The query
         *     object is updated to indicate that the query results are
         *     available and to contain the query result. If the active query
         *     object name for <target> is zero when EndQueryEXT is called, the
         *     error INVALID_OPERATION is generated.
         */
        ErrorInvalidOperation("endQuery: There is no active query of type %s.",
                              GetQueryTargetEnumString(target));
        return;
    }

    MakeContextCurrent();

    if (target == LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN) {
        gl->fEndQuery(LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
    } else {
        gl->fEndQuery(SimulateOcclusionQueryTarget(gl, target));
    }

    UpdateBoundQuery(target, nullptr);
}
already_AddRefed<WebGLQuery>
WebGL2Context::GetQuery(GLenum target, GLenum pname)
{
    if (IsContextLost())
        return nullptr;

    if (!ValidateQueryTarget(target, "getQuery"))
        return nullptr;

    if (pname != LOCAL_GL_CURRENT_QUERY) {
        /* OpenGL ES 3.0 spec 6.1.7:
         *     pname must be CURRENT_QUERY.
         */
        ErrorInvalidEnum("getQuery: `pname` must be CURRENT_QUERY.");
        return nullptr;
    }

    WebGLRefPtr<WebGLQuery>& targetSlot = GetQuerySlotByTarget(target);

    nsRefPtr<WebGLQuery> tmp = targetSlot.get();
    return tmp.forget();
}
示例#3
0
void
WebGL2Context::UpdateBoundQuery(GLenum target, WebGLQuery* query)
{
    WebGLRefPtr<WebGLQuery>& querySlot = GetQuerySlotByTarget(target);
    querySlot = query;
}
示例#4
0
void
WebGL2Context::BeginQuery(GLenum target, WebGLQuery* query)
{
    if (IsContextLost())
        return;

    if (!ValidateQueryTarget(target, "beginQuery"))
        return;

    if (!query) {
        /* From GLES's EXT_occlusion_query_boolean:
         *     BeginQueryEXT sets the active query object name for the query
         *     type given by <target> to <id>. If BeginQueryEXT is called with
         *     an <id> of zero, if the active query object name for <target> is
         *     non-zero (for the targets ANY_SAMPLES_PASSED_EXT and
         *     ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if the active query for
         *     either target is non-zero), if <id> is the name of an existing
         *     query object whose type does not match <target>, or if <id> is
         *     the active query object name for any query type, the error
         *     INVALID_OPERATION is generated.
         */
        ErrorInvalidOperation("beginQuery: Query should not be null.");
        return;
    }

    if (query->IsDeleted()) {
        /* From GLES's EXT_occlusion_query_boolean:
         *     BeginQueryEXT fails and an INVALID_OPERATION error is generated
         *     if <id> is not a name returned from a previous call to
         *     GenQueriesEXT, or if such a name has since been deleted with
         *     DeleteQueriesEXT.
         */
        ErrorInvalidOperation("beginQuery: Query has been deleted.");
        return;
    }

    if (query->HasEverBeenActive() &&
        query->mType != target)
    {
        ErrorInvalidOperation("beginQuery: Target doesn't match with the query"
                              " type.");
        return;
    }

    WebGLRefPtr<WebGLQuery>& querySlot = GetQuerySlotByTarget(target);
    WebGLQuery* activeQuery = querySlot.get();
    if (activeQuery)
        return ErrorInvalidOperation("beginQuery: An other query already active.");

    if (!query->HasEverBeenActive())
        query->mType = target;

    MakeContextCurrent();

    if (target == LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN) {
        gl->fBeginQuery(LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
                        query->mGLName);
    } else {
        gl->fBeginQuery(SimulateOcclusionQueryTarget(gl, target),
                        query->mGLName);
    }

    UpdateBoundQuery(target, query);
}