GrGeometryBuffer.h revision ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976e
18fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc.
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */
827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
1027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#ifndef GrGeometryBuffer_DEFINED
1127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#define GrGeometryBuffer_DEFINED
1227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com
138fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com#include "GrResource.h"
148fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
158fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.comclass GrGpu;
1627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com
1727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com/**
1827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com * Parent class for vertex and index buffers
1927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com */
208fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.comclass GrGeometryBuffer : public GrResource {
2127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.compublic:
228fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
2327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    /**
2427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     *Retrieves whether the buffer was created with the dynamic flag
2527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     *
2627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * @return true if the buffer was created with the dynamic flag
2727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
2827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    bool dynamic() const { return fDynamic; }
298fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
3027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    /**
3127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * Locks the buffer to be written by the CPU.
328fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
3327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * The previous content of the buffer is invalidated. It is an error
3427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * to draw from the buffer while it is locked. It is an error to call lock
3527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * on an already locked buffer.
368fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
3727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * @return a pointer to the data or NULL if the lock fails.
3827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
3927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    virtual void* lock() = 0;
408fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
4127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    /**
4227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * Returns the same ptr that lock() returned at time of lock or NULL if the
4327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * is not locked.
4427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     *
4527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * @return ptr to locked buffer data or undefined if buffer is not locked.
4627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
4727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    virtual void* lockPtr() const = 0;
488fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
498fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com    /**
508fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     * Unlocks the buffer.
518fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
5227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * The pointer returned by the previous lock call will no longer be valid.
5327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
5427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    virtual void unlock() = 0;
558fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
568fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com    /**
5727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     Queries whether the buffer has been locked.
588fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
5927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     @return true if the buffer is locked, false otherwise.
6027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
6127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    virtual bool isLocked() const = 0;
628fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
6327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    /**
648fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     * Updates the buffer data.
658fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
668fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     * The size of the buffer will be preserved. The src data will be
6727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * placed at the begining of the buffer and any remaining contents will
6827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * be undefined.
698fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
7027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * @return returns true if the update succeeds, false otherwise.
7127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
7227847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
738fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com
7427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    /**
758fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     * Updates a portion of the buffer data.
768fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
7727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * The contents of the buffer outside the update region are preserved.
788fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com     *
7927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     * @return returns true if the update succeeds, false otherwise.
8027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com     */
818fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com    virtual bool updateSubData(const void* src,
828fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com                               size_t srcSizeInBytes,
8327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com                               size_t offset) = 0;
84cee661af926cc977addc6e039b7022975a448acebsalomon@google.com
85cee661af926cc977addc6e039b7022975a448acebsalomon@google.com    // GrResource overrides
86cee661af926cc977addc6e039b7022975a448acebsalomon@google.com    virtual size_t sizeInBytes() const { return fSizeInBytes; }
87cee661af926cc977addc6e039b7022975a448acebsalomon@google.com
8827847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comprotected:
898fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com    GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
908fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com        : INHERITED(gpu)
918fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com        , fSizeInBytes(sizeInBytes)
928fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com        , fDynamic(dynamic) {}
9327847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com
9427847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.comprivate:
9527847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    size_t   fSizeInBytes;
9627847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com    bool     fDynamic;
9727847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com
988fe72477f204b1a45393e6a64caa84fd287b805bbsalomon@google.com    typedef GrResource INHERITED;
9927847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com};
10027847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com
10127847dedd9b5c1f48998c40842f3494c0746257fbsalomon@google.com#endif
102