Exemplo n.º 1
0
void ShaderManager::update_viewport()
{
    if (current_ == kInvalidProgram)
    {
        current_ = kDefaultProgram;
        const Shader::Details& details = get_program();
        glUseProgram(details.program);
        update_projection();
        glUniform1i(glGetUniformLocation(details.program, "texture"), 0);
        return;
    }
    update_projection();
}
Exemplo n.º 2
0
Camera::  Camera(const float fov,
                 const float aspectRatio,
                 const float near,
                 const float far,
                 const GLKVector3 &position,
                 const GLKVector3 &focus,
                 const GLKVector3 &up,
                 const GLKVector3 &lightDir,
                 const GLKVector4 &lightColor
                 ) :
fov_(fov),
aspectRatio_(aspectRatio),
near_(near),
far_(far),
position_(position),
focus_(focus),
up_(up),
lightDirection_(lightDir),
lightColor_(lightColor),
viewMatrix_(GLKMatrix4Identity),
projectionMatrix_(GLKMatrix4Identity)
{
  update_view();
  update_projection();
}
Exemplo n.º 3
0
void Renderer::reshape(int width, int height)
{
  // Prevent divide by zero
  width_ = std::max(width, 1);
  height_ = std::max(height, 1);
  update_projection();
}
Exemplo n.º 4
0
void ShaderManager::use(unsigned int program)
{
    if (program != current_)
    {
#ifndef USE_VERTEX_ARRAY_OBJECT
        const Shader::Details& current = get_program();
#endif  // !USE_VERTEX_ARRAY_OBJECT
        current_ = program;

        if (current_ == kInvalidProgram)
            return;

        const Shader::Details& details = get_program();
        glUseProgram(details.program);

        update_projection();

#ifndef USE_VERTEX_ARRAY_OBJECT
        if (details.texture0 != current.texture0)
        {
            if (!details.texture0)
                glDisableVertexAttribArray(Shader::kAttributeTexCoord);
            else
                glEnableVertexAttribArray(Shader::kAttributeTexCoord);
        }
#endif  // !USE_VERTEX_ARRAY_OBJECT
    }
}
Exemplo n.º 5
0
/**
 * Updates the combined modelview-projection matrix.
 *
 * \param ctx GL context.
 * \param new_state new state bit mask.
 *
 * If there is a new model view matrix then analyzes it. If there is a new
 * projection matrix, updates it. Finally calls
 * calculate_model_project_matrix() to recalculate the modelview-projection
 * matrix.
 */
void _mesa_update_modelview_project( struct gl_context *ctx, GLuint new_state )
{
    if (new_state & _NEW_MODELVIEW)
        _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );

    if (new_state & _NEW_PROJECTION)
        update_projection( ctx );

    /* Keep ModelviewProject up to date always to allow tnl
     * implementations that go model->clip even when eye is required.
     */
    calculate_model_project_matrix(ctx);
}
Exemplo n.º 6
0
void
SampledTaskPoint::update_oz(const TaskProjection &projection)
{
    m_search_max = m_search_reference;
    m_search_min = m_search_reference;
    m_boundary_points.clear();
    if (m_boundary_scored) {
        for (fixed t=fixed_zero; t<= fixed_one; t+= fixed_steps) {
            SearchPoint sp(get_boundary_parametric(t));
            m_boundary_points.push_back(sp);
        }
        prune_interior(m_boundary_points);
    } else {
        m_boundary_points.push_back(m_search_reference);
    }
    update_projection(projection);
}
Exemplo n.º 7
0
/**
 * Updates the combined modelview-projection matrix.
 *
 * \param ctx GL context.
 * \param new_state new state bit mask.
 *
 * If there is a new model view matrix then analyzes it. If there is a new
 * projection matrix, updates it. Finally calls
 * calculate_model_project_matrix() to recalculate the modelview-projection
 * matrix.
 */
void _mesa_update_modelview_project( GLcontext *ctx, GLuint new_state )
{
   if (new_state & _NEW_MODELVIEW) {
      _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
    
      /* Bring cull position uptodate.
       */
      TRANSFORM_POINT3( ctx->Transform.CullObjPos, 
			ctx->ModelviewMatrixStack.Top->inv,
			ctx->Transform.CullEyePos );
   }


   if (new_state & _NEW_PROJECTION)
      update_projection( ctx );

   /* Keep ModelviewProject uptodate always to allow tnl
    * implementations that go model->clip even when eye is required.
    */
   calculate_model_project_matrix(ctx);
}
Exemplo n.º 8
0
SdlManager::SdlManager(int w,int h,int d, float x, float y) : in_main_loop(false), width(w), height(h), old_ticks(0), x(x), y(y) {
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER|SDL_OPENGL)) throw Except(Except::ZIZI_INIT_ERR,"cannot initialize sdl");

    screen=SDL_SetVideoMode(width,height,d,SDL_OPENGL|SDL_DOUBLEBUF);
    if (not screen) throw Except(Except::ZIZI_INIT_ERR,"cannot create sdl screen");

    SDL_SetEventFilter(&event_filter);
    SDL_ShowCursor(false);

    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glClearColor(0,0,0,0);
    glEnable(GL_DEPTH_TEST);// Enables Depth Testing
    glDepthFunc(GL_LEQUAL);// The Type Of Depth Testing To Do
    glEnable(GL_BLEND);//Alpha blending
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Really Nice Perspective Calculations
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER,0.05);

    update_projection();
}
Exemplo n.º 9
0
void SdlManager::set_screen_center(float cx,float cy) {
    const_cast<float&>(x) = cx-width/2.;
    const_cast<float&>(y) = cy-height/2.;
    update_projection();
}
Exemplo n.º 10
0
void Camera::SetFar(const float far)
{
  far_ = far;
  update_projection();
}
Exemplo n.º 11
0
void Camera::SetNear(const float near)
{
  near_ = near;
  update_projection();
}
Exemplo n.º 12
0
void Camera::SetAspectRatio(const float aspectRatio)
{
  aspectRatio_ = aspectRatio;
  update_projection();
}
Exemplo n.º 13
0
void Camera::SetFOV(const float fov)
{
  fov_ = fov;
  update_projection();
}
Exemplo n.º 14
0
/*
 * If ctx->NewState is non-zero then this function MUST be called before
 * rendering any primitive.  Basically, function pointers and miscellaneous
 * flags are updated to reflect the current state of the state machine.
 *
 * The above constraint is now maintained largely by the two Exec
 * dispatch tables, which trigger the appropriate flush on transition
 * between State and Geometry modes.
 *
 * Special care is taken with the derived value _NeedEyeCoords.  This
 * is a bitflag which is updated with information from a number of
 * attribute groups (MODELVIEW, LIGHT, TEXTURE).  A lot of derived
 * state references this value, and must be treated with care to
 * ensure that updates are done correctly.  All state dependent on
 * _NeedEyeCoords is calculated from within _mesa_update_tnl_spaces(),
 * and from nowhere else.
 */
void _mesa_update_state( GLcontext *ctx )
{
   const GLuint new_state = ctx->NewState;
   const GLuint oldneedeyecoords = ctx->_NeedEyeCoords;

   if (MESA_VERBOSE & VERBOSE_STATE)
      _mesa_print_state("_mesa_update_state", new_state);

   if (new_state & _NEW_MODELVIEW)
      _math_matrix_analyse( &ctx->ModelView );

   if (new_state & _NEW_PROJECTION)
      update_projection( ctx );

   if (new_state & _NEW_TEXTURE_MATRIX)
      update_texture_matrices( ctx );

   if (new_state & _NEW_COLOR_MATRIX)
      _math_matrix_analyse( &ctx->ColorMatrix );

   /* References ColorMatrix.type (derived above).
    */
   if (new_state & _IMAGE_NEW_TRANSFER_STATE)
      update_image_transfer_state(ctx);

   /* Contributes to NeedEyeCoords, NeedNormals.
    */
   if (new_state & _NEW_TEXTURE)
      update_texture_state( ctx );

   if (new_state & (_NEW_BUFFERS|_NEW_SCISSOR))
      update_drawbuffer( ctx );

   if (new_state & _NEW_POLYGON)
      update_polygon( ctx );

   /* Contributes to NeedEyeCoords, NeedNormals.
    */
   if (new_state & _NEW_LIGHT)
      _mesa_update_lighting( ctx );

   /* We can light in object space if the modelview matrix preserves
    * lengths and relative angles.
    */
   if (new_state & (_NEW_MODELVIEW|_NEW_LIGHT)) {
      ctx->_NeedEyeCoords &= ~NEED_EYE_LIGHT_MODELVIEW;
      if (ctx->Light.Enabled &&
	  !TEST_MAT_FLAGS( &ctx->ModelView, MAT_FLAGS_LENGTH_PRESERVING))
	    ctx->_NeedEyeCoords |= NEED_EYE_LIGHT_MODELVIEW;
   }

   /* Keep ModelviewProject uptodate always to allow tnl
    * implementations that go model->clip even when eye is required.
    */
   if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
      calculate_model_project_matrix(ctx);


   /* ctx->_NeedEyeCoords is now uptodate.
    *
    * If the truth value of this variable has changed, update for the
    * new lighting space and recompute the positions of lights and the
    * normal transform.
    *
    * If the lighting space hasn't changed, may still need to recompute
    * light positions & normal transforms for other reasons.
    */
   if (new_state & (_NEW_MODELVIEW |
		    _NEW_LIGHT |
		    _MESA_NEW_NEED_EYE_COORDS))
      update_tnl_spaces( ctx, oldneedeyecoords );

   /*
    * Here the driver sets up all the ctx->Driver function pointers
    * to it's specific, private functions, and performs any
    * internal state management necessary, including invalidating
    * state of active modules.
    *
    * Set ctx->NewState to zero to avoid recursion if
    * Driver.UpdateState() has to call FLUSH_VERTICES().  (fixed?)
    */
   ctx->NewState = 0;
   ctx->Driver.UpdateState(ctx, new_state);
   ctx->Array.NewState = 0;

   /* At this point we can do some assertions to be sure the required
    * device driver function pointers are all initialized.
    */
   ASSERT(ctx->Driver.GetString);
   ASSERT(ctx->Driver.UpdateState);
   ASSERT(ctx->Driver.Clear);
   ASSERT(ctx->Driver.SetDrawBuffer);
   ASSERT(ctx->Driver.GetBufferSize);
   if (ctx->Visual.accumRedBits > 0) {
      ASSERT(ctx->Driver.Accum);
   }
   ASSERT(ctx->Driver.DrawPixels);
   ASSERT(ctx->Driver.ReadPixels);
   ASSERT(ctx->Driver.CopyPixels);
   ASSERT(ctx->Driver.Bitmap);
   ASSERT(ctx->Driver.ResizeBuffers);
   ASSERT(ctx->Driver.TexImage1D);
   ASSERT(ctx->Driver.TexImage2D);
   ASSERT(ctx->Driver.TexImage3D);
   ASSERT(ctx->Driver.TexSubImage1D);
   ASSERT(ctx->Driver.TexSubImage2D);
   ASSERT(ctx->Driver.TexSubImage3D);
   ASSERT(ctx->Driver.CopyTexImage1D);
   ASSERT(ctx->Driver.CopyTexImage2D);
   ASSERT(ctx->Driver.CopyTexSubImage1D);
   ASSERT(ctx->Driver.CopyTexSubImage2D);
   ASSERT(ctx->Driver.CopyTexSubImage3D);
   if (ctx->Extensions.ARB_texture_compression) {
      ASSERT(ctx->Driver.BaseCompressedTexFormat);
      ASSERT(ctx->Driver.CompressedTextureSize);
      ASSERT(ctx->Driver.GetCompressedTexImage);
#if 0  /* HW drivers need these, but not SW rasterizers */
      ASSERT(ctx->Driver.CompressedTexImage1D);
      ASSERT(ctx->Driver.CompressedTexImage2D);
      ASSERT(ctx->Driver.CompressedTexImage3D);
      ASSERT(ctx->Driver.CompressedTexSubImage1D);
      ASSERT(ctx->Driver.CompressedTexSubImage2D);
      ASSERT(ctx->Driver.CompressedTexSubImage3D);
#endif
   }
}