GteGL4Resource.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
11 using namespace gte;
12 
14  :
15  GL4GraphicsObject(gtResource)
16 {
17 }
18 
20 {
21  glBindBuffer(target, mGLHandle);
22  GLvoid* mapped = glMapBuffer(target, GL_WRITE_ONLY);
23  glBindBuffer(target, 0);
24  return mapped;
25 }
26 
28 {
29  glBindBuffer(target, mGLHandle);
30  glUnmapBuffer(target);
31  glBindBuffer(target, 0);
32 }
33 
35 {
36  // TODO: DX11 requires a staging resource when copying between CPU and
37  // GPU. Does OpenGL hide the double hop?
38 
39  // Verify existence of objects.
40  if (mGLHandle == 0)
41  {
42  LogError("Resource does not exist.");
43  return false;
44  }
45 
46  // Verify the copy type. TODO: Change the Resource::CopyType names to
47  // be COPY_CPU_TO_GPU and COPY_GPU_TO_CPU.
48  Resource::CopyType copyType = GetResource()->GetCopyType();
49  if (copyType == Resource::COPY_CPU_TO_STAGING) // CPU -> GPU
50  {
51  if (access == GL_WRITE_ONLY)
52  {
53  return true;
54  }
55  }
56  else if (copyType == Resource::COPY_STAGING_TO_CPU) // GPU -> CPU
57  {
58  if (access == GL_READ_ONLY)
59  {
60  return true;
61  }
62  }
63  else if (copyType == Resource::COPY_BIDIRECTIONAL)
64  {
65  if (access == GL_READ_WRITE)
66  {
67  return true;
68  }
69  if (access == GL_WRITE_ONLY)
70  {
71  return true;
72  }
73  if (access == GL_READ_ONLY)
74  {
75  return true;
76  }
77  }
78 
79  LogError("Resource has incorrect copy type.");
80  return false;
81 }
GL4Resource(Resource const *gtResource)
COPY_STAGING_TO_CPU
Definition: GteResource.h:55
void *APIENTRY glMapBuffer(GLenum target, GLenum access)
Definition: GteOpenGL.cpp:1628
bool PreparedForCopy(GLenum access) const
GLenum target
Definition: glcorearb.h:1662
void GLvoid
Definition: glcorearb.h:82
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2217
void Unmap(GLenum target)
unsigned int GLenum
Definition: glcorearb.h:83
#define LogError(message)
Definition: GteLogger.h:92
void * MapForWrite(GLenum target)
void APIENTRY glBindBuffer(GLenum target, GLuint buffer)
Definition: GteOpenGL.cpp:1534
Resource * GetResource() const
COPY_CPU_TO_STAGING
Definition: GteResource.h:55
#define GL_READ_ONLY
Definition: glcorearb.h:630
CopyType GetCopyType() const
Definition: GteResource.h:136
#define GL_READ_WRITE
Definition: glcorearb.h:632
GLboolean APIENTRY glUnmapBuffer(GLenum target)
Definition: GteOpenGL.cpp:1644
#define GL_WRITE_ONLY
Definition: glcorearb.h:631


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00