mirror of
https://github.com/brl/mutter.git
synced 2025-03-25 04:33:52 +00:00
cogl/pipeline/vertend/glsl: Move out unit test to its own file
Fix a memory leak while at it. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2555>
This commit is contained in:
parent
04bbe31287
commit
30daad4da5
@ -36,10 +36,15 @@
|
|||||||
|
|
||||||
#include "cogl-pipeline-private.h"
|
#include "cogl-pipeline-private.h"
|
||||||
|
|
||||||
|
typedef struct _CoglPipelineVertendShaderState CoglPipelineVertendShaderState;
|
||||||
|
|
||||||
extern const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
|
extern const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
|
||||||
|
|
||||||
GLuint
|
GLuint
|
||||||
_cogl_pipeline_vertend_glsl_get_shader (CoglPipeline *pipeline);
|
_cogl_pipeline_vertend_glsl_get_shader (CoglPipeline *pipeline);
|
||||||
|
|
||||||
|
COGL_EXPORT_TEST
|
||||||
|
CoglPipelineVertendShaderState * cogl_pipeline_vertend_glsl_get_shader_state (CoglPipeline *pipeline);
|
||||||
|
|
||||||
#endif /* __COGL_PIPELINE_VERTEND_GLSL_PRIVATE_H */
|
#endif /* __COGL_PIPELINE_VERTEND_GLSL_PRIVATE_H */
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <test-fixtures/test-unit.h>
|
|
||||||
|
|
||||||
#include "cogl-context-private.h"
|
#include "cogl-context-private.h"
|
||||||
#include "cogl-pipeline-private.h"
|
#include "cogl-pipeline-private.h"
|
||||||
#include "driver/gl/cogl-util-gl-private.h"
|
#include "driver/gl/cogl-util-gl-private.h"
|
||||||
@ -51,7 +49,7 @@
|
|||||||
|
|
||||||
const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
|
const CoglPipelineVertend _cogl_pipeline_glsl_vertend;
|
||||||
|
|
||||||
typedef struct
|
struct _CoglPipelineVertendShaderState
|
||||||
{
|
{
|
||||||
unsigned int ref_count;
|
unsigned int ref_count;
|
||||||
|
|
||||||
@ -59,7 +57,7 @@ typedef struct
|
|||||||
GString *header, *source;
|
GString *header, *source;
|
||||||
|
|
||||||
CoglPipelineCacheEntry *cache_entry;
|
CoglPipelineCacheEntry *cache_entry;
|
||||||
} CoglPipelineVertendShaderState;
|
};
|
||||||
|
|
||||||
static CoglUserDataKey shader_state_key;
|
static CoglUserDataKey shader_state_key;
|
||||||
|
|
||||||
@ -81,6 +79,12 @@ get_shader_state (CoglPipeline *pipeline)
|
|||||||
return cogl_object_get_user_data (COGL_OBJECT (pipeline), &shader_state_key);
|
return cogl_object_get_user_data (COGL_OBJECT (pipeline), &shader_state_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoglPipelineVertendShaderState *
|
||||||
|
cogl_pipeline_vertend_glsl_get_shader_state (CoglPipeline *pipeline)
|
||||||
|
{
|
||||||
|
return get_shader_state (pipeline);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_shader_state (void *user_data,
|
destroy_shader_state (void *user_data,
|
||||||
void *instance)
|
void *instance)
|
||||||
@ -737,58 +741,3 @@ const CoglPipelineVertend _cogl_pipeline_glsl_vertend =
|
|||||||
_cogl_pipeline_vertend_glsl_pre_change_notify,
|
_cogl_pipeline_vertend_glsl_pre_change_notify,
|
||||||
_cogl_pipeline_vertend_glsl_layer_pre_change_notify
|
_cogl_pipeline_vertend_glsl_layer_pre_change_notify
|
||||||
};
|
};
|
||||||
|
|
||||||
UNIT_TEST (check_point_size_shader,
|
|
||||||
0 /* no requirements */,
|
|
||||||
0 /* no failure cases */)
|
|
||||||
{
|
|
||||||
CoglPipeline *pipelines[4];
|
|
||||||
CoglPipelineVertendShaderState *shader_states[G_N_ELEMENTS (pipelines)];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Default pipeline with zero point size */
|
|
||||||
pipelines[0] = cogl_pipeline_new (test_ctx);
|
|
||||||
|
|
||||||
/* Point size 1 */
|
|
||||||
pipelines[1] = cogl_pipeline_new (test_ctx);
|
|
||||||
cogl_pipeline_set_point_size (pipelines[1], 1.0f);
|
|
||||||
|
|
||||||
/* Point size 2 */
|
|
||||||
pipelines[2] = cogl_pipeline_new (test_ctx);
|
|
||||||
cogl_pipeline_set_point_size (pipelines[2], 2.0f);
|
|
||||||
|
|
||||||
/* Same as the first pipeline, but reached by restoring the old
|
|
||||||
* state from a copy */
|
|
||||||
pipelines[3] = cogl_pipeline_copy (pipelines[1]);
|
|
||||||
cogl_pipeline_set_point_size (pipelines[3], 0.0f);
|
|
||||||
|
|
||||||
/* Draw something with all of the pipelines to make sure their state
|
|
||||||
* is flushed */
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (pipelines); i++)
|
|
||||||
cogl_framebuffer_draw_rectangle (test_fb,
|
|
||||||
pipelines[i],
|
|
||||||
0.0f, 0.0f,
|
|
||||||
10.0f, 10.0f);
|
|
||||||
cogl_framebuffer_finish (test_fb);
|
|
||||||
|
|
||||||
/* Get all of the shader states. These might be NULL if the driver
|
|
||||||
* is not using GLSL */
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (pipelines); i++)
|
|
||||||
shader_states[i] = get_shader_state (pipelines[i]);
|
|
||||||
|
|
||||||
/* If the first two pipelines are using GLSL then they should have
|
|
||||||
* the same shader unless there is no builtin uniform for the point
|
|
||||||
* size */
|
|
||||||
if (shader_states[0])
|
|
||||||
{
|
|
||||||
g_assert (shader_states[0] != shader_states[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The second and third pipelines should always have the same shader
|
|
||||||
* state because only toggling between zero and non-zero should
|
|
||||||
* change the shader */
|
|
||||||
g_assert (shader_states[1] == shader_states[2]);
|
|
||||||
|
|
||||||
/* The fourth pipeline should be exactly the same as the first */
|
|
||||||
g_assert (shader_states[0] == shader_states[3]);
|
|
||||||
}
|
|
||||||
|
@ -7,6 +7,7 @@ cogl_unit_tests = [
|
|||||||
['test-pipeline-state-known-failure', false, all_variants],
|
['test-pipeline-state-known-failure', false, all_variants],
|
||||||
['test-pipeline-state', true, all_variants],
|
['test-pipeline-state', true, all_variants],
|
||||||
['test-pipeline-glsl', true, all_variants],
|
['test-pipeline-glsl', true, all_variants],
|
||||||
|
['test-pipeline-vertend-glsl', true, all_variants],
|
||||||
]
|
]
|
||||||
|
|
||||||
test_env = environment()
|
test_env = environment()
|
||||||
|
70
src/tests/cogl/unit/test-pipeline-vertend-glsl.c
Normal file
70
src/tests/cogl/unit/test-pipeline-vertend-glsl.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "cogl-config.h"
|
||||||
|
|
||||||
|
#include "cogl/cogl.h"
|
||||||
|
#include "cogl/driver/gl/cogl-pipeline-vertend-glsl-private.h"
|
||||||
|
#include "tests/cogl-test-utils.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_pipeline_vertend_glsl_point_size_shader (void)
|
||||||
|
{
|
||||||
|
CoglPipeline *pipelines[4];
|
||||||
|
CoglPipelineVertendShaderState *shader_states[G_N_ELEMENTS (pipelines)];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Default pipeline with zero point size */
|
||||||
|
pipelines[0] = cogl_pipeline_new (test_ctx);
|
||||||
|
|
||||||
|
/* Point size 1 */
|
||||||
|
pipelines[1] = cogl_pipeline_new (test_ctx);
|
||||||
|
cogl_pipeline_set_point_size (pipelines[1], 1.0f);
|
||||||
|
|
||||||
|
/* Point size 2 */
|
||||||
|
pipelines[2] = cogl_pipeline_new (test_ctx);
|
||||||
|
cogl_pipeline_set_point_size (pipelines[2], 2.0f);
|
||||||
|
|
||||||
|
/* Same as the first pipeline, but reached by restoring the old
|
||||||
|
* state from a copy */
|
||||||
|
pipelines[3] = cogl_pipeline_copy (pipelines[1]);
|
||||||
|
cogl_pipeline_set_point_size (pipelines[3], 0.0f);
|
||||||
|
|
||||||
|
/* Draw something with all of the pipelines to make sure their state
|
||||||
|
* is flushed */
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (pipelines); i++)
|
||||||
|
{
|
||||||
|
cogl_framebuffer_draw_rectangle (test_fb,
|
||||||
|
pipelines[i],
|
||||||
|
0.0f, 0.0f,
|
||||||
|
10.0f, 10.0f);
|
||||||
|
}
|
||||||
|
cogl_framebuffer_finish (test_fb);
|
||||||
|
|
||||||
|
/* Get all of the shader states. These might be NULL if the driver
|
||||||
|
* is not using GLSL */
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (pipelines); i++)
|
||||||
|
{
|
||||||
|
shader_states[i] =
|
||||||
|
cogl_pipeline_vertend_glsl_get_shader_state (pipelines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the first two pipelines are using GLSL then they should have
|
||||||
|
* the same shader unless there is no builtin uniform for the point
|
||||||
|
* size */
|
||||||
|
if (shader_states[0])
|
||||||
|
g_assert (shader_states[0] != shader_states[1]);
|
||||||
|
|
||||||
|
/* The second and third pipelines should always have the same shader
|
||||||
|
* state because only toggling between zero and non-zero should
|
||||||
|
* change the shader */
|
||||||
|
g_assert (shader_states[1] == shader_states[2]);
|
||||||
|
|
||||||
|
/* The fourth pipeline should be exactly the same as the first */
|
||||||
|
g_assert (shader_states[0] == shader_states[3]);
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (pipelines); i++)
|
||||||
|
cogl_object_unref (pipelines[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
COGL_TEST_SUITE (
|
||||||
|
g_test_add_func ("/pipeline/vertend/glsl/point-size-shader",
|
||||||
|
test_pipeline_vertend_glsl_point_size_shader);
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user