"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-depth-state.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2011 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  * Authors:
23  *   Robert Bragg <robert@linux.intel.com>
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "cogl-util.h"
31 #include "cogl-depth-state-private.h"
32 #include "cogl-depth-state.h"
33
34 void
35 cogl_depth_state_init (CoglDepthState *state)
36 {
37   state->magic = COGL_DEPTH_STATE_MAGIC;
38
39   /* The same as the GL defaults */
40   state->test_enabled = FALSE;
41   state->write_enabled = TRUE;
42   state->test_function = COGL_DEPTH_TEST_FUNCTION_LESS;
43   state->range_near = 0;
44   state->range_far = 1;
45 }
46
47 void
48 cogl_depth_state_set_test_enabled (CoglDepthState *state,
49                                    gboolean enabled)
50 {
51   _COGL_RETURN_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC);
52   state->test_enabled = enabled;
53 }
54
55 gboolean
56 cogl_depth_state_get_test_enabled (CoglDepthState *state)
57 {
58   _COGL_RETURN_VAL_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC, FALSE);
59   return state->test_enabled;
60 }
61
62 void
63 cogl_depth_state_set_write_enabled (CoglDepthState *state,
64                                     gboolean enabled)
65 {
66   _COGL_RETURN_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC);
67   state->write_enabled = enabled;
68 }
69
70 gboolean
71 cogl_depth_state_get_write_enabled (CoglDepthState *state)
72 {
73   _COGL_RETURN_VAL_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC, FALSE);
74   return state->write_enabled;
75 }
76
77 void
78 cogl_depth_state_set_test_function (CoglDepthState *state,
79                                     CoglDepthTestFunction function)
80 {
81   _COGL_RETURN_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC);
82   state->test_function = function;
83 }
84
85 CoglDepthTestFunction
86 cogl_depth_state_get_test_function (CoglDepthState *state)
87 {
88   _COGL_RETURN_VAL_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC, FALSE);
89   return state->test_function;
90 }
91
92 void
93 cogl_depth_state_set_range (CoglDepthState *state,
94                             float near,
95                             float far)
96 {
97   _COGL_RETURN_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC);
98   state->range_near = near;
99   state->range_far = far;
100 }
101
102 void
103 cogl_depth_state_get_range (CoglDepthState *state,
104                             float *near_out,
105                             float *far_out)
106 {
107   _COGL_RETURN_IF_FAIL (state->magic == COGL_DEPTH_STATE_MAGIC);
108   *near_out = state->range_near;
109   *far_out = state->range_far;
110 }