4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * Stanislav Vorobiov <s.vorobiov@samsung.com>
8 * Jinhyung Jo <jinhyung.jo@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 #include "GLES3/gl3.h"
35 #include "yagl_gles3_query.h"
36 #include "yagl_malloc.h"
37 #include "yagl_state.h"
38 #include "yagl_host_gles_calls.h"
40 static void yagl_gles3_query_update_result(struct yagl_gles3_query *query, GLenum pname)
42 if (!query->result_available) {
43 query->result_available =
44 yagl_host_glGetQueryObjectuiv(query->global_name, pname, &query->result);
48 static void yagl_gles3_query_destroy(struct yagl_ref *ref)
50 struct yagl_gles3_query *query = (struct yagl_gles3_query*)ref;
52 yagl_host_glDeleteObjects(&query->global_name, 1);
54 yagl_object_cleanup(&query->base);
59 struct yagl_gles3_query *yagl_gles3_query_create(void)
61 struct yagl_gles3_query *query;
63 query = yagl_malloc0(sizeof(*query));
65 yagl_object_init(&query->base, &yagl_gles3_query_destroy);
67 query->global_name = yagl_get_global_name();
69 yagl_host_glGenQueries(&query->global_name, 1);
74 void yagl_gles3_query_acquire(struct yagl_gles3_query *query)
77 yagl_object_acquire(&query->base);
81 void yagl_gles3_query_release(struct yagl_gles3_query *query)
84 yagl_object_release(&query->base);
88 void yagl_gles3_query_begin(struct yagl_gles3_query *query,
91 yagl_host_glBeginQuery(target, query->global_name);
94 query->result_available = 0;
96 query->was_active = 1;
99 void yagl_gles3_query_end(struct yagl_gles3_query *query,
102 yagl_host_glEndQuery(target);
107 int yagl_gles3_query_is_result_available(struct yagl_gles3_query *query)
109 yagl_gles3_query_update_result(query, GL_QUERY_RESULT_AVAILABLE);
111 return query->result_available;
114 GLuint yagl_gles3_query_get_result(struct yagl_gles3_query *query)
116 yagl_gles3_query_update_result(query, GL_QUERY_RESULT);
118 return query->result;
121 int yagl_gles3_query_was_active(struct yagl_gles3_query *query)
123 return query->was_active;