6#ifndef WUT_TEXTURE_2D_SHADER_H_
7#define WUT_TEXTURE_2D_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 Texture2DShader :
public Shader
23 virtual ~Texture2DShader();
25 static const uint32_t cuAttributeCount = 2;
29 static Texture2DShader * shaderInstance;
46 static const uint32_t cuMaxRotatedDraws = 64;
47 static const uint32_t cuRotatedSlotSize = GX2_VERTEX_BUFFER_ALIGNMENT;
48 static_assert(4 *
cuVertexAttrSize <= cuRotatedSlotSize,
"rotated quad must fit in one slot");
49 GX2RBuffer rotatedBuffer;
52 uint32_t angleLocation;
53 uint32_t offsetLocation;
54 uint32_t scaleLocation;
55 uint32_t colorIntensityLocation;
56 uint32_t blurLocation;
57 uint32_t samplerLocation;
58 uint32_t positionLocation;
59 uint32_t texCoordLocation;
66 shaderInstance =
new Texture2DShader();
67 return shaderInstance;
73 delete shaderInstance;
74 shaderInstance =
nullptr;
80 fetchShader->setShader();
81 vertexShader.setShader();
82 pixelShader.setShader();
107 if(!GX2RBufferExists(&rotatedBuffer) || rotatedSlot >= cuMaxRotatedDraws)
110 float * dst =
static_cast<float *
>(GX2RLockBufferEx(&rotatedBuffer, GX2R_RESOURCE_USAGE_CPU_WRITE));
114 slotOut = rotatedSlot++;
115 dst += slotOut * (cuRotatedSlotSize /
sizeof(float));
116 for(
int i = 0; i < 4; i++)
118 dst[i * 3 + 0] = ndcCorners[i * 2 + 0];
119 dst[i * 3 + 1] = ndcCorners[i * 2 + 1];
120 dst[i * 3 + 2] = 0.0f;
122 GX2RUnlockBufferEx(&rotatedBuffer, GX2R_RESOURCE_USAGE_CPU_WRITE);
131 GX2RSetAttributeBuffer(
const_cast<GX2RBuffer *
>(&rotatedBuffer), 0,
cuVertexAttrSize, slot * cuRotatedSlotSize);
161 GX2SetPixelTexture(texture, samplerLocation);
162 GX2SetPixelSampler(sampler, samplerLocation);
172 static const float zero[3] = {0.0f, 0.0f, 0.0f};
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 cuTexCoordAttrSize
Size in bytes of one texture coordinate (2 floats)
void setOffset(const float offset[3])
void setRotatedAttributeBuffer(uint32_t slot) const
Binds a slot from uploadRotatedQuad() as the position stream (plus the shared texcoords).
void setAttributeBuffer() const
Binds the quad position and texture-coordinate buffers.
void resetFrame()
Call once per frame, before any draws - rewinds the rotated-quad slot counter (see WutVideoDriver::pr...
static Texture2DShader * instance()
void clearBlur() const
The compiled pixel shader reads a per-draw blur-direction uniform that this driver doesn't expose as ...
void setTextureAndSampler(const GX2Texture *texture, const GX2Sampler *sampler) const
Binds the texture to sample and the sampler describing its filtering.
void setColorIntensity(const float colorIntensity[4])
static void destroyInstance()
Destroys the shared instance; the next instance() call creates a new one.
void setScale(const float scale[3])
void setAngle(float angleRadians)
bool uploadRotatedQuad(const float ndcCorners[8], uint32_t &slotOut)
Copies a pre-rotated quad into its own vertex slot.
void setShaders() const
Binds the fetch, vertex and pixel shaders for subsequent draws.
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.