Filling a uniform struct (named for search purposes)

Since I seem to finally have gotten it right as far as a lack of opengl complaints indicates to me I figured I’d do as I did with the index buffer & post the flow of calls (still haven’t got my triangle on screen, would appreciate help with that):

make test
...
cd ../../bin && ./tryextra._x86_64_linux_cc_debug.elf -D APP_DATA=../run
Attempting to open module './libvfxglfw._x86_64_linux_cc_debug.so'... Success!
Attempting to open module './libvfxgl._x86_64_linux_cc_debug.so'... Success!
Creating program 'flat'
.../opengl_vfxapp.c:   42: glCreateProgram();
Creating/seeking shader with path '../run/shaders/spec.glsl'...
.../opengl_shader.c:  118: glCreateShader( GL_VERTEX_SHADER );
.../opengl_shader.c:   79: glShaderSource( 2, 1, [0x55de9a4943d0], (nil) );
.../opengl_shader.c:   87: glCompileShader( 2 );
.../opengl_shader.c:   88: glGetShaderiv( 2, GL_COMPILE_STATUS, 0x7ffdf2d65218 );
.../opengl_vfxapp.c:   62: glAttachShader( 1, 2 );
Success
Creating/seeking shader with path '../run/shaders/frag.glsl'...
.../opengl_shader.c:  118: glCreateShader( GL_FRAGMENT_SHADER );
.../opengl_shader.c:   79: glShaderSource( 3, 1, [0x55de9a9e5c70], (nil) );
.../opengl_shader.c:   87: glCompileShader( 3 );
.../opengl_shader.c:   88: glGetShaderiv( 3, GL_COMPILE_STATUS, 0x7ffdf2d65218 );
.../opengl_vfxapp.c:   62: glAttachShader( 1, 3 );
Success
Linking program...
.../opengl_vfxapp.c:   81: glLinkProgram( 1 );
.../opengl_vfxapp.c:   82: glGetProgramiv( 1, GL_LINK_STATUS, 0x7ffdf2d6539c );
Success
Testing program...
.../opengl_vfxapp.c:   97: glValidateProgram( 1 );
.../opengl_vfxapp.c:   98: glGetProgramiv( 1, GL_VALIDATE_STATUS, 0x7ffdf2d6539c );
Success
.../opengl_vfxapp.c:  145: glUseProgram( 1 );
.../opengl_vfxcfg.c:   23: glGenVertexArrays( 1, &ref );
.../opengl_vfxcfg.c:    6: glBindVertexArray( 1 );
.../opengl_vfxbuf.c:   32: glGenBuffers( 1, &ref );
.../opengl_vfxbuf.c:   52: glBindBuffer( GL_ARRAY_BUFFER, 1 );
.../opengl_vfxbuf.c:   91: glBufferData( GL_ARRAY_BUFFER, 96, 0x55de9aa1c150, GL_STATIC_DRAW );
====================================='UNIFORMS' name count = 9
.../opengl_vfxsym.c:  104: glGetUniformBlockIndex( 1, 'UNIFORMS' );
------------------------- [0] uint VtxCount
.../opengl_vfxsym.c:  137: sym->ref = top->ref /* 0 */;
------------------------- [1] uint FlatLine
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 0 */ + 1;
------------------------- [2] ivec2 WinPoint
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 1 */ + 1;
------------------------- [3] ivec3 WinSpace
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 2 */ + 1;
------------------------- [4] vec3 WinScale
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 3 */ + 1;
------------------------- [5] vec3 RegScale
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 4 */ + 1;
------------------------- [6] vec3 RegPoint
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 5 */ + 1;
------------------------- [7] vec3 RegEmits
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 6 */ + 1;
------------------------- [8] vec3 RegTakes
.../opengl_vfxsym.c:  137: sym->ref = prv->ref /* 7 */ + 1;
=====================================vec4 NulPoint, name count = 6
.../opengl_vfxbuf.c:   32: glGenBuffers( 1, &ref );
.../opengl_vfxbuf.c:   52: glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 2 );
.../opengl_vfxbuf.c:   91: glBufferData( GL_ELEMENT_ARRAY_BUFFER, 24, 0x55de9aa21c40, GL_STATIC_DRAW );
.../opengl_vfxsym.c:   24: glGetAttribLocation( 1, 'NulPoint' );
.../opengl_vfxbuf.c:   52: glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 2 );
.../opengl_vfxsym.c:  324: glVertexArrayElementBuffer( 1, 2 );
===========Entering draw loop==========
.../opengl_vfxapp.c:  145: glUseProgram( 1 );
.../opengl_vfxcfg.c:    6: glBindVertexArray( 1 );
>	Enabling VfxSym 'UNIFORMS'
>	Enabling VfxSym 'VtxCount'
.../opengl_vfxsym.c:  239: glUniform1ui( 0, 1 );
>	Disabling VfxSym 'VtxCount'
>	Enabling VfxSym 'FlatLine'
.../opengl_vfxsym.c:  239: glUniform1ui( 1, 4 );
>	Disabling VfxSym 'FlatLine'
>	Enabling VfxSym 'WinPoint'
.../opengl_vfxsym.c:  240: glUniform2i( 2, 720, 222 );
>	Disabling VfxSym 'WinPoint'
>	Enabling VfxSym 'WinSpace'
.../opengl_vfxsym.c:  240: glUniform3i( 3, 222, 480, 640 );
>	Disabling VfxSym 'WinSpace'
>	Enabling VfxSym 'WinScale'
.../opengl_vfxsym.c:  241: glUniform3f( 4, 0.000000, 0.000000, 0.000000 );
>	Disabling VfxSym 'WinScale'
>	Enabling VfxSym 'RegScale'
.../opengl_vfxsym.c:  241: glUniform3f( 5, 0.000000, 0.000000, 0.750000 );
>	Disabling VfxSym 'RegScale'
>	Enabling VfxSym 'RegPoint'
.../opengl_vfxsym.c:  241: glUniform3f( 6, 0.000000, 0.750000, 1.000000 );
>	Disabling VfxSym 'RegPoint'
>	Enabling VfxSym 'RegEmits'
.../opengl_vfxsym.c:  241: glUniform3f( 7, 0.750000, 1.000000, 1.000000 );
>	Disabling VfxSym 'RegEmits'
>	Enabling VfxSym 'RegTakes'
.../opengl_vfxsym.c:  241: glUniform3f( 8, 1.000000, 1.000000, 1.000000 );
>	Disabling VfxSym 'RegTakes'
>	Disabling VfxSym 'UNIFORMS'
>	Enabling VfxSym 'NulPoint'
.../opengl_vfxsym.c:  212: glEnableVertexArrayAttrib(  1, 0  );
.../opengl_vfxbuf.c:   52: glBindBuffer( GL_ARRAY_BUFFER, 1 );
.../opengl_vfxbuf.c:   52: glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 2 );
.../opengl_vfxbuf.c:   65: glVertexArrayElementBuffer( 1, 1 );
.../opengl_vfxsym.c:  343: glDrawElementsInstanced( GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, 0x55de9aa21c40, 4 );
>	Disabling VfxSym 'NulPoint'
.../opengl_vfxsym.c:  200: glDisableVertexArrayAttrib(  1, 0  );
-------------------------------
...
-------------------------------
.../opengl_vfxbuf.c:   16: glDeleteBuffers( 1, [2] );
.../opengl_vfxbuf.c:   16: glDeleteBuffers( 1, [1] );
.../opengl_vfxcfg.c:   42: glDeleteVertexArrays( 1, [1] );
.../opengl_shader.c:  139: glDeleteShader( 3 );
.../opengl_shader.c:  139: glDeleteShader( 2 );
.../opengl_vfxapp.c:  154: glDeleteProgram( 1 );
Compilation finished successfully.

Since my glsl has changed a bit I’ll post that also:

#ifndef SAME_GLSL
#define SAME_GLSL

#	if defined(GL_SPIRV) || defined(GL_core_profile) || \
	defined(GL_compatibility_profile) || defined(GL_es_profile)
#		define IS_OPENGL
#	endif

#	if defined(IS_OPENGL) || defined(VULKAN)
/* Mappings to CGLM union names */
#		define uvec2s	uvec2
#		define uvec3s	uvec3
#		define uvec4s	uvec4
#		define ivec2s	ivec2
#		define ivec3s	ivec3
#		define ivec4s	ivec4
#		define vec2s	vec2
#		define vec3s	vec3
#		define vec4s	vec4
#		define dvec2s	dvec2
#		define dvec3s	dvec3
#		define dvec4s	dvec4
#	else
#		include <cglm/struct.h>
#		include <cglm/cglm.h>
#		include <cglm/call.h>
#		define uniform typedef struct
#	endif /* IS_OPENGL / VULKAN */


uniform UNIFORMS
{
	/* unsigned integers */
	uint	FlatLine;
	uint	VtxCount;
	/* signed integers */
	ivec2s	WinPoint;
	ivec3s	WinSpace;
	/* floats */
	vec3s	WinScale;
	vec3s	RegScale;
	vec3s	RegPoint;
	/* Light emitted */
	vec3s	RegEmits;
	/* Light taken before ray bounces */
	vec3s	RegTakes;
} uniforms;

#define UNIFORM_NAMES \
	"VtxCount", "FlatLine", \
	"WinPoint", "WinSpace", \
	"WinScale", "RegScale", "RegPoint", "RegEmits", "RegTakes"
#define UNIFORM_TYPES \
	VFXDATA_UINT, VFXDATA_UINT, \
	VFXDATA_IVEC2, VFXDATA_IVEC3, \
	VFXDATA_FVEC3, VFXDATA_FVEC3, VFXDATA_FVEC3, VFXDATA_FVEC3, VFXDATA_FVEC3
#define UNIFORMS_TAKE 1, 1, 1, 1, 1, 1, 1, 1, 1

#	ifndef IS_OPENGL
#		undef uniform
#	else
const int INT_MAX = int(  ~0u >> 1 );
const int INT_MIN = int(~(~0u >> 1));

const uint		uqtr = ~0u / 4;
const uint		uoct = ~0u / 8;
const double	dcap = double(~0u);
const double	dqtr = double(~0u / 4);

vec2 square_vertices[] =
{
	{  0.25,  0.25 },
	{  0.25,  0.75 },
	{  0.75,  0.25 },
	{  0.75,  0.75 }
};

vec4 edge_vertex( uint x, uint y )
{
	vec4 point;
	point.x = (float(double(x) / dqtr) * 2.0) - 1.0;
	point.y = (float(double(y) / dqtr) * 2.0) - 1.0;
	point.z = 1.0;
	point.w	= 1.0;
	return point;
}

vec4 calc_point( uint v, uint vertices )
{
	double aim = double(v);
	double max = double(vertices);
	uint rotate = uint((aim / max) * dcap);
	uint linear = rotate % uqtr;

	if ( uniforms.FlatLine != 0 )
		return edge_vertex( linear, uqtr - linear );
	else
	{
		uint curved = linear + (linear / 3);
		if ( linear < uoct )
			return edge_vertex( curved, uqtr - linear );
		else
			return edge_vertex( linear, uqtr - curved );
	}
}
#	endif /* IS_OPENGL */

#endif /* SAME_GLSL */

spec.glsl (Vertex shader)

#version 440
#include "same.glsl"

in vec4 NulPoint;
out VERTEX
{
	vec4 DyeColor;
	vec4 DyeTexel;
} frag;

void main()
{
	uint v = gl_InstanceID, c = uniforms.VtxCount, stop = c - 1;
	vec4 center = vec4( 0.0, 0.0, 0.0, 1.0 );

	gl_Position =
		vec4( square_vertices[v % 4], 1.0, 1.0 ) + vec4( NulPoint.xyz, 1.0 );
	frag.DyeColor = vec4(1.0,1.0,1.0,1.0);
	frag.DyeTexel = vec4(1.0,1.0,1.0,1.0);
}

frag.glsl (Fragment shader)

#version 440
#include "same.glsl"

in VERTEX
{
	vec4 DyeColor;
	/* We use a vec4 so we can store our information in 1 cache, we can just use
	 * the extra values for something else, like say the index of the texel */
	vec4 DyeTexel;
} frag;

uniform sampler2D Texture;

out vec4 UseColor;

void main()
{
	vec4 ImgColor = texture( Texture, frag.DyeTexel.zw );
	UseColor = frag.DyeColor;// * ImgColor;
}

Edit: btw both NulPoint buffers (vertex & index) are filled with just 0, they only exist as placeholders for now, the current goal is calculate rotated points correctly using just the instance number

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.