1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_SERVICE_MULTI_DRAW_MANAGER_H_
#define GPU_COMMAND_BUFFER_SERVICE_MULTI_DRAW_MANAGER_H_
#include <vector>
#include "gpu/gpu_gles2_export.h"
// Forwardly declare a few GL types to avoid including GL header files.
typedef unsigned GLenum;
typedef int GLsizei;
typedef int GLint;
typedef unsigned int GLuint;
namespace gpu {
namespace gles2 {
class GPU_GLES2_EXPORT MultiDrawManager {
public:
enum class DrawFunction {
DrawArrays,
DrawArraysInstanced,
DrawArraysInstancedBaseInstance,
DrawElements,
DrawElementsInstanced,
DrawElementsInstancedBaseVertexBaseInstance,
};
struct GPU_GLES2_EXPORT ResultData {
DrawFunction draw_function;
GLsizei drawcount = 0;
GLenum mode = 0;
GLenum type = 0;
std::vector<GLint> firsts;
std::vector<GLsizei> counts;
std::vector<GLsizei> offsets;
std::vector<const void*> indices;
std::vector<GLsizei> instance_counts;
std::vector<GLint> basevertices;
std::vector<GLuint> baseinstances;
ResultData();
~ResultData();
ResultData(ResultData&& rhs);
ResultData& operator=(ResultData&& rhs);
};
enum class IndexStorageType {
Offset,
Pointer,
};
MultiDrawManager(IndexStorageType index_type);
bool Begin(GLsizei drawcount);
bool End(ResultData* result);
bool MultiDrawArrays(GLenum mode,
const GLint* firsts,
const GLsizei* counts,
GLsizei drawcount);
bool MultiDrawArraysInstanced(GLenum mode,
const GLint* firsts,
const GLsizei* counts,
const GLsizei* instance_counts,
GLsizei drawcount);
bool MultiDrawArraysInstancedBaseInstance(GLenum mode,
const GLint* firsts,
const GLsizei* counts,
const GLsizei* instance_counts,
const GLuint* baseinstances,
GLsizei drawcount);
bool MultiDrawElements(GLenum mode,
const GLsizei* counts,
GLenum type,
const GLsizei* offsets,
GLsizei drawcount);
bool MultiDrawElementsInstanced(GLenum mode,
const GLsizei* counts,
GLenum type,
const GLsizei* offsets,
const GLsizei* instance_counts,
GLsizei drawcount);
bool MultiDrawElementsInstancedBaseVertexBaseInstance(
GLenum mode,
const GLsizei* counts,
GLenum type,
const GLsizei* offsets,
const GLsizei* instance_counts,
const GLint* basevertices,
const GLuint* baseinstances,
GLsizei drawcount);
private:
void ResizeArrays();
bool ValidateDrawcount(GLsizei drawcount) const;
bool EnsureDrawArraysFunction(DrawFunction draw_function,
GLenum mode,
GLsizei drawcount);
bool EnsureDrawElementsFunction(DrawFunction draw_function,
GLenum mode,
GLenum type,
GLsizei drawcount);
void CopyArraysHelper(GLsizei drawcount,
const GLint* firsts,
const GLsizei* counts,
const GLsizei* offsets,
const GLsizei* instance_counts,
const GLint* basevertices,
const GLuint* baseinstances);
enum class DrawState {
Begin,
Draw,
End,
};
DrawState draw_state_;
GLsizei current_draw_offset_;
IndexStorageType index_type_;
ResultData result_;
};
} // namespace gles2
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_MULTI_DRAW_MANAGER_H_
|