Beispiel #1
0
/**
 * Helper function used by the functions below.
 */
static GLint
add_parameter(struct program_parameter_list *paramList,
              const char *name, const GLfloat values[4],
              enum parameter_type type)
{
   const GLuint n = paramList->NumParameters;

   paramList->Parameters = (struct program_parameter *)
      _mesa_realloc(paramList->Parameters,
                    n * sizeof(struct program_parameter),
                    (n + 1) * sizeof(struct program_parameter));
   if (!paramList->Parameters) {
      /* out of memory */
      paramList->NumParameters = 0;
      return -1;
   }
   else {
      paramList->NumParameters = n + 1;
      paramList->Parameters[n].Name = _mesa_strdup(name);
      paramList->Parameters[n].Type = type;
      if (values)
         COPY_4V(paramList->Parameters[n].Values, values);
      return (GLint) n;
   }
}
Beispiel #2
0
/**
 * Allocate space for and store data in a buffer object.  Any data that was
 * previously stored in the buffer object is lost.  If \c data is \c NULL,
 * memory will be allocated, but no copy will occur.
 *
 * This is the default callback for \c dd_function_table::BufferData()
 * Note that all GL error checking will have been done already.
 *
 * \param ctx     GL context.
 * \param target  Buffer object target on which to operate.
 * \param size    Size, in bytes, of the new data store.
 * \param data    Pointer to the data to store in the buffer object.  This
 *                pointer may be \c NULL.
 * \param usage   Hints about how the data will be used.
 * \param bufObj  Object to be used.
 *
 * \return GL_TRUE for success, GL_FALSE for failure
 * \sa glBufferDataARB, dd_function_table::BufferData.
 */
static GLboolean
_mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
		   const GLvoid * data, GLenum usage,
		   struct gl_buffer_object * bufObj )
{
   void * new_data;

   (void) ctx; (void) target;

   new_data = _mesa_realloc( bufObj->Data, bufObj->Size, size );
   if (new_data) {
      bufObj->Data = (GLubyte *) new_data;
      bufObj->Size = size;
      bufObj->Usage = usage;

      if (data) {
	 memcpy( bufObj->Data, data, size );
      }

      return GL_TRUE;
   }
   else {
      return GL_FALSE;
   }
}
Beispiel #3
0
static void emit_op3fn(struct tnl_program *p,
		       GLuint op,
		       struct ureg dest,
		       GLuint mask,
		       struct ureg src0,
		       struct ureg src1,
		       struct ureg src2,
		       const char *fn,
		       GLuint line)
{
   GLuint nr = p->program->Base.NumInstructions++;
      
   if (nr >= p->nr_instructions) {
      p->program->Base.Instructions = 
	 _mesa_realloc(p->program->Base.Instructions,
		       sizeof(struct prog_instruction) * p->nr_instructions,
		       sizeof(struct prog_instruction) * (p->nr_instructions *= 2));
   }

   {      
      struct prog_instruction *inst = &p->program->Base.Instructions[nr];
      memset(inst, 0, sizeof(*inst));
      inst->Opcode = op; 
      inst->StringPos = 0;
      inst->Data = 0;
   
      emit_arg( &inst->SrcReg[0], src0 );
      emit_arg( &inst->SrcReg[1], src1 );
      emit_arg( &inst->SrcReg[2], src2 );   

      emit_dst( &inst->DstReg, dest, mask );

      debug_insn(inst, fn, line);
   }
}
void *
_slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize)
{
#if USE_MALLOC_FREE
   return _mesa_realloc(oldBuffer, oldSize, newSize);
#else
   GET_CURRENT_CONTEXT(ctx);
   slang_mempool *pool = (slang_mempool *) ctx->Shader.MemPool;

   if (newSize < oldSize) {
      return oldBuffer;
   }
   else {
      const GLuint copySize = (oldSize < newSize) ? oldSize : newSize;
      void *newBuffer = _slang_alloc(newSize);

      if (oldBuffer)
         ASSERT(is_valid_address(pool, oldBuffer));

      if (newBuffer && oldBuffer && copySize > 0)
         _mesa_memcpy(newBuffer, oldBuffer, copySize);

      return newBuffer;
   }
#endif
}
Beispiel #5
0
/**
 * Attach shader to a shader program.
 */
static void
attach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
{
   struct gl_shader_program *shProg;
   struct gl_shader *sh;
   GLuint i, n;

   const bool same_type_disallowed = _mesa_is_gles(ctx);

   shProg = _mesa_lookup_shader_program_err(ctx, program, "glAttachShader");
   if (!shProg)
      return;

   sh = _mesa_lookup_shader_err(ctx, shader, "glAttachShader");
   if (!sh) {
      return;
   }

   n = shProg->NumShaders;
   for (i = 0; i < n; i++) {
      if (shProg->Shaders[i] == sh) {
         /* The shader is already attched to this program.  The
          * GL_ARB_shader_objects spec says:
          *
          *     "The error INVALID_OPERATION is generated by AttachObjectARB
          *     if <obj> is already attached to <containerObj>."
          */
         _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader");
         return;
      } else if (same_type_disallowed &&
                 shProg->Shaders[i]->Type == sh->Type) {
        /* Shader with the same type is already attached to this program,
         * OpenGL ES 2.0 and 3.0 specs say:
         *
         *      "Multiple shader objects of the same type may not be attached
         *      to a single program object. [...] The error INVALID_OPERATION
         *      is generated if [...] another shader object of the same type
         *      as shader is already attached to program."
         */
         _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader");
         return;
      }
   }

   /* grow list */
   shProg->Shaders = (struct gl_shader **)
      _mesa_realloc(shProg->Shaders,
                    n * sizeof(struct gl_shader *),
                    (n + 1) * sizeof(struct gl_shader *));
   if (!shProg->Shaders) {
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
      return;
   }

   /* append */
   shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */
   _mesa_reference_shader(ctx, &shProg->Shaders[n], sh);
   shProg->NumShaders++;
}
Beispiel #6
0
static pp_symbol *
pp_symbols_push (pp_symbols *self)
{
   self->symbols = (pp_symbol *) (_mesa_realloc (self->symbols, self->count * sizeof (pp_symbol),
                                                 (self->count + 1) * sizeof (pp_symbol)));
   if (self->symbols == NULL)
      return NULL;
   pp_symbol_init (&self->symbols[self->count]);
   return &self->symbols[self->count++];
}
Beispiel #7
0
/**
 * Reallocate memory storing an array of program instructions.
 * This is used when we need to append additional instructions onto an
 * program.
 * \param oldInst  pointer to first of old/src instructions
 * \param numOldInst  number of instructions at <oldInst>
 * \param numNewInst  desired size of new instruction array.
 * \return  pointer to start of new instruction array.
 */
struct prog_instruction *
_mesa_realloc_instructions(struct prog_instruction *oldInst,
                           GLuint numOldInst, GLuint numNewInst)
{
   struct prog_instruction *newInst;

   newInst = (struct prog_instruction *)
      _mesa_realloc(oldInst,
                    numOldInst * sizeof(struct prog_instruction),
                    numNewInst * sizeof(struct prog_instruction));

   return newInst;
}
Beispiel #8
0
static GLboolean
pp_symbols_erase (pp_symbols *self, pp_symbol *symbol)
{
   assert (symbol >= self->symbols && symbol < self->symbols + self->count);

   self->count--;
   pp_symbol_free (symbol);
   if (symbol < self->symbols + self->count)
      _mesa_memcpy (symbol, symbol + 1, sizeof (pp_symbol) * (self->symbols + self->count - symbol));
   self->symbols = (pp_symbol *) (_mesa_realloc (self->symbols, (self->count + 1) * sizeof (pp_symbol),
                                                 self->count * sizeof (pp_symbol)));
   return self->symbols != NULL;
}
Beispiel #9
0
/**
 * Attach shader to a shader program.
 */
static void
attach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
{
   struct gl_shader_program *shProg;
   struct gl_shader *sh;
   GLuint i, n;

   shProg = _mesa_lookup_shader_program_err(ctx, program, "glAttachShader");
   if (!shProg)
      return;

   sh = _mesa_lookup_shader_err(ctx, shader, "glAttachShader");
   if (!sh) {
      return;
   }

   n = shProg->NumShaders;
   for (i = 0; i < n; i++) {
      if (shProg->Shaders[i] == sh) {
         /* The shader is already attched to this program.  The
          * GL_ARB_shader_objects spec says:
          *
          *     "The error INVALID_OPERATION is generated by AttachObjectARB
          *     if <obj> is already attached to <containerObj>."
          */
         _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader");
         return;
      }
   }

   /* grow list */
   shProg->Shaders = (struct gl_shader **)
      _mesa_realloc(shProg->Shaders,
                    n * sizeof(struct gl_shader *),
                    (n + 1) * sizeof(struct gl_shader *));
   if (!shProg->Shaders) {
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
      return;
   }

   /* append */
   shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */
   _mesa_reference_shader(ctx, &shProg->Shaders[n], sh);
   shProg->NumShaders++;
}
Beispiel #10
0
static GLboolean
grow (slang_string *self, GLuint size)
{
   if (self->fail)
      return GL_FALSE;
   if (size > self->capacity) {
      /* do not overflow 32-bit range */
      assert (size < 0x80000000);

      self->data = (char *) (_mesa_realloc (self->data, self->capacity, size * 2));
      self->capacity = size * 2;
      if (self->data == NULL) {
         self->capacity = 0;
         self->fail = GL_TRUE;
         return GL_FALSE;
      }
   }
   return GL_TRUE;
}
Beispiel #11
0
/**
 * Allocate space for and store data in a buffer object.  Any data that was
 * previously stored in the buffer object is lost.  If \c data is \c NULL,
 * memory will be allocated, but no copy will occur.
 *
 * This is the default callback for \c dd_function_table::BufferData()
 * Note that all GL error checking will have been done already.
 *
 * \param ctx     GL context.
 * \param target  Buffer object target on which to operate.
 * \param size    Size, in bytes, of the new data store.
 * \param data    Pointer to the data to store in the buffer object.  This
 *                pointer may be \c NULL.
 * \param usage   Hints about how the data will be used.
 * \param bufObj  Object to be used.
 *
 * \sa glBufferDataARB, dd_function_table::BufferData.
 */
static void
_mesa_buffer_data( GLcontext *ctx, GLenum target, GLsizeiptrARB size,
		   const GLvoid * data, GLenum usage,
		   struct gl_buffer_object * bufObj )
{
   void * new_data;

   (void) ctx; (void) target;

   new_data = _mesa_realloc( bufObj->Data, bufObj->Size, size );
   if (new_data) {
      bufObj->Data = (GLubyte *) new_data;
      bufObj->Size = size;
      bufObj->Usage = usage;

      if (data) {
	 _mesa_memcpy( bufObj->Data, data, size );
      }
   }
}
Beispiel #12
0
/**
 * Called via ctx->Driver.AttachShader()
 */
void
_mesa_attach_shader(GLcontext *ctx, GLuint program, GLuint shader)
{
   struct gl_shader_program *shProg
      = _mesa_lookup_shader_program(ctx, program);
   struct gl_shader *sh = _mesa_lookup_shader(ctx, shader);
   GLuint n;
   GLuint i;

   if (!shProg || !sh) {
      _mesa_error(ctx, GL_INVALID_VALUE,
                  "glAttachShader(bad program or shader name)");
      return;
   }

   n = shProg->NumShaders;

   for (i = 0; i < n; i++) {
      if (shProg->Shaders[i] == sh) {
         /* already attached */
         return;
      }
   }

   /* grow list */
   shProg->Shaders = (struct gl_shader **)
      _mesa_realloc(shProg->Shaders,
                    n * sizeof(struct gl_shader *),
                    (n + 1) * sizeof(struct gl_shader *));
   if (!shProg->Shaders) {
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
      return;
   }

   /* append */
   shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */
   _mesa_reference_shader(ctx, &shProg->Shaders[n], sh);
   shProg->NumShaders++;
}
Beispiel #13
0
/**
 * Add a new parameter to a parameter list.
 * Note that parameter values are usually 4-element GLfloat vectors.
 * When size > 4 we'll allocate a sequential block of parameters to
 * store all the values (in blocks of 4).
 *
 * \param paramList  the list to add the parameter to
 * \param type  type of parameter, such as 
 * \param name  the parameter name, will be duplicated/copied!
 * \param size  number of elements in 'values' vector (1..4, or more)
 * \param values  initial parameter value, up to 4 GLfloats, or NULL
 * \param state  state indexes, or NULL
 * \return  index of new parameter in the list, or -1 if error (out of mem)
 */
GLint
_mesa_add_parameter(struct gl_program_parameter_list *paramList,
                    enum register_file type, const char *name,
                    GLuint size, GLenum datatype, const GLfloat *values,
                    const gl_state_index state[STATE_LENGTH])
{
   const GLuint oldNum = paramList->NumParameters;
   const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */

   assert(size > 0);

   if (oldNum + sz4 > paramList->Size) {
      /* Need to grow the parameter list array (alloc some extra) */
      paramList->Size = paramList->Size + 4 * sz4;

      /* realloc arrays */
      paramList->Parameters = (struct gl_program_parameter *)
	 _mesa_realloc(paramList->Parameters,
		       oldNum * sizeof(struct gl_program_parameter),
		       paramList->Size * sizeof(struct gl_program_parameter));

      paramList->ParameterValues = (GLfloat (*)[4])
         _mesa_align_realloc(paramList->ParameterValues,         /* old buf */
                             oldNum * 4 * sizeof(GLfloat),      /* old size */
                             paramList->Size * 4 *sizeof(GLfloat), /* new sz */
                             16);
   }

   if (!paramList->Parameters ||
       !paramList->ParameterValues) {
      /* out of memory */
      paramList->NumParameters = 0;
      paramList->Size = 0;
      return -1;
   }
   else {
      GLuint i;

      paramList->NumParameters = oldNum + sz4;

      _mesa_memset(&paramList->Parameters[oldNum], 0, 
		   sz4 * sizeof(struct gl_program_parameter));

      for (i = 0; i < sz4; i++) {
         struct gl_program_parameter *p = paramList->Parameters + oldNum + i;
         p->Name = name ? _mesa_strdup(name) : NULL;
         p->Type = type;
         p->Size = size;
         p->DataType = datatype;
         if (values) {
            COPY_4V(paramList->ParameterValues[oldNum + i], values);
            values += 4;
         }
         else {
            /* silence valgrind */
            ASSIGN_4V(paramList->ParameterValues[oldNum + i], 0, 0, 0, 0);
         }
         size -= 4;
      }

      if (state) {
         for (i = 0; i < STATE_LENGTH; i++)
            paramList->Parameters[oldNum].StateIndexes[i] = state[i];
      }

      return (GLint) oldNum;
   }
}
Beispiel #14
0
void *slang_alloc_realloc (void *ptr, unsigned int old_size, unsigned int size)
{
	return _mesa_realloc (ptr, old_size, size);
}