summaryrefslogtreecommitdiffstats
path: root/src/mesa/tnl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/tnl')
-rw-r--r--src/mesa/tnl/t_context.c3
-rw-r--r--src/mesa/tnl/t_context.h2
-rw-r--r--src/mesa/tnl/t_draw.c67
-rw-r--r--src/mesa/tnl/t_vb_program.c37
-rw-r--r--src/mesa/tnl/t_vertex.h5
-rw-r--r--src/mesa/tnl/t_vp_build.c2
-rw-r--r--src/mesa/tnl/t_vp_build.h2
-rw-r--r--src/mesa/tnl/tnl.h5
8 files changed, 87 insertions, 36 deletions
diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
index 47aeeb88594..5f5e2663b5f 100644
--- a/src/mesa/tnl/t_context.c
+++ b/src/mesa/tnl/t_context.c
@@ -34,6 +34,7 @@
#include "main/light.h"
#include "math/m_translate.h"
#include "math/m_xform.h"
+#include "main/state.h"
#include "tnl.h"
#include "t_context.h"
@@ -127,7 +128,7 @@ _tnl_InvalidateState( struct gl_context *ctx, GLuint new_state )
RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR0 );
}
- if (NEED_SECONDARY_COLOR(ctx))
+ if (_mesa_need_secondary_color(ctx))
RENDERINPUTS_SET( tnl->render_inputs_bitset, _TNL_ATTRIB_COLOR1 );
for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
index bc01646247c..6a9444216c0 100644
--- a/src/mesa/tnl/t_context.h
+++ b/src/mesa/tnl/t_context.h
@@ -527,6 +527,8 @@ typedef struct
GLubyte *block[VERT_ATTRIB_MAX];
GLuint nr_blocks;
+ GLuint CurInstance;
+
} TNLcontext;
diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c
index e2aac64ad74..b1967e65417 100644
--- a/src/mesa/tnl/t_draw.c
+++ b/src/mesa/tnl/t_draw.c
@@ -125,6 +125,43 @@ convert_half_to_float(const struct gl_client_array *input,
}
}
+/**
+ * \brief Convert fixed-point to floating-point.
+ *
+ * In OpenGL, a fixed-point number is a "signed 2's complement 16.16 scaled
+ * integer" (Table 2.2 of the OpenGL ES 2.0 spec).
+ *
+ * If the buffer has the \c normalized flag set, the formula
+ * \code normalize(x) := (2*x + 1) / (2^16 - 1) \endcode
+ * is used to map the fixed-point numbers into the range [-1, 1].
+ */
+static void
+convert_fixed_to_float(const struct gl_client_array *input,
+ const GLubyte *ptr, GLfloat *fptr,
+ GLuint count)
+{
+ GLuint i, j;
+ const GLint size = input->Size;
+
+ if (input->Normalized) {
+ for (i = 0; i < count; ++i) {
+ const GLfixed *in = (GLfixed *) ptr;
+ for (j = 0; j < size; ++j) {
+ *fptr++ = (GLfloat) (2 * in[j] + 1) / (GLfloat) ((1 << 16) - 1);
+ }
+ ptr += input->StrideB;
+ }
+ } else {
+ for (i = 0; i < count; ++i) {
+ const GLfixed *in = (GLfixed *) ptr;
+ for (j = 0; j < size; ++j) {
+ *fptr++ = in[j] / (GLfloat) (1 << 16);
+ }
+ ptr += input->StrideB;
+ }
+ }
+}
+
/* Adjust pointer to point at first requested element, convert to
* floating point, populate VB->AttribPtr[].
*/
@@ -175,14 +212,7 @@ static void _tnl_import_array( struct gl_context *ctx,
convert_half_to_float(input, ptr, fptr, count, sz);
break;
case GL_FIXED:
- {
- GLuint i, j;
- for (i = 0; i < count; i++) {
- const GLint *in = (GLint *) (ptr + i * input->StrideB);
- for (j = 0; j < sz; j++)
- *fptr++ = *in++ / 65536.0f;
- }
- }
+ convert_fixed_to_float(input, ptr, fptr, count);
break;
default:
assert(0);
@@ -463,6 +493,7 @@ void _tnl_draw_prims( struct gl_context *ctx,
*/
struct gl_buffer_object *bo[VERT_ATTRIB_MAX + 1];
GLuint nr_bo = 0;
+ GLuint inst;
for (i = 0; i < nr_prims;) {
GLuint this_nr_prims;
@@ -477,18 +508,24 @@ void _tnl_draw_prims( struct gl_context *ctx,
break;
}
+ assert(prim[i].num_instances > 0);
+
/* Binding inputs may imply mapping some vertex buffer objects.
* They will need to be unmapped below.
*/
- bind_prims(ctx, &prim[i], this_nr_prims);
- bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1,
- bo, &nr_bo);
- bind_indices(ctx, ib, bo, &nr_bo);
+ for (inst = 0; inst < prim[i].num_instances; inst++) {
- TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx);
+ bind_prims(ctx, &prim[i], this_nr_prims);
+ bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1,
+ bo, &nr_bo);
+ bind_indices(ctx, ib, bo, &nr_bo);
- unmap_vbos(ctx, bo, nr_bo);
- free_space(ctx);
+ tnl->CurInstance = inst;
+ TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx);
+
+ unmap_vbos(ctx, bo, nr_bo);
+ free_space(ctx);
+ }
i += this_nr_prims;
}
diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c
index 76f8fde3f52..f5d8f7477aa 100644
--- a/src/mesa/tnl/t_vb_program.c
+++ b/src/mesa/tnl/t_vb_program.c
@@ -67,6 +67,8 @@ struct vp_stage_data {
GLvector4f ndcCoords; /**< normalized device coords */
GLubyte *clipmask; /**< clip flags */
GLubyte ormask, andmask; /**< for clipping */
+
+ struct gl_program_machine machine;
};
@@ -218,7 +220,8 @@ _tnl_program_string(struct gl_context *ctx, GLenum target, struct gl_program *pr
* Initialize virtual machine state prior to executing vertex program.
*/
static void
-init_machine(struct gl_context *ctx, struct gl_program_machine *machine)
+init_machine(struct gl_context *ctx, struct gl_program_machine *machine,
+ GLuint instID)
{
/* Input registers get initialized from the current vertex attribs */
memcpy(machine->VertAttribs, ctx->Current.Attrib,
@@ -254,6 +257,8 @@ init_machine(struct gl_context *ctx, struct gl_program_machine *machine)
machine->FetchTexelDeriv = NULL; /* not used by vertex programs */
machine->Samplers = ctx->VertexProgram._Current->Base.SamplerUnits;
+
+ machine->SystemValues[SYSTEM_VALUE_INSTANCE_ID][0] = (GLfloat) instID;
}
@@ -311,7 +316,7 @@ run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage )
struct vp_stage_data *store = VP_STAGE_DATA(stage);
struct vertex_buffer *VB = &tnl->vb;
struct gl_vertex_program *program = ctx->VertexProgram._Current;
- struct gl_program_machine machine;
+ struct gl_program_machine *machine = &store->machine;
GLuint outputs[VERT_RESULT_MAX], numOutputs;
GLuint i, j;
@@ -339,7 +344,7 @@ run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage )
for (i = 0; i < VB->Count; i++) {
GLuint attr;
- init_machine(ctx, &machine);
+ init_machine(ctx, machine, tnl->CurInstance);
#if 0
printf("Input %d: %f, %f, %f, %f\n", i,
@@ -372,23 +377,23 @@ run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage )
check_float(data[2]);
check_float(data[3]);
#endif
- COPY_CLEAN_4V(machine.VertAttribs[attr], size, data);
+ COPY_CLEAN_4V(machine->VertAttribs[attr], size, data);
}
}
/* execute the program */
- _mesa_execute_program(ctx, &program->Base, &machine);
+ _mesa_execute_program(ctx, &program->Base, machine);
/* copy the output registers into the VB->attribs arrays */
for (j = 0; j < numOutputs; j++) {
const GLuint attr = outputs[j];
#ifdef NAN_CHECK
- check_float(machine.Outputs[attr][0]);
- check_float(machine.Outputs[attr][1]);
- check_float(machine.Outputs[attr][2]);
- check_float(machine.Outputs[attr][3]);
+ check_float(machine->Outputs[attr][0]);
+ check_float(machine->Outputs[attr][1]);
+ check_float(machine->Outputs[attr][2]);
+ check_float(machine->Outputs[attr][3]);
#endif
- COPY_4V(store->results[attr].data[i], machine.Outputs[attr]);
+ COPY_4V(store->results[attr].data[i], machine->Outputs[attr]);
}
/* FOGC is a special case. Fragment shader expects (f,0,0,1) */
@@ -398,14 +403,14 @@ run_vp( struct gl_context *ctx, struct tnl_pipeline_stage *stage )
store->results[VERT_RESULT_FOGC].data[i][3] = 1.0;
}
#ifdef NAN_CHECK
- ASSERT(machine.Outputs[0][3] != 0.0F);
+ ASSERT(machine->Outputs[0][3] != 0.0F);
#endif
#if 0
printf("HPOS: %f %f %f %f\n",
- machine.Outputs[0][0],
- machine.Outputs[0][1],
- machine.Outputs[0][2],
- machine.Outputs[0][3]);
+ machine->Outputs[0][0],
+ machine->Outputs[0][1],
+ machine->Outputs[0][2],
+ machine->Outputs[0][3]);
#endif
}
@@ -501,7 +506,7 @@ init_vp(struct gl_context *ctx, struct tnl_pipeline_stage *stage)
const GLuint size = VB->Size;
GLuint i;
- stage->privatePtr = MALLOC(sizeof(*store));
+ stage->privatePtr = CALLOC(sizeof(*store));
store = VP_STAGE_DATA(stage);
if (!store)
return GL_FALSE;
diff --git a/src/mesa/tnl/t_vertex.h b/src/mesa/tnl/t_vertex.h
index 252f2f7c295..83b0dbcebbd 100644
--- a/src/mesa/tnl/t_vertex.h
+++ b/src/mesa/tnl/t_vertex.h
@@ -28,9 +28,12 @@
#ifndef _TNL_VERTEX_H
#define _TNL_VERTEX_H
-#include "main/mtypes.h"
+#include "main/glheader.h"
#include "t_context.h"
+struct gl_context;
+struct tnl_clipspace;
+
/* New mechanism to specify hardware vertices so that tnl can build
* and manipulate them directly.
*/
diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c
index 421ec88a454..70492a4353d 100644
--- a/src/mesa/tnl/t_vp_build.c
+++ b/src/mesa/tnl/t_vp_build.c
@@ -32,7 +32,7 @@
#include "main/glheader.h"
#include "main/ffvertex_prog.h"
-#include "main/dd.h"
+#include "main/mtypes.h"
#include "t_vp_build.h"
diff --git a/src/mesa/tnl/t_vp_build.h b/src/mesa/tnl/t_vp_build.h
index 1d10ff245d9..e9f6de5a920 100644
--- a/src/mesa/tnl/t_vp_build.h
+++ b/src/mesa/tnl/t_vp_build.h
@@ -27,7 +27,7 @@
#ifndef T_VP_BUILD_H
#define T_VP_BUILD_H
-#include "main/mtypes.h"
+struct gl_context;
#define TNL_FIXED_FUNCTION_STATE_FLAGS (_NEW_PROGRAM | \
_NEW_LIGHT | \
diff --git a/src/mesa/tnl/tnl.h b/src/mesa/tnl/tnl.h
index 702efdc5cca..24a0c725008 100644
--- a/src/mesa/tnl/tnl.h
+++ b/src/mesa/tnl/tnl.h
@@ -28,8 +28,11 @@
#ifndef _TNL_H
#define _TNL_H
-#include "main/mtypes.h"
+#include "main/glheader.h"
+struct gl_client_array;
+struct gl_context;
+struct gl_program;
/* These are the public-access functions exported from tnl. (A few