2008-06-02 10:58:57 +00:00
|
|
|
/*
|
2009-04-27 15:48:12 +01:00
|
|
|
* Cogl
|
2008-06-02 10:58:57 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2008-06-02 10:58:57 +00:00
|
|
|
*
|
2010-08-02 21:40:55 +01:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2008-06-02 10:58:57 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2008-06-02 10:58:57 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2008-06-02 10:58:57 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2008-06-02 10:58:57 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-05 22:21:51 +08:00
|
|
|
#include "cogl-config.h"
|
2008-06-02 10:58:57 +00:00
|
|
|
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 14:14:10 +01:00
|
|
|
#include "cogl-object-private.h"
|
2013-01-07 19:16:11 +00:00
|
|
|
#include "cogl-glsl-shader-boilerplate.h"
|
2018-05-21 21:57:38 +02:00
|
|
|
#include "driver/gl/cogl-util-gl-private.h"
|
|
|
|
#include "deprecated/cogl-shader-private.h"
|
2008-06-02 10:58:57 +00:00
|
|
|
|
2010-08-02 21:40:55 +01:00
|
|
|
#include <glib.h>
|
|
|
|
|
2010-08-04 17:53:51 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-06-02 10:58:57 +00:00
|
|
|
static void _cogl_shader_free (CoglShader *shader);
|
|
|
|
|
2009-04-01 17:16:44 +01:00
|
|
|
COGL_HANDLE_DEFINE (Shader, shader);
|
2008-06-02 10:58:57 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_shader_free (CoglShader *shader)
|
|
|
|
{
|
|
|
|
/* Frees shader resources but its handle is not
|
|
|
|
released! Do that separately before this! */
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2010-08-04 17:53:51 +01:00
|
|
|
|
|
|
|
if (shader->gl_handle)
|
2011-07-06 21:51:00 +01:00
|
|
|
GE (ctx, glDeleteShader (shader->gl_handle));
|
2010-07-22 16:58:23 +01:00
|
|
|
|
2020-10-18 13:46:08 +02:00
|
|
|
g_free (shader);
|
2008-06-02 10:58:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
2009-05-12 14:15:18 +01:00
|
|
|
cogl_create_shader (CoglShaderType type)
|
2008-06-02 10:58:57 +00:00
|
|
|
{
|
|
|
|
CoglShader *shader;
|
2009-05-12 14:15:18 +01:00
|
|
|
|
2019-02-20 14:53:01 +01:00
|
|
|
_COGL_GET_CONTEXT (ctx, NULL);
|
2010-08-02 21:40:55 +01:00
|
|
|
|
2010-08-04 17:53:51 +01:00
|
|
|
switch (type)
|
2009-05-12 14:15:18 +01:00
|
|
|
{
|
2010-08-04 17:53:51 +01:00
|
|
|
case COGL_SHADER_TYPE_VERTEX:
|
|
|
|
case COGL_SHADER_TYPE_FRAGMENT:
|
|
|
|
break;
|
|
|
|
default:
|
2009-05-12 14:15:18 +01:00
|
|
|
g_warning ("Unexpected shader type (0x%08lX) given to "
|
|
|
|
"cogl_create_shader", (unsigned long) type);
|
2019-02-20 14:53:01 +01:00
|
|
|
return NULL;
|
2009-05-12 14:15:18 +01:00
|
|
|
}
|
2008-06-02 10:58:57 +00:00
|
|
|
|
2020-10-18 13:46:08 +02:00
|
|
|
shader = g_new0 (CoglShader, 1);
|
2010-08-04 17:53:51 +01:00
|
|
|
shader->gl_handle = 0;
|
2013-01-19 16:00:33 +00:00
|
|
|
shader->compilation_pipeline = NULL;
|
2010-07-14 19:39:24 +01:00
|
|
|
shader->type = type;
|
2008-06-02 10:58:57 +00:00
|
|
|
|
|
|
|
return _cogl_shader_handle_new (shader);
|
|
|
|
}
|
|
|
|
|
2010-12-02 21:08:30 +00:00
|
|
|
void
|
|
|
|
cogl_shader_source (CoglHandle handle,
|
|
|
|
const char *source)
|
|
|
|
{
|
|
|
|
CoglShader *shader;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (!cogl_is_shader (handle))
|
|
|
|
return;
|
|
|
|
|
2012-03-06 18:21:28 +00:00
|
|
|
shader = handle;
|
2010-12-02 21:08:30 +00:00
|
|
|
|
|
|
|
shader->source = g_strdup (source);
|
|
|
|
}
|
|
|
|
|
2009-05-12 14:15:18 +01:00
|
|
|
CoglShaderType
|
|
|
|
cogl_shader_get_type (CoglHandle handle)
|
2008-06-02 10:58:57 +00:00
|
|
|
{
|
|
|
|
CoglShader *shader;
|
|
|
|
|
2011-07-06 21:51:00 +01:00
|
|
|
_COGL_GET_CONTEXT (ctx, COGL_SHADER_TYPE_VERTEX);
|
2010-08-02 21:40:55 +01:00
|
|
|
|
2008-06-02 10:58:57 +00:00
|
|
|
if (!cogl_is_shader (handle))
|
2009-05-12 14:15:18 +01:00
|
|
|
{
|
|
|
|
g_warning ("Non shader handle type passed to cogl_shader_get_type");
|
|
|
|
return COGL_SHADER_TYPE_VERTEX;
|
|
|
|
}
|
|
|
|
|
2012-03-06 18:21:28 +00:00
|
|
|
shader = handle;
|
2010-07-23 17:44:53 +01:00
|
|
|
return shader->type;
|
2009-05-12 14:15:18 +01:00
|
|
|
}
|