6#ifndef WUT_COLOR_SHADER_H_
7#define WUT_COLOR_SHADER_H_
9#include "VertexShader.h"
10#include "PixelShader.h"
11#include "FetchShader.h"
12#include <gx2r/buffer.h>
14#include <gx2r/resource.h>
19class ColorShader :
public Shader
23 virtual ~ColorShader();
25 static const uint32_t cuAttributeCount = 2;
28 static ColorShader * shaderInstance;
41 static const uint32_t cuMaxColorDraws = 512;
42 GX2RBuffer colorBuffer;
45 uint32_t angleLocation;
46 uint32_t offsetLocation;
47 uint32_t scaleLocation;
48 uint32_t colorLocation;
49 uint32_t colorIntensityLocation;
50 uint32_t positionLocation;
60 shaderInstance =
new ColorShader();
61 return shaderInstance;
67 delete shaderInstance;
68 shaderInstance =
nullptr;
74 fetchShader->setShader();
75 vertexShader.setShader();
76 pixelShader.setShader();
107 uint32_t slot = colorSlot;
108 if(colorSlot < cuMaxColorDraws - 1)
111 if(GX2RBufferExists(&colorBuffer))
113 uint8_t * dst =
static_cast<uint8_t *
>(GX2RLockBufferEx(&colorBuffer, GX2R_RESOURCE_USAGE_CPU_WRITE));
117 GX2RUnlockBufferEx(&colorBuffer, GX2R_RESOURCE_USAGE_CPU_WRITE);
133 void bindMesh(
const float * positions,
const uint8_t * colors, uint32_t vertexCapacity,
const float * offset =
nullptr,
const float * scale =
nullptr)
135 static const float zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
136 static const float one[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
149 static void drawMesh(uint32_t firstVertex, uint32_t vertexCount)
151 GX2DrawEx(GX2_PRIMITIVE_MODE_TRIANGLES, vertexCount, firstVertex, 1);
void setOffset(const float offset[3])
Sets the NDC position of the quad's center.
void resetFrame()
Call once per frame, before any draws - rewinds the per-draw color slot counter so this frame starts ...
static void destroyInstance()
Destroys the shared instance; the next instance() call creates a new one.
void bindMesh(const float *positions, const uint8_t *colors, uint32_t vertexCapacity, const float *offset=nullptr, const float *scale=nullptr)
Binds caller-owned vertex streams for mesh draws and sets the uniforms so vertices pass through uncha...
void setColorIntensity(const float colorIntensity[4])
Sets the RGBA color the quad is filled with.
void setAttributeBuffer(const uint8_t *colorAttr)
static void drawMesh(uint32_t firstVertex, uint32_t vertexCount)
Draws triangles from the streams bound with bindMesh().
void setShaders() const
Binds the fetch, vertex and pixel shaders for subsequent draws.
void setAngle(float angleRadians)
Sets the quad rotation in radians.
static const uint32_t cuColorVtxsSize
Size in bytes of the four per-vertex colors of one quad.
void setScale(const float scale[3])
Sets the NDC half-extents of the quad.
static ColorShader * instance()
Owns the GX2 fetch shader program that binds vertex attribute streams to a vertex shader.
Owns a GX2PixelShader's compiled program and uniform/sampler metadata, mirroring VertexShader's role ...
static void setUniformReg(uint32_t location, uint32_t size, const void *reg)
Writes uniform registers for the bound pixel shader.
static const uint16_t cuVertexAttrSize
Size in bytes of one position vertex (3 floats)
static const uint16_t cuColorAttrSize
Size in bytes of one vertex color (4 bytes, RGBA)
Owns a GX2VertexShader's compiled program and uniform/attribute metadata.
static void setUniformReg(uint32_t location, uint32_t size, const void *reg)
Writes uniform registers for the bound vertex shader.
static void setAttributeBuffer(uint32_t bufferIdx, uint32_t bufferSize, uint32_t stride, const void *buffer)
Binds a vertex data buffer to an attribute buffer slot.