Skip to content

Commit

Permalink
call-lists: correctly handle glColor() commands
Browse files Browse the repository at this point in the history
In call lists we were properly handling glColor() calls if they appeared
within glBegin()/glEnd(), otherwise they were ignored.

Fix this by storing these commands too in the call lists.
  • Loading branch information
mardy authored and WinterMute committed Oct 6, 2024
1 parent 23d53e2 commit a95baa0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/call_lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ typedef struct
GLfloat z;
} rotate;

float color[4];

float matrix[16];
} c;
} Command;
Expand Down Expand Up @@ -265,6 +267,9 @@ static void run_command(Command *cmd)
case COMMAND_FRONT_FACE:
glFrontFace(cmd->c.mode);
break;
case COMMAND_COLOR:
glColor4fv(cmd->c.color);
break;
}

}
Expand Down Expand Up @@ -458,6 +463,9 @@ bool _ogx_call_list_append(CommandType op, ...)
case COMMAND_FRONT_FACE:
command->c.mode = va_arg(ap, GLenum);
break;
case COMMAND_COLOR:
floatcpy(command->c.color, va_arg(ap, GLfloat *), 4);
break;
}
va_end(ap);
return glparamstate.current_call_list.must_execute;
Expand Down
9 changes: 9 additions & 0 deletions src/call_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ POSSIBILITY OF SUCH DAMAGE.

#include "state.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Except when specified otherwise, the enum name matches the GL function
* (e.g., COMMAND_ENABLE == glEnable)
*/
Expand All @@ -59,6 +63,7 @@ typedef enum {
COMMAND_ROTATE,
COMMAND_SCALE,
COMMAND_FRONT_FACE,
COMMAND_COLOR,
} CommandType;

#define HANDLE_CALL_LIST(operation, ...) \
Expand All @@ -70,4 +75,8 @@ typedef enum {

bool _ogx_call_list_append(CommandType op, ...);

#ifdef __cplusplus
} // extern C
#endif

#endif /* OPENGX_CALL_LISTS_H */
14 changes: 10 additions & 4 deletions src/vertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/

#include "call_lists.h"
#include "debug.h"
#include "state.h"
#include "utils.h"
Expand All @@ -51,10 +52,7 @@ T full_color()
template <typename T>
void set_current_color(T red, T green, T blue, T alpha = full_color<T>())
{
if (glparamstate.imm_mode.in_gl_begin)
glparamstate.imm_mode.has_color = 1;

auto &c = glparamstate.imm_mode.current_color;
float c[4];
if constexpr (std::is_floating_point<T>::value) {
c[0] = red;
c[1] = green;
Expand All @@ -71,6 +69,14 @@ void set_current_color(T red, T green, T blue, T alpha = full_color<T>())
c[2] = blue / max;
c[3] = alpha / max;
}

if (glparamstate.imm_mode.in_gl_begin) {
glparamstate.imm_mode.has_color = 1;
} else {
HANDLE_CALL_LIST(COLOR, c);
}

floatcpy(glparamstate.imm_mode.current_color, c, 4);
}

static inline void set_current_tex_coords(float s, float t = 0)
Expand Down

0 comments on commit a95baa0

Please sign in to comment.