Beispiel #1
0
	void LightManager::RenderLights()
	{
		LightPtr pLight = GetNextAffectingLight(LightPtr(), ViewFrustum());
		while(pLight)
		{
			if(pLight->GetEnabled())
			{
				pLight->RenderLight(m_pRenderSystem);
			}
			pLight = GetNextAffectingLight(pLight, ViewFrustum());
		}
	}
Beispiel #2
0
void Camera::defaults()
{
	setRenderable( false );

	m_x								= 0;
	m_y								= 0;
	m_width							= 0;
	m_height						= 0;
	m_viewFrustum					= ViewFrustum();
	m_cachedWidthProjectionScalar	= 0.f;
	m_worldToCamera					= Matrix4x4(0);
	m_view							= Matrix4x4(0);
	m_projection					= Matrix4x4(0);
	m_viewProjection				= Matrix4x4(0);
	m_aspect						= 4.f/3.f;

	resetStatistics();
}
Beispiel #3
0
/*virtual*/ void D3D9Renderer::RenderBucket(
    Bucket* pBucket, const ViewportPass* const pViewportPass) {
  XTRACE_FUNCTION;

  PROFILE_FUNCTION;

  if (pBucket->m_RenderTarget) {
    SetRenderTarget(pBucket->m_RenderTarget);

    if (pViewportPass) {
      SetViewport(pViewportPass);
    }
  }

  if (pBucket->m_ClearFlags != CLEAR_NONE) {
    Clear(pBucket->m_ClearFlags, pBucket->m_ClearColor, pBucket->m_ClearDepth);
  }

  if (pBucket->m_View) {
    View* const pView = pViewportPass ? pViewportPass->GetView(pBucket->m_View)
                                      : pBucket->m_View;
    m_View = *pView;
    m_View.ApplyToRenderer(*this);
  }

  if (pBucket->m_Flags & MAT_ALPHA) {
    pBucket->Sort(m_View);
  } else if (m_DoMaterialSort && pBucket->m_SortByMaterial) {
    pBucket->SortByMaterials();
  }

  Mesh* pMesh = NULL;
  D3D9VertexBuffer* VertexBuffer = NULL;
  D3D9IndexBuffer* IndexBuffer = NULL;
  IVertexDeclaration* pVertexDeclaration = NULL;
  uint NumMeshes = pBucket->m_Meshes.Size();
  Frustum ViewFrustum(GetViewMatrix() * GetProjectionMatrix());

#if BUILD_DEBUG
  if (pBucket->m_DEBUGUseFrustum) {
    pBucket->m_DEBUGFrustumView.ApplyToFrustum(ViewFrustum);
  }
#endif

  for (uint MeshIndex = 0; MeshIndex < NumMeshes; ++MeshIndex) {
    XTRACE_NAMED(RenderBucketMesh);

    pMesh = pBucket->m_Meshes[MeshIndex];
    DEVASSERT(pMesh);

    DEVASSERT(pMesh->m_VertexBuffer->GetNumVertices() > 0);

    const uint MaterialFlags = pMesh->GetMaterialFlags();

    // Frustum culling--I can't do this earlier, when a mesh is added, because
    // it might be visible in one view (e.g., shadow map depth) and not to
    // player.
    if (!m_DoFrustumCulling || pBucket->m_Flags & MAT_HUD ||
        pBucket->m_Flags & MAT_INWORLDHUD ||
#if BUILD_DEV
        pBucket->m_Flags & MAT_DEBUG_ALWAYS ||
        MaterialFlags & MAT_DEBUG_ALWAYS ||
#endif
        pBucket->m_Flags & MAT_ALWAYS || MaterialFlags & MAT_ALWAYS ||
        ViewFrustum.Intersects(pMesh->m_AABB)) {
      VertexBuffer = (D3D9VertexBuffer*)pMesh->m_VertexBuffer;
      IndexBuffer = (D3D9IndexBuffer*)pMesh->m_IndexBuffer;
      // RENDERTODO: It might be useful to adapt this for material overrides in
      // the future
      // Shader			= (D3D9Shader*)( pBucket->m_OverrideShader ?
      // pBucket->m_OverrideShader : pMesh->m_OLDMaterial.m_Shader );

      if (pMesh->m_VertexDeclaration != pVertexDeclaration) {
        XTRACE_NAMED(SetVertexDeclaration);
        m_D3DDevice->SetVertexDeclaration(
            (IDirect3DVertexDeclaration9*)
            pMesh->m_VertexDeclaration->GetDeclaration());
      }
      pVertexDeclaration = pMesh->m_VertexDeclaration;

      DEVASSERT(VertexBuffer);
      DEVASSERT(pVertexDeclaration);
      DEVASSERT(IndexBuffer);

      SetWorldMatrix(pMesh->GetConcatenatedTransforms());

      {
        XTRACE_NAMED(SetStreams);

        uint VertexSignature = pVertexDeclaration->GetSignature();
        uint Index = 0;
#define SETSTREAM(STREAM, SIGNATURE, TYPE)                                 \
  if (SIGNATURE == (VertexSignature & SIGNATURE)) {                        \
    IDirect3DVertexBuffer9* const pBuffer =                                \
        static_cast<IDirect3DVertexBuffer9*>(VertexBuffer->Get##STREAM()); \
    DEVASSERT(pBuffer);                                                    \
    m_D3DDevice->SetStreamSource(Index++, pBuffer, 0, sizeof(TYPE));       \
  }

        SETSTREAM(Positions, VD_POSITIONS, Vector);
        SETSTREAM(Colors, VD_COLORS, uint);
#if USE_HDR
        SETSTREAM(FloatColors1, VD_FLOATCOLORS, Vector4);
        SETSTREAM(FloatColors2, VD_BASISCOLORS, Vector4);
        SETSTREAM(FloatColors3, VD_BASISCOLORS, Vector4);

        // For SM2 cards, an alternative way to do HDR colors
        SETSTREAM(FloatColors1, VD_FLOATCOLORS_SM2, Vector4);
        SETSTREAM(FloatColors2, VD_BASISCOLORS_SM2, Vector4);
        SETSTREAM(FloatColors3, VD_BASISCOLORS_SM2, Vector4);
#endif
        SETSTREAM(UVs, VD_UVS, Vector2);
        SETSTREAM(Normals, VD_NORMALS, Vector);
        SETSTREAM(Tangents, VD_TANGENTS, Vector4);
        SETSTREAM(BoneIndices, VD_BONEINDICES, SBoneData);
        SETSTREAM(BoneWeights, VD_BONEWEIGHTS, SBoneData);

#undef SETSTREAM

        m_D3DDevice->SetIndices(
            (IDirect3DIndexBuffer9*)IndexBuffer->GetIndices());
      }

      ApplyMaterial(pMesh->m_Material, pMesh, m_View);

      if (VertexBuffer->GetNumVertices() > 0) {
        XTRACE_NAMED(DrawIndexedPrimitive);

        m_D3DDevice->DrawIndexedPrimitive(IndexBuffer->GetPrimitiveType(), 0, 0,
                                          VertexBuffer->GetNumVertices(), 0,
                                          IndexBuffer->GetNumPrimitives());
      }

#if BUILD_DEBUG
      ++m_DEBUGRenderStats.NumMeshes;
      m_DEBUGRenderStats.NumPrimitives += IndexBuffer->GetNumPrimitives();
#endif
    }

#if BUILD_DEV
    // WARNING: This assumes the mesh is only in one bucket, which could be bad
    if (pMesh->m_IsDebugMesh) {
      m_DeferredDeleteDebugMeshes.PushBackUnique(pMesh);
    }
#endif
  }
}