Gawain: add immRect utility functions (replaces legacy glRect)

Caller is responsible for setting up vertex format, binding a shader program, and setting the color *before* calling immRect.
This commit is contained in:
Mike Erwin 2016-10-10 12:30:55 -04:00
parent 6371f8ff8a
commit 587a16352a
4 changed files with 67 additions and 0 deletions

View File

@ -72,6 +72,8 @@ set(SRC
gawain/element.h
gawain/immediate.c
gawain/immediate.h
gawain/imm_util.c
gawain/imm_util.h
gawain/vertex_buffer.c
gawain/vertex_buffer.h
gawain/vertex_format.c

View File

@ -31,6 +31,7 @@
#pragma once
#include "gawain/immediate.h"
#include "gawain/imm_util.h"
#include "GPU_shader.h"
/* Extend immBindProgram to use Blenders library of built-in shader programs.

View File

@ -0,0 +1,46 @@
// Gawain immediate mode drawing utilities
//
// This code is part of the Gawain library, with modifications
// specific to integration with Blender.
//
// Copyright 2016 Mike Erwin
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include "imm_util.h"
#include "immediate.h"
void immRectf(unsigned pos, float x1, float y1, float x2, float y2)
{
immBegin(GL_TRIANGLE_FAN, 4);
immVertex2f(pos, x1, y1);
immVertex2f(pos, x2, y1);
immVertex2f(pos, x2, y2);
immVertex2f(pos, x1, y2);
immEnd();
}
void immRecti(unsigned pos, int x1, int y1, int x2, int y2)
{
immBegin(GL_TRIANGLE_FAN, 4);
immVertex2i(pos, x1, y1);
immVertex2i(pos, x2, y1);
immVertex2i(pos, x2, y2);
immVertex2i(pos, x1, y2);
immEnd();
}
#if 0 // more complete version in case we want that
void immRecti_complete(int x1, int y1, int x2, int y2, const float color[4])
{
VertexFormat *format = immVertexFormat();
unsigned pos = add_attrib(format, "pos", GL_INT, 2, CONVERT_INT_TO_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4fv(color);
immRecti(pos, x1, y1, x2, y2);
immUnbindProgram();
}
#endif

View File

@ -0,0 +1,18 @@
// Gawain immediate mode drawing utilities
//
// This code is part of the Gawain library, with modifications
// specific to integration with Blender.
//
// Copyright 2016 Mike Erwin
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
#pragma once
// Draw 2D rectangles (replaces glRect functions)
// caller is reponsible for vertex format & shader
void immRectf(unsigned pos, float x1, float y1, float x2, float y2);
void immRecti(unsigned pos, int x1, int y1, int x2, int y2);