Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/gldemo/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void setup_plane()

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, plane_buffers[1]);

glBindVertexArray(0);
}

Expand Down Expand Up @@ -103,13 +105,9 @@ void make_plane_mesh()

void draw_plane()
{
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, plane_buffers[1]);
glBindVertexArray(plane_array);

glDrawElements(GL_TRIANGLES, plane_index_count, GL_UNSIGNED_SHORT, 0);

glBindVertexArray(0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}

void render_plane()
Expand Down
4 changes: 2 additions & 2 deletions examples/gldemo/sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void setup_sphere()

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sphere_buffers[1]);

glBindVertexArray(0);

sphere_list = glGenLists(1);
Expand Down Expand Up @@ -77,15 +79,13 @@ void make_sphere_vertex(vertex_t *dst, uint32_t ring, uint32_t segment)

void draw_sphere_internal()
{
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sphere_buffers[1]);
glBindVertexArray(sphere_array);

glDrawElements(GL_TRIANGLE_FAN, sphere_segments + 2, GL_UNSIGNED_SHORT, 0);
glDrawElements(GL_TRIANGLE_FAN, sphere_segments + 2, GL_UNSIGNED_SHORT, (void*)((sphere_segments + 2) * sizeof(uint16_t)));
glDrawElements(GL_TRIANGLES, (sphere_rings - 1) * (sphere_segments * 6), GL_UNSIGNED_SHORT, (void*)((sphere_segments + 2) * 2 * sizeof(uint16_t)));

glBindVertexArray(0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
}

void make_sphere_mesh()
Expand Down
1 change: 1 addition & 0 deletions include/GL/gl_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define GL_FLOAT 0x1406
#define GL_DOUBLE 0x140A
#define GL_HALF_FIXED_N64 0x6F00
#define GL_SHORT_5_6_5_N64 0x6F01

#define GL_NO_ERROR 0
#define GL_INVALID_ENUM 0x0500
Expand Down
81 changes: 81 additions & 0 deletions src/GL/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#ifndef __ARRAY_H
#define __ARRAY_H

#include <stdint.h>
#include "GL/gl.h"

typedef enum {
ARRAY_VERTEX,
ARRAY_NORMAL,
ARRAY_COLOR,
ARRAY_TEXCOORD,
ARRAY_MTX_INDEX,
ARRAY_COUNT
} array_type_t;

typedef struct gl_buffer_object_s gl_buffer_object_t;

typedef void (*cpu_read_attrib_func)(void*,const void*,uint32_t);
typedef void (*rsp_read_attrib_func)(void*,const void*,uint32_t);

typedef struct array_s {
GLint size;
GLenum type;
GLsizei stride;
const GLvoid *pointer;
gl_buffer_object_t *binding;
bool normalize;
bool enabled;

const GLvoid *final_pointer;
uint16_t final_stride;
cpu_read_attrib_func cpu_read_func;
rsp_read_attrib_func rsp_read_func;
} array_t;

#ifdef __cplusplus
extern "C" {
#endif

inline uint32_t array_type_get_stride(array_type_t type)
{
switch (type)
{
case ARRAY_VERTEX:
return sizeof(int16_t) * 3;
case ARRAY_NORMAL:
return sizeof(uint16_t);
case ARRAY_COLOR:
return sizeof(uint32_t);
case ARRAY_TEXCOORD:
return sizeof(int16_t) * 2;
case ARRAY_MTX_INDEX:
return sizeof(uint8_t);
default:
return 0;
}
}

inline uint32_t array_type_get_alignment(array_type_t type)
{
switch (type)
{
case ARRAY_VERTEX:
return 8;
case ARRAY_NORMAL:
return 2;
case ARRAY_COLOR:
return 4;
case ARRAY_TEXCOORD:
return 4;
case ARRAY_MTX_INDEX:
default:
return 1;
}
}

#ifdef __cplusplus
}
#endif

#endif
15 changes: 15 additions & 0 deletions src/GL/array_convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "array_convert.h"

void array_convert(array_convert_parms_t *parms)
{
for (size_t i = 0; i < parms->range.count; i++)
{
for (size_t j = 0; j < parms->array_count; j++)
{
uint8_t *dst = ((uint8_t*)parms->out_buffer) + parms->out_layout->offsets[j] + i * parms->out_layout->stride;
const array_t *array = parms->arrays[j];
const uint8_t *src = ((const uint8_t*)array->final_pointer) + (i+parms->range.first) * array->final_stride;
array->rsp_read_func(dst, src, array->size);
}
}
}
26 changes: 26 additions & 0 deletions src/GL/array_convert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef __ARRAY_CONVERT_H
#define __ARRAY_CONVERT_H

#include "indices.h"
#include "array.h"
#include "data_source.h"

typedef struct array_convert_parms_s {
const array_t *arrays[ARRAY_COUNT];
uint32_t array_count;
const data_layout_t *out_layout;
index_bounds_t range;
void *out_buffer;
} array_convert_parms_t;

#ifdef __cplusplus
extern "C" {
#endif

void array_convert(array_convert_parms_t *parms);

#ifdef __cplusplus
}
#endif

#endif
Loading
Loading