src/ascension/window.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 29
1d001eb694dc
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_WINDOW_H
#define ASCENSION_WINDOW_H

#include <SDL2/SDL.h>

#include "datatypes.h"
#include "primitives.h"

#ifndef ASC_MAX_WINDOWS
/** The maximum number of windows that can exist simultaneously. */
#define ASC_MAX_WINDOWS 4u
#endif // ASC_MAX_WINDOWS

typedef struct AscWindowSettings {
    int depth_size;
    int vsync;
    asc_vec2i dimensions;
    int fullscreen;
    int gl_major_version;
    int gl_minor_version;
    char const* title;
} AscWindowSettings;

typedef struct AscWindow {
    Uint32 id;
    SDL_Window* window;
    SDL_GLContext glctx;
    AscPrimitives primitives;
    asc_vec2i dimensions;
    asc_mat4f projection;
} AscWindow;

/**
 * Initializes the settings structure with default values.
 *
 * @param settings an uninitialized settings object
 */
void asc_window_settings_init_defaults(AscWindowSettings* settings);

/**
 * Creates and initializes a new window and a corresponding OpenGL context.
 *
 * The new window will also be automatically activated (see asc_window_activate()).
 *
 * The index specified must not be in use by another window already.
 * The maximum number of windows is defined by #ASC_MAX_WINDOWS.
 *
 * @param index the index of the new window
 * @param settings the settings to be used for initialization
 * @return a pointer to the window data or \c NULL if initialization failed
 */
AscWindow *asc_window_initialize(unsigned int index, AscWindowSettings const* settings);

/**
 * Destroys the window and its OpenGL context.
 *
 * When this window is currently active, there will be \em no active window afterwards.
 *
 * Still alive windows will also be destroyed by asc_context_destroy()
 * automatically.
 *
 * @param window the window
 */
void asc_window_destroy(AscWindow* window);

/**
 * Swaps buffers and adjusts the viewport to the current window size.
 *
 * This function is automatically invoked for all initialized windows
 * by asc_loop_next(). You usually do not need to call this function manually.
 *
 * @param window the window
 */
void asc_window_sync(AscWindow const *window);

/**
 * Switches the active window.
 *
 * In particular that makes the corresponding OpenGL context "current".
 * When you only want to draw into one window, you'll never need this.
 *
 * @param the window to activate
 */
void asc_window_activate(AscWindow const *window);

#endif /* ASCENSION_WINDOW_H */

mercurial