src/ascension/shader.h

Tue, 09 Apr 2024 21:18:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 09 Apr 2024 21:18:52 +0200
changeset 50
d8d2e4817db1
parent 44
b3da4096c607
child 72
84472fb3adbd
permissions
-rw-r--r--

add texture.h

/*
 * 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 AscShaderSprite {
    AscShaderProgram base;
    int depth;
    int tex;
} AscShaderSprite;


/**
 * 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);


AscShaderProgram asc_shader_easy_compile_and_link(
        char const *vtxName,
        char const *fragName
);

#endif //ASCENSION_SHADER_H

mercurial