コード例 #1
0
ファイル: RenderBuffer.cpp プロジェクト: truongascii/Wendy
bool IndexBuffer::init(size_t count, IndexBufferType type, BufferUsage usage)
{
  m_type = type;
  m_usage = usage;
  m_count = count;

  glGenBuffers(1, &m_bufferID);

  m_context.setCurrentIndexBuffer(this);

  glBufferData(GL_ELEMENT_ARRAY_BUFFER,
               m_count * typeSize(m_type),
               nullptr,
               convertToGL(m_usage));

  if (!checkGL("Error during creation of index buffer of element size %u",
               (uint) typeSize(m_type)))
  {
    m_context.setCurrentIndexBuffer(nullptr);
    return false;
  }

  if (RenderStats* stats = m_context.stats())
    stats->addIndexBuffer(size());

  return true;
}
コード例 #2
0
ファイル: RenderBuffer.cpp プロジェクト: truongascii/Wendy
bool VertexBuffer::init(const VertexFormat& format, size_t count, BufferUsage usage)
{
  m_format = format;
  m_usage = usage;
  m_count = count;

  glGenBuffers(1, &m_bufferID);

  m_context.setCurrentVertexBuffer(this);

  glBufferData(GL_ARRAY_BUFFER,
               m_count * m_format.size(),
               nullptr,
               convertToGL(m_usage));

  if (!checkGL("Error during creation of vertex buffer of format %s",
               m_format.asString().c_str()))
  {
    m_context.setCurrentVertexBuffer(nullptr);
    return false;
  }

  if (RenderStats* stats = m_context.stats())
    stats->addVertexBuffer(size());

  return true;
}
コード例 #3
0
void AccelerometerTest::onAcceleration(Acceleration* acc, Event* event)
{
//     double fNow = pAccelerationValue->timestamp;
// 
//     if (_lastTime > 0.0)
//     {
//         auto ptNow = convertToUI
//     }
// 
//     _lastTime = fNow;

    auto pDir = Director::getInstance();

    /*FIXME: Testing on the Nexus S sometimes _ball is NULL */
    if ( _ball == NULL ) {
        return;
    }

    auto ballSize  = _ball->getContentSize();

    auto ptNow  = _ball->getPosition();
    auto ptTemp = pDir->convertToUI(ptNow);

    ptTemp.x += acc->x * 9.81f;
    ptTemp.y -= acc->y * 9.81f;

    auto ptNext = pDir->convertToGL(ptTemp);
    FIX_POS(ptNext.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0));
    FIX_POS(ptNext.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0));
    _ball->setPosition(ptNext);
}
コード例 #4
0
ファイル: RenderBuffer.cpp プロジェクト: truongascii/Wendy
void VertexBuffer::discard()
{
  m_context.setCurrentVertexBuffer(this);

  glBufferData(GL_ARRAY_BUFFER,
               m_count * m_format.size(),
               nullptr,
               convertToGL(m_usage));

#if WENDY_DEBUG
  checkGL("Error during vertex buffer discard");
#endif
}
コード例 #5
0
ファイル: RenderBuffer.cpp プロジェクト: truongascii/Wendy
bool TextureFramebuffer::setBuffer(Attachment attachment, Texture* newTexture,
                                   const TextureImage& image, uint z)
{
  if (isColorAttachment(attachment))
  {
    const RenderLimits& limits = m_context.limits();
    const uint index = attachment - COLOR_BUFFER0;

    if (index >= limits.maxColorAttachments)
    {
      logError("OpenGL context supports at most %u FBO color attachments",
               limits.maxColorAttachments);
      return false;
    }

    if (index >= limits.maxDrawBuffers)
    {
      logError("OpenGL context supports at most %u draw buffers",
               limits.maxDrawBuffers);
      return false;
    }
  }

  Framebuffer& previous = m_context.currentFramebuffer();
  apply();

  if (m_textures[attachment])
    m_textures[attachment]->detach(convertToGL(attachment));

  m_textures[attachment] = newTexture;

  if (m_textures[attachment])
    m_textures[attachment]->attach(convertToGL(attachment), image, z);

  previous.apply();
  return true;
}
コード例 #6
0
ファイル: UtilityFunctions.cpp プロジェクト: mjcaley/Pong
bool ClickedMe(const EventMouse* event, const Node *node)
{
    auto rect = node->getBoundingBox();
    Vec2 click;
    if (std::string(cocos2dVersion()) == "cocos2d-x 3.5")
    {
        // Maybe a bug in cocos2d-x 3.4 - https://github.com/cocos2d/cocos2d-x/issues/8536
        auto dir = Director::getInstance();
        click = dir->convertToGL(Vec2(
                                      event->getLocation().x,
                                      event->getLocation().y - Director::getInstance()->getVisibleSize().height)
                                 );
    }
    else
    {
        click = event->getLocation();
    }
    
    return rect.containsPoint(click);
}
コード例 #7
0
ファイル: RenderBuffer.cpp プロジェクト: truongascii/Wendy
void TextureFramebuffer::apply() const
{
  glBindFramebuffer(GL_FRAMEBUFFER, m_bufferID);

  GLenum enables[5];
  GLsizei count = 0;

  for (size_t i = 0;  i < sizeof(enables) / sizeof(enables[0]);  i++)
  {
    Attachment attachment = (Attachment) i;

    if (m_textures[i] && isColorAttachment(attachment))
      enables[count++] = convertToGL(attachment);
  }

  if (count)
    glDrawBuffers(count, enables);
  else
    glDrawBuffer(GL_NONE);

#if WENDY_DEBUG
  checkGL("Error when applying image framebuffer");
#endif
}
コード例 #8
0
ファイル: HelloWorldScene.cpp プロジェクト: wt0317/TraceEm
inline Point locationInGLFromTouch(Touch& touch)
{
	auto director = Director::getInstance();
	return director->convertToGL(touch.getLocationInView());
}