src/ascension/shader.h

Mon, 18 Dec 2023 13:04:04 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Dec 2023 13:04:04 +0100
changeset 20
b101c1ef13c7
parent 16
c5dde81b6fb2
child 40
6c438be1a1fd
permissions
-rw-r--r--

add pseudo-rule s.t. dry-runs won't fail

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright 2023 Mike Becker. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef ASCENSION_SHADER_H
#define ASCENSION_SHADER_H

typedef struct AscShader {
    unsigned int id;
} AscShader;

typedef struct AscShaderProgram {
    unsigned int id;
    int model;
    int view;
    int projection;
} AscShaderProgram;

typedef struct AscShaderFont {
    AscShaderProgram base;
    int surface;
} AscShaderFont;


extern AscShaderFont ASC_SHADER_FONT;


/**
 * Compiles a shader from the given source code.
 *
 * The ID of the returned shader will be zero when something went wrong.
 *
 * @param type the shader type (use the GL enum)
 * @param code the source code
 * @param length the length of the source code
 * @return the compiled shader
 */
AscShader asc_shader_compile(unsigned int type, char const *code, int length);

/**
 * Compiles a shader from the given source file.
 *
 * The ID of the returned shader will be zero when something went wrong.
 * The file is mapped into memory for compilation and then unmapped again.
 *
 * @param type the shader type (use the GL enum)
 * @param filename the path to the shader file
 * @return the compiled shader
 */
AscShader asc_shader_compilef(unsigned int type, char const *filename);

/**
 * This function links shaders into a program.
 *
 * The ID of the returned program will be zero when something went wrong.
 *
 * @param vertex the vertex shader
 * @param fragment the fragment shader
 * @return a compiled program
 */
AscShaderProgram asc_shader_link(AscShader vertex, AscShader fragment);

/**
 * Destroys the shader.
 *
 * @param shader the shader
 */
void asc_shader_destroy(AscShader shader);

/**
 * Destroys the shader program.
 *
 * @param program the program
 */
void asc_shader_program_destroy(AscShaderProgram program);

/**
 * Initializes shaders that already come with the engine.
 */
void asc_shader_initialize_predefined(void);

/**
 * You do not need to do this manually.
 *
 * When the ascension context is destroyed, this function is called automatically.
 * When you did not initialize the predefined shaders, this function does nothing.
 */
void asc_shader_destroy_predefined(void);

#endif //ASCENSION_SHADER_H

mercurial