GL3: Fix color-only rendering of models (+refactor GL3_UpdateUBO*)

* Of course the color attribute has 4 floats, not 2..
* I read that updating UBOs with glBufferData() is kinda slow.
  I didn't change that (yet), but at least all three GL3_UpdateUBO*()
  functions now call updateUBO() which can easily be changed to do
  whatever is best without touching the other three functions.
This commit is contained in:
Daniel Gibson 2017-02-26 00:20:32 +01:00
parent b7bf822e6d
commit f3e77e1123
3 changed files with 14 additions and 7 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016-2017 Daniel Gibson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View file

@ -717,20 +717,25 @@ void GL3_ShutdownShaders(void)
gl3state.uniCommonUBO = gl3state.uni2DUBO = gl3state.uni3DUBO = 0;
}
static inline void
updateUBO(GLuint ubo, GLsizeiptr size, void* data)
{
// TODO: use glMapBufferRange() or something else instead?
glBindBuffer(GL_UNIFORM_BUFFER, ubo);
glBufferData(GL_UNIFORM_BUFFER, size, data, GL_DYNAMIC_DRAW);
}
void GL3_UpdateUBOCommon(void)
{
glBindBuffer(GL_UNIFORM_BUFFER, gl3state.uniCommonUBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(gl3state.uniCommonData), &gl3state.uniCommonData, GL_DYNAMIC_DRAW);
updateUBO(gl3state.uniCommonUBO, sizeof(gl3state.uniCommonData), &gl3state.uniCommonData);
}
void GL3_UpdateUBO2D(void)
{
glBindBuffer(GL_UNIFORM_BUFFER, gl3state.uni2DUBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(gl3state.uni2DData), &gl3state.uni2DData, GL_DYNAMIC_DRAW);
updateUBO(gl3state.uni2DUBO, sizeof(gl3state.uni2DData), &gl3state.uni2DData);
}
void GL3_UpdateUBO3D(void)
{
glBindBuffer(GL_UNIFORM_BUFFER, gl3state.uni3DUBO);
glBufferData(GL_UNIFORM_BUFFER, sizeof(gl3state.uni3DData), &gl3state.uni3DData, GL_DYNAMIC_DRAW);
updateUBO(gl3state.uni3DUBO, sizeof(gl3state.uni3DData), &gl3state.uni3DData);
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016-2017 Daniel Gibson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -74,7 +75,7 @@ void GL3_SurfInit(void)
qglVertexAttribPointer(GL3_ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), 3*sizeof(GLfloat));
glEnableVertexAttribArray(GL3_ATTRIB_COLOR);
qglVertexAttribPointer(GL3_ATTRIB_COLOR, 2, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), 5*sizeof(GLfloat));
qglVertexAttribPointer(GL3_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 9*sizeof(GLfloat), 5*sizeof(GLfloat));
}
void GL3_SurfShutdown(void)